Skip to content

Commit

Permalink
Rename assignment_service.set_document_url to upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Oct 11, 2021
1 parent bf6ccc0 commit c97d799
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lms/services/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def exists(
except ValueError:
return False

def set_document_url( # pylint:disable=too-many-arguments
def upsert( # pylint:disable=too-many-arguments
self,
document_url,
tool_consumer_instance_guid,
Expand All @@ -128,13 +128,13 @@ def set_document_url( # pylint:disable=too-many-arguments
extra=None,
):
"""
Save the given document_url in an existing assignment or create new one.
Update or create an assignment with the given document_url.
Set the document_url for the assignment that matches
tool_consumer_instance_guid and resource_link_id/ext_lti_assignment_id
or create a new one if none exist on the DB.
Any existing document URL for this assignment will be overwritten.
Any existing document_url for this assignment will be overwritten.
"""
assignment = self.get(
tool_consumer_instance_guid, resource_link_id, ext_lti_assignment_id
Expand Down
2 changes: 1 addition & 1 deletion lms/views/api/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create(self):
if groupset := params.get("groupset"):
extra["canvas_groupset"] = groupset

assignment = self.assignment_service.set_document_url(
assignment = self.assignment_service.upsert(
url,
self.application_instance.tool_consumer_instance_guid,
ext_lti_assignment_id=params["ext_lti_assignment_id"],
Expand Down
6 changes: 3 additions & 3 deletions lms/views/basic_lti_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def canvas_file_basic_lti_launch(self):
# module item configuration. As a result of this we can rely on this
# being around in future code.
document_url = f"canvas://file/course/{course_id}/file_id/{file_id}"
self.assignment_service.set_document_url(
self.assignment_service.upsert(
# This URL is mostly for show. We just want to ensure that a module
# configuration exists. If we're going to do that we might as well
# make sure this URL is meaningful.
Expand Down Expand Up @@ -209,7 +209,7 @@ def course_copied_basic_lti_launch(self, original_resource_link_id):
tool_consumer_instance_guid, original_resource_link_id
).document_url

self.assignment_service.set_document_url(
self.assignment_service.upsert(
document_url, tool_consumer_instance_guid, resource_link_id
)

Expand Down Expand Up @@ -307,7 +307,7 @@ def configure_assignment(self):
"""
document_url = self.request.parsed_params["document_url"]

self.assignment_service.set_document_url(
self.assignment_service.upsert(
document_url,
self.request.parsed_params["tool_consumer_instance_guid"],
self.request.parsed_params["resource_link_id"],
Expand Down
12 changes: 5 additions & 7 deletions tests/unit/lms/services/assignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,12 @@ def test_if_both_resource_link_id_and_ext_lti_assignment_id_are_None_it_returns_
assert not result


class TestSetDocumentURL:
class TestUpsertDocumentURL:
def test_at_least_one_of_resource_link_id_or_ext_lti_assignment_id_is_required(
self, svc
):
with pytest.raises(ValueError):
svc.set_document_url(
"new_document_url", MATCHING_TOOL_CONSUMER_INSTANCE_GUID
)
svc.upsert("new_document_url", MATCHING_TOOL_CONSUMER_INSTANCE_GUID)

def test_it_raises_if_there_are_multiple_matching_assignments(self, svc):
factories.Assignment(
Expand All @@ -473,7 +471,7 @@ def test_it_raises_if_there_are_multiple_matching_assignments(self, svc):
)

with pytest.raises(MultipleResultsFound):
svc.set_document_url(
svc.upsert(
"new_document_url",
MATCHING_TOOL_CONSUMER_INSTANCE_GUID,
MATCHING_RESOURCE_LINK_ID,
Expand All @@ -491,7 +489,7 @@ def test_it_raises_if_there_are_multiple_matching_assignments(self, svc):
def test_if_theres_no_matching_assignment_it_creates_one(
self, svc, resource_link_id, ext_lti_assignment_id
):
svc.set_document_url(
svc.upsert(
"new_document_url",
MATCHING_TOOL_CONSUMER_INSTANCE_GUID,
resource_link_id,
Expand Down Expand Up @@ -525,7 +523,7 @@ def test_if_theres_a_matching_assignment_it_updates_it(
document_url="old_document_url",
)

svc.set_document_url(
svc.upsert(
"new_document_url",
MATCHING_TOOL_CONSUMER_INSTANCE_GUID,
resource_link_id,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lms/views/api/assignments_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ def test_create(

result = AssignmentsAPIViews(pyramid_request).create()

assignment_service.set_document_url.assert_called_once_with(
assignment_service.upsert.assert_called_once_with(
expected_url,
application_instance_service.get.return_value.tool_consumer_instance_guid,
ext_lti_assignment_id="EXT_LTI_ASSIGNMENT_ID",
extra=expected_extra,
)
assert result == {
"ext_lti_assignment_id": assignment_service.set_document_url.return_value.ext_lti_assignment_id
"ext_lti_assignment_id": assignment_service.upsert.return_value.ext_lti_assignment_id
}

@pytest.mark.usefixtures("application_instance_service", "assignment_service")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/lms/views/basic_lti_launch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_it(self, context, pyramid_request, assignment_service):
course_id = pyramid_request.params["custom_canvas_course_id"]
file_id = pyramid_request.params["file_id"]

assignment_service.set_document_url.assert_called_once_with(
assignment_service.upsert.assert_called_once_with(
document_url=f"canvas://file/course/{course_id}/file_id/{file_id}",
tool_consumer_instance_guid=pyramid_request.params[
"tool_consumer_instance_guid"
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_it_copies_the_assignment_settings_and_adds_the_document_url(

# It copies the assignment settings to the new resource_link_id in the
# DB.
assignment_service.set_document_url.assert_called_once_with(
assignment_service.upsert.assert_called_once_with(
assignment_service.get.return_value.document_url,
pyramid_request.params["tool_consumer_instance_guid"],
pyramid_request.params["resource_link_id"],
Expand Down Expand Up @@ -366,7 +366,7 @@ def test_it_saves_the_assignments_document_url_to_the_db(
):
configure_assignment_caller(context, pyramid_request)

assignment_service.set_document_url.assert_called_once_with(
assignment_service.upsert.assert_called_once_with(
pyramid_request.parsed_params["document_url"],
pyramid_request.parsed_params["tool_consumer_instance_guid"],
pyramid_request.parsed_params["resource_link_id"],
Expand Down

0 comments on commit c97d799

Please sign in to comment.