-
Notifications
You must be signed in to change notification settings - Fork 14
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
Refactor get_assignments tests to exercise all parameters independently and combined #6437
Merged
marcospri
merged 1 commit into
api-filter-assignments-by-assignments
from
get-assignments-test-refactor
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import pytest | ||
from h_matchers import Any | ||
|
||
from lms.models import AssignmentGrouping, AssignmentMembership, RoleScope | ||
from lms.models import AssignmentGrouping, AssignmentMembership, RoleScope, RoleType | ||
from lms.services.assignment import AssignmentService, factory | ||
from tests import factories | ||
|
||
|
@@ -239,55 +239,52 @@ def test_is_member(self, svc, db_session): | |
assert svc.is_member(assignment, user.h_userid) | ||
assert not svc.is_member(assignment, other_user.h_userid) | ||
|
||
def test_get_assignments(self, svc, db_session): | ||
assert db_session.scalars(svc.get_assignments()).all() | ||
|
||
def test_get_assignments_by_course(self, svc, db_session, assignment): | ||
@pytest.mark.parametrize("instructor_h_userid", [True, False]) | ||
@pytest.mark.parametrize("course_id", [True, False]) | ||
@pytest.mark.parametrize("h_userids", [True, False]) | ||
def test_get_assignments( | ||
self, | ||
svc, | ||
db_session, | ||
instructor_h_userid, | ||
assignment, | ||
with_assignment_noise, | ||
course_id, | ||
h_userids, | ||
): | ||
factories.User() | ||
course = factories.Course() | ||
factories.AssignmentGrouping.create(assignment=assignment, grouping=course) | ||
db_session.flush() | ||
|
||
assert db_session.scalars(svc.get_assignments(course_id=course.id)).all() == [ | ||
assignment | ||
] | ||
|
||
def test_get_assignments_with_instructor_h_userid(self, svc, db_session): | ||
factories.User() # User not in assignment | ||
assignment = factories.Assignment() | ||
user = factories.User() | ||
lti_role = factories.LTIRole(scope=RoleScope.COURSE) | ||
lti_role = factories.LTIRole(scope=RoleScope.COURSE, type=RoleType.INSTRUCTOR) | ||
factories.AssignmentMembership.create( | ||
assignment=assignment, user=user, lti_role=lti_role | ||
) | ||
# Other membership record, with a different role | ||
factories.AssignmentMembership.create( | ||
assignment=assignment, user=user, lti_role=factories.LTIRole() | ||
) | ||
|
||
factories.AssignmentGrouping.create(assignment=assignment, grouping=course) | ||
db_session.flush() | ||
|
||
assert db_session.scalars(svc.get_assignments(user.h_userid)).all() == [ | ||
assignment | ||
] | ||
query_parameters = {} | ||
|
||
def test_get_assignments_with_h_userids(self, svc, db_session): | ||
factories.User() # User not in assignment | ||
assignment = factories.Assignment() | ||
user = factories.User() | ||
lti_role = factories.LTIRole(scope=RoleScope.COURSE) | ||
factories.AssignmentMembership.create( | ||
assignment=assignment, user=user, lti_role=lti_role | ||
) | ||
# Other membership record, with a different role | ||
factories.AssignmentMembership.create( | ||
assignment=assignment, user=user, lti_role=factories.LTIRole() | ||
) | ||
if instructor_h_userid: | ||
query_parameters["instructor_h_userid"] = user.h_userid | ||
|
||
db_session.flush() | ||
if course_id: | ||
query_parameters["course_id"] = course.id | ||
|
||
assert db_session.scalars( | ||
svc.get_assignments(h_userids=[user.h_userid]) | ||
).all() == [assignment] | ||
if h_userids: | ||
query_parameters["h_userids"] = [user.h_userid] | ||
|
||
query = svc.get_assignments(**query_parameters) | ||
|
||
if not query_parameters: | ||
assert set(db_session.scalars(query).all()) == set( | ||
[assignment] + with_assignment_noise | ||
) | ||
|
||
else: | ||
assert db_session.scalars(query).all() == [assignment] | ||
|
||
def test_get_assignments_by_course_id_with_duplicate(self, db_session, svc): | ||
course = factories.Course() | ||
|
@@ -357,14 +354,16 @@ def non_matching_params(self, request, matching_params): | |
|
||
@pytest.fixture(autouse=True) | ||
def with_assignment_noise(self, assignment): | ||
factories.Assignment( | ||
tool_consumer_instance_guid=assignment.tool_consumer_instance_guid, | ||
resource_link_id="noise_resource_link_id", | ||
) | ||
factories.Assignment( | ||
tool_consumer_instance_guid="noise_tool_consumer_instance_guid", | ||
resource_link_id=assignment.resource_link_id, | ||
) | ||
return [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixture now not only creates the assignments but returns them. I reckon all fixtures should return the values they create even if not immediately used. |
||
factories.Assignment( | ||
tool_consumer_instance_guid=assignment.tool_consumer_instance_guid, | ||
resource_link_id="noise_resource_link_id", | ||
), | ||
factories.Assignment( | ||
tool_consumer_instance_guid="noise_tool_consumer_instance_guid", | ||
resource_link_id=assignment.resource_link_id, | ||
), | ||
] | ||
|
||
@pytest.fixture | ||
def create_assignment(self, svc): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Improve the assert here, check it matches the assignment created in this test (
assignment
) + the other ones in the DB (with_assignment_noise
).