Skip to content

Commit b7ddf99

Browse files
committed
testing
1 parent c6b2267 commit b7ddf99

6 files changed

Lines changed: 159 additions & 0 deletions

File tree

tests/unit/lms/product/canvas/_plugin/misc_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def test_get_assignment_configuration_with_auto_grading_config(
6262
"auto_grading_config": {"some": "value"},
6363
}
6464

65+
def test_get_assignment_configuration_with_checkpoint(
66+
self, plugin, pyramid_request
67+
):
68+
pyramid_request.params["checkpoint_enabled"] = "true"
69+
70+
config = plugin.get_assignment_configuration(
71+
pyramid_request, sentinel.assignment, sentinel.historical_assignment
72+
)
73+
74+
assert config["checkpoint_enabled"] is True
75+
6576
def test_get_assignment_configuration(self, plugin, pyramid_request):
6677
config = plugin.get_assignment_configuration(
6778
pyramid_request, sentinel.assignment, sentinel.historical_assignment

tests/unit/lms/product/plugin/misc_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ def test_get_assignment_configuration_with_auto_grading_in_deep_linked_configura
7777
== auto_grading_config.asdict()
7878
)
7979

80+
def test_get_assignment_configuration_with_checkpoint_in_existing_db_assignment(
81+
self, plugin, pyramid_request
82+
):
83+
assignment = factories.AssignmentCheckpoint().assignment
84+
pyramid_request.lti_params["resource_link_id"] = sentinel.link_id
85+
86+
result = plugin.get_assignment_configuration(pyramid_request, assignment, None)
87+
88+
assert result["checkpoint_enabled"] is True
89+
90+
def test_get_assignment_configuration_with_checkpoint_in_deep_linked_configuration(
91+
self, plugin, get_deep_linked_assignment_configuration
92+
):
93+
get_deep_linked_assignment_configuration.return_value = {
94+
"checkpoint_enabled": "true"
95+
}
96+
97+
assert (
98+
plugin.get_assignment_configuration(sentinel.request, None, None)[
99+
"checkpoint_enabled"
100+
]
101+
is True
102+
)
103+
80104
def test_get_assignment_configuration_with_assignment_in_db_copied_assignment(
81105
self, plugin, pyramid_request
82106
):

tests/unit/lms/services/assignment_test.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlalchemy import select
77

