Skip to content

fix: reduce warnings when running tests #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ config :cadet, CadetWeb.Endpoint,
config :cadet, environment: :test

# Print only warnings and errors during test
config :logger, level: :warn, compile_time_purge_matching: [[level_lower_than: :warn]]
config :logger, level: :warning, compile_time_purge_matching: [[level_lower_than: :warning]]

config :ex_aws,
access_key_id: "hello",
Expand Down
4 changes: 0 additions & 4 deletions lib/cadet/accounts/teams.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ defmodule Cadet.Accounts.Teams do

true ->
Enum.reduce_while(attrs["student_ids"], {:ok, nil}, fn team_attrs, {:ok, _} ->
student_ids = Enum.map(team_attrs, &Map.get(&1, "userId"))

{:ok, team} =
%Team{}
|> Team.changeset(attrs)
Expand Down Expand Up @@ -105,7 +103,6 @@ defmodule Cadet.Accounts.Teams do
ids = Enum.map(team, &Map.get(&1, "userId"))

unique_ids_count = ids |> Enum.uniq() |> Enum.count()
all_ids_distinct = unique_ids_count == Enum.count(ids)

student_already_in_team?(-1, ids, assessment_id)
end)
Expand Down Expand Up @@ -229,7 +226,6 @@ defmodule Cadet.Accounts.Teams do

"""
def update_team(team = %Team{}, new_assessment_id, student_ids) do
old_assessment_id = team.assessment_id
team_id = team.id
new_student_ids = Enum.map(hd(student_ids), fn student -> Map.get(student, "userId") end)

Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/devices/devices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ defmodule Cadet.Devices do
},
300,
[],
''
""
)

# ExAws includes the session token in the signed payload and doesn't allow
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/jobs/autograder/lambda_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Cadet.Autograder.LambdaWorker do
lambda_params = build_request_params(params)

if Enum.empty?(lambda_params.testcases) do
Logger.warn("No testcases found. Skipping autograding for answer_id: #{answer.id}")
Logger.warning("No testcases found. Skipping autograding for answer_id: #{answer.id}")
# Fix for https://github.com/source-academy/backend/issues/472
Process.sleep(1000)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/jobs/xml_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Cadet.Updater.XMLParser do
:ok
else
{:error, stage, %{errors: [assessment: {"has submissions", []}]}, _} when is_atom(stage) ->
Logger.warn("Assessment has submissions, ignoring...")
Logger.warning("Assessment has submissions, ignoring...")
{:ok, "Assessment has submissions, ignoring..."}

{:error, error_message} ->
Expand Down
12 changes: 6 additions & 6 deletions lib/cadet/notifications.ex
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ defmodule Cadet.Notifications do
|> Repo.insert()
end

@doc """
Returns the list of sent_notifications.
# @doc """
# Returns the list of sent_notifications.

## Examples
# ## Examples

iex> list_sent_notifications()
[%SentNotification{}, ...]
# iex> list_sent_notifications()
# [%SentNotification{}, ...]

"""
# """

# def list_sent_notifications do
# Repo.all(SentNotification)
Expand Down
6 changes: 3 additions & 3 deletions lib/cadet_web/admin_controllers/admin_stories_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule CadetWeb.AdminStoriesController do

case result do
{:ok, _story} ->
conn |> put_status(200) |> text('')
conn |> put_status(200) |> text("")

{:error, {status, message}} ->
conn
Expand All @@ -29,7 +29,7 @@ defmodule CadetWeb.AdminStoriesController do

case result do
{:ok, _story} ->
conn |> put_status(200) |> text('')
conn |> put_status(200) |> text("")

{:error, {status, message}} ->
conn
Expand All @@ -43,7 +43,7 @@ defmodule CadetWeb.AdminStoriesController do

case result do
{:ok, _nil} ->
conn |> put_status(204) |> text('')
conn |> put_status(204) |> text("")

{:error, {status, message}} ->
conn
Expand Down
8 changes: 4 additions & 4 deletions lib/cadet_web/controllers/answer_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ defmodule CadetWeb.AnswerController do
end
end

def submit(conn, _params) do
send_resp(conn, :bad_request, "Missing or invalid parameter(s)")
end

def check_last_modified(conn, %{
"questionid" => question_id,
"lastModifiedAt" => last_modified_at
Expand Down Expand Up @@ -79,10 +83,6 @@ defmodule CadetWeb.AnswerController do
end
end

def submit(conn, _params) do
send_resp(conn, :bad_request, "Missing or invalid parameter(s)")
end

swagger_path :submit do
post("/assessments/question/{questionId}/answer")

Expand Down
4 changes: 2 additions & 2 deletions test/cadet/assessments/assessments_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ defmodule Cadet.AssessmentsTest do

test "limit submisssions 2", %{
course_regs: %{avenger1_cr: avenger},
assessments: assessments
assessments: _assessments
} do
{_, res} =
Assessments.submissions_by_grader_for_index(avenger, %{
Expand Down Expand Up @@ -3142,7 +3142,7 @@ defmodule Cadet.AssessmentsTest do

defp expected_top_relative_scores(top_x, token_divider) do
# "return 0;" in the factory has 3 token
10..0
10..0//-1
|> Enum.to_list()
|> Enum.map(fn score -> 10 * score - :math.pow(2, 3 / token_divider) end)
|> Enum.take(top_x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do
import Ecto.Query
import ExUnit.CaptureLog

alias Cadet.{Assessments, Repo}
alias Cadet.Repo
alias Cadet.Accounts.CourseRegistration
alias Cadet.Assessments.{Assessment, Submission}
alias Cadet.Test.XMLGenerator
Expand Down
2 changes: 0 additions & 2 deletions test/cadet_web/plug/rate_limiter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ defmodule CadetWeb.Plugs.RateLimiterTest do
end

test "rate limit exceeded", %{conn: conn} do
key = "user:1"

# Simulate exceeding the rate limit
for _ <- 1..RateLimiter.rate_limit() do
conn = RateLimiter.call(conn, %{})
Expand Down
Loading