Conversation
Add get_user_courses_ects_safe that converts string ECTS to float, replaces missing/invalid values with 0.0 and logs occurrences. Use the safe wrapper in get_grades and add async tests covering filtering/conversion, empty responses, and mixed valid/None courses.
There was a problem hiding this comment.
Pull request overview
Adds a defensive wrapper around the USOS “user ECTS points” call to avoid crashes when the API returns None/non-numeric ECTS values, and introduces unit tests meant to cover the new behavior in the grades app.
Changes:
- Added
get_user_courses_ects_safe()and switchedget_gradesto use it. - Added a new test module for the safe ECTS wrapper.
- Initialized the
grades.testspackage.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
grades/views.py |
Introduces the safe ECTS fetch/normalize helper and routes get_grades through it. |
grades/tests/test_grade_fetching.py |
Adds tests intended to validate handling of None/string ECTS values. |
grades/tests/__init__.py |
Marks grades/tests as a package for test discovery/imports. |
Expect None ECTS values to be converted to 0.0 instead of filtered out. Update AsyncMock usage to mock_client.connection.get and adjust assertions accordingly.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use a more descriptive missing_or_invalid_ects_count and update the info log accordingly. Also switch the test to SimpleTestCase to avoid unnecessary DB setup for an async unit test.
Cover get_user_courses_ects_safe to ensure non-numeric or non-string ECTS values are converted to 0.0 and do not break the result structure.
|
Niestety jak na razie nie mam pojęcia jak naprawić ten problem z testami, bo lokalnie u mnie przechodzą bez problemu. A według chatu to problem leży w tym, że testy jednostkowe nie są widoczne w CI. |
|
O testy przeszły. Ogólnie jednak problem leżał w tym że w grades był pusty plik tests.py a ja dodatkowo stworzyłem testy w podfolderze tests, a w unittest w django wywala właśnie taki błąd. Tak czy inaczej teraz działa, dlatego @MoonPrincess06 proszę o review w wolnej chwili. Z góry dzięki :) |
Important
Fixes None ECTS handling in
get_user_courses_ects_safe()and adds tests for various scenarios.get_user_courses_ects_safe()inviews.pyto handle None ECTS values by setting them to 0.0.get_grades()inviews.pyto use the safe wrapper function.test_grade_fetching.pyto test filtering of None values, handling of all None terms, empty responses, conversion of string ECTS to float, and mixed valid/None courses.get_user_courses_ects_safe().This description was created by
for 4bfe13f. You can customize this summary. It will automatically update as commits are pushed.