88
from lms.models import (
9+
AssignmentCheckpoint,
910
AssignmentGrouping,
1011
AssignmentMembership,
1112
AutoGradingConfig,
@@ -138,6 +139,52 @@ def test_update_assignment_removes_auto_grading_config(
138139
assert not assignment.auto_grading_config
139140
assert not db_session.get(AutoGradingConfig, auto_grading_config.id)
140141

142+
def test_update_assignment_with_checkpoint(self, svc, pyramid_request, course):
143+
assignment = factories.Assignment()
144+
145+
assignment = svc.update_assignment(
146+
pyramid_request,
147+
assignment,
148+
sentinel.document_url,
149+
sentinel.group_set_id,
150+
course,
151+
checkpoint_enabled=True,
152+
)
153+
154+
assert assignment.checkpoint
155+
156+
def test_update_assignment_without_checkpoint(self, svc, pyramid_request, course):
157+
assignment = factories.Assignment()
158+
159+
assignment = svc.update_assignment(
160+
pyramid_request,
161+
assignment,
162+
sentinel.document_url,
163+
sentinel.group_set_id,
164+
course,
165+
checkpoint_enabled=False,
166+
)
167+
168+
assert not assignment.checkpoint
169+
170+
def test_update_assignment_keeps_existing_checkpoint(
171+
self, svc, pyramid_request, course
172+
):
173+
existing_checkpoint = AssignmentCheckpoint()
174+
assignment = factories.Assignment()
175+
assignment.checkpoint = existing_checkpoint
176+
177+
assignment = svc.update_assignment(
178+
pyramid_request,
179+
assignment,
180+
sentinel.document_url,
181+
sentinel.group_set_id,
182+
course,
183+
checkpoint_enabled=True,
184+
)
185+
186+
assert assignment.checkpoint is existing_checkpoint
187+
141188
@pytest.mark.parametrize(
142189
"param",
143190
(

tests/unit/lms/services/h_api_test.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,59 @@ def test_get_groups(self, h_api, http_service):
266266
for group in groups
267267
]
268268

269+
def test_sync_checkpoints(self, h_api, _api_request): # noqa: PT019
270+
checkpoints = [
271+
{
272+
"group_authority_provided_id": "group1",
273+
"document_uri": "https://example.com/doc",
274+
"reveal_date": None,
275+
}
276+
]
277+
278+
h_api.sync_checkpoints(authority="lms.hypothes.is", checkpoints=checkpoints)
279+
280+
_api_request.assert_called_once_with(
281+
"POST",
282+
path="bulk/checkpoint",
283+
body=json.dumps(
284+
{"authority": "lms.hypothes.is", "checkpoints": checkpoints}
285+
),
286+
headers={"Content-Type": "application/json"},
287+
)
288+
289+
def test_sync_checkpoints_with_instructor(self, h_api, _api_request): # noqa: PT019
290+
checkpoints = [
291+
{
292+
"group_authority_provided_id": "group1",
293+
"document_uri": "https://example.com/doc",
294+
"reveal_date": None,
295+
}
296+
]
297+
298+
h_api.sync_checkpoints(
299+
authority="lms.hypothes.is",
300+
checkpoints=checkpoints,
301+
instructor_username="teacher",
302+
)
303+
304+
_api_request.assert_called_once_with(
305+
"POST",
306+
path="bulk/checkpoint",
307+
body=json.dumps(
308+
{
309+
"authority": "lms.hypothes.is",
310+
"checkpoints": checkpoints,
311+
"instructor_username": "teacher",
312+
}
313+
),
314+
headers={"Content-Type": "application/json"},
315+
)
316+
317+
def test_sync_checkpoints_with_no_checkpoints(self, h_api, _api_request): # noqa: PT019
318+
h_api.sync_checkpoints(authority="lms.hypothes.is", checkpoints=[])
319+
320+
_api_request.assert_not_called()
321+
269322
def test__api_request(self, h_api, http_service):
270323
h_api._api_request(sentinel.method, "dummy-path", body=sentinel.raw_body) # noqa: SLF001
271324

tests/unit/lms/services/lti_h_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ def test_sync_upserts_the_GroupInfo_into_the_db(
6969
grouping=grouping, params=sentinel.params
7070
)
7171

72+
def test_sync_syncs_checkpoints(self, h_api, lti_h_svc):
73+
groupings = factories.Course.create_batch(2)
74+
checkpoint_data = {
75+
"document_uri": "https://example.com/doc",
76+
"reveal_date": "2026-07-01T12:00:00",
77+
"instructor_username": "teacher",
78+
}
79+
80+
lti_h_svc.sync(groupings, sentinel.params, checkpoint_data=checkpoint_data)
81+
82+
h_api.sync_checkpoints.assert_called_once_with(
83+
authority=lti_h_svc._authority, # noqa: SLF001
84+
checkpoints=[
85+
{
86+
"group_authority_provided_id": grouping.authority_provided_id,
87+
"document_uri": "https://example.com/doc",
88+
"reveal_date": "2026-07-01T12:00:00",
89+
}
90+
for grouping in groupings
91+
],
92+
instructor_username="teacher",
93+
)
94+
7295
@pytest.fixture
7396
def lti_h_svc(self, pyramid_request):
7497
return LTIHService(None, pyramid_request)

tests/unit/lms/views/lti/deep_linking_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def test_it_for_v11(
294294
{"auto_grading_config": {"key": "value"}},
295295
{"auto_grading_config": '{"key": "value"}'},
296296
),
297+
({"checkpoint_enabled": True}, {"checkpoint_enabled": "true"}),
297298
],
298299
)
299300
def test__get_assignment_configuration(

0 commit comments

Comments
 (0)