-
Notifications
You must be signed in to change notification settings - Fork 0
build: configure pytest-django and add dev dependencies #40
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
base: dev
Are you sure you want to change the base?
Conversation
A-lexisL
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- tests should be comprehensive, so more tests are needed. Please arrange them into classes based on API and Authenticated status.
e.g.
class TestCourseListAuthenticated
class TestCourseListNotAuthenticated
class TestCourseDetailAuthenticated
...
apps/web/tests/test_auth.py
Outdated
| response = base_client.get(url) | ||
| assert response.status_code == 200 | ||
| # Should be at least 1 due to the 'review' fixture | ||
| assert response.data["review_count"] >= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test should be precise, so use ==1 instead of >=1
apps/web/tests/test_course.py
Outdated
| response = base_client.get(url) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.data["count"] >= 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
apps/web/tests/test_course.py
Outdated
| # Check that filtering worked (only 1 course returned) | ||
| assert response.data["count"] == 1 | ||
|
|
||
| # FIX: Check course_code instead of department key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that you are making adjustments during developments. But comments are for reviewers and future maintainers, so the Fix: xxx here becomes confusing
| assert "results" in response.data | ||
|
|
||
| def test_filter_courses_by_department(self, base_client, course_factory): | ||
| """Verify filtering courses by department code.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, only filter courses by department code for nonauthenticated user exists. But tests for all the following params are needed for authenticated/nonauthenticated users.
- department (string): Filter by department code (case-insensitive)
- code (string): Filter by course code (partial match)
- min_quality (integer): Filter by minimum quality score (authenticated only)
- min_difficulty (integer): Filter by minimum difficulty score (authenticated only)
- sort_by (string): Sort field ("course_code", "review_count"),("quality_score", "difficulty_score")(authenticated only)
- sort_order (string): "asc" or "desc" (default: "asc")
- page (integer): Page number for pagination
(docstring of CoursesListAPI in apps/web/views.py)
Same for other apis
apps/web/tests/factories.py
Outdated
| @factory.lazy_attribute | ||
| def course_code(self): | ||
| """Generates unique MATH100, PHYS101, etc.""" | ||
| return f"{self.department}{self.number}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
course_code is department+4-digit number+J, e.g. CHEM2110J
apps/web/tests/test_review.py
Outdated
| class TestReviewManagement: | ||
| """ | ||
| Tests for Review management: | ||
| - Creation with validation (30+ chars, valid term) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
30 is not a fixed number but varies according to configs.
Its best to generate comments based on settings.WEB["REVIEW"]["COMMENT_MIN_LENGTH"] (since the content of comments is not important, could use python internal string manipulation methods or faker to generate comments of desired length instead of writing them manually)
apps/web/tests/test_review.py
Outdated
| url = reverse("user_review_api", kwargs={"review_id": review.id}) | ||
| response = auth_client.delete(url) | ||
| assert response.status_code == 204 | ||
| assert Review.objects.filter(id=review.id).count() == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tests for base_client
|
|
||
| assert response.status_code == 200 | ||
| # Verify the title matches the fixture-created course | ||
| assert response.data["course_title"] == course.course_title |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base_client and auth_client will receive different response data:
- auth_client: full details
- base_client:
"quality_score" ,"difficulty_score","difficulty_vote","quality_vote","quality_vote_count","difficulty_vote_count"fields are removed(the docstrings for CoursesDetailAPI is not complete)
…fix the format of the course code later
d40df23 to
bc0334e
Compare
…sc and desc) pagnition)
A-lexisL
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are comprehensive. But some test cases still need polishing.
| term_data | ||
| and term_data.group("year") == "16" | ||
| and term_data.group("term") == "w" | ||
| and term_data.group("term") == "F" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| @pytest.fixture | ||
| def department_mixed_courses(db): | ||
| """Returns a mixed set of courses for filtering/sorting tests.""" | ||
| # Note: Using 'title' to match your original course.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since title is changed to course_title, this comment is outdated
apps/web/tests/test_course.py
Outdated
| resp_p1 = auth_client.get(url, {"page": 1}) | ||
|
|
||
| assert resp_p1.status_code == 200 | ||
| assert len(resp_p1.data["results"]) == 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 is hardcoded.
Its not very necessary to test pagination, as it has nothing to do with data correctness/authentication access
| status.HTTP_403_FORBIDDEN, | ||
| ] | ||
|
|
||
| def test_department_api_empty(self, base_client, db): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed: department_api is already tested in test_course.py
| """5. Verify user can list their own reviews.""" | ||
| response = auth_client.get(personal_reviews_list_url) | ||
| assert response.status_code == status.HTTP_200_OK | ||
| assert any(r["id"] == review.id for r in response.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check if the api returns and only returns personal reviews. e.g. review + other_review and the api only returns review
|
|
||
| ReviewFactory(course=course, professor="UniqueProf", comments="c" * min_len) | ||
| response = auth_client.get(course_reviews_url, {"q": "UniqueProf"}) | ||
| assert any(r["professor"] == "UniqueProf" for r in response.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be all
Although search review could also match partial UniqueProf in professor/comment, in this case only reviews that ["professor"] == "UniqueProf" would be returned
| self, auth_client, personal_review_detail_url, review, valid_review_data | ||
| ): | ||
| """9. Verify successful update of user's own review.""" | ||
| valid_review_data["comments"] = "Updated content that is long enough." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
min length is according to config. So this comment may not be long enough. Use 'b' * min_len
| ] | ||
| assert Review.objects.filter(id=review.id).exists() | ||
|
|
||
| def test_department_api_sorting(self, base_client, db): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be removed.
| ): | ||
| """14. Verify PUT fails if required fields (professor) are missing.""" | ||
| response = auth_client.put( | ||
| personal_review_detail_url, {"comments": "Valid length..."}, format="json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still min length problem.
Dont know whether 400 is caused by min length or missing fields
| ): | ||
| """19. Verify vote statistics are included in the response.""" | ||
| response = auth_client.get(personal_review_detail_url) | ||
| assert "kudos_count" in response.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also test dislike_count
f0ba2fa to
5a7a0b1
Compare
No description provided.