Skip to content

Commit

Permalink
fix: refactor acs test tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ilee2u committed Jul 28, 2023
1 parent 30635d5 commit 664e893
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions edx_exams/apps/lti/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def setUp(self):
self.test_provider.save()

self.url = self.get_acs_url(self.attempt.id)
self.token = self.make_access_token('https://purl.imsglobal.org/spec/lti-ap/scope/control.all')

def get_acs_url(self, lti_config_id):
"""
Expand Down Expand Up @@ -169,12 +170,9 @@ def test_acs_attempt_status(self,

mock_get_attempt.return_value = self.attempt
mock_permissions.return_value = True

token = self.make_access_token('https://purl.imsglobal.org/spec/lti-ap/scope/control.all')

request_body = self.create_request_body(self.attempt.attempt_number, 'flag')

response = self.make_post_request(request_body, token)
response = self.make_post_request(request_body, self.token)

self.assertEqual(response.status_code, expected_response_status)

Expand All @@ -192,13 +190,10 @@ def test_acs_no_attempt_found(self,

mock_get_attempt.return_value = None
mock_permissions.return_value = True

token = self.make_access_token('https://purl.imsglobal.org/spec/lti-ap/scope/control.all')

# Request w/ attempt number for an attempt that does not exist
# Request w/ attempt number for an attempt that does not exist
request_body = self.create_request_body(false_attempt_number, 'flag')

response = self.make_post_request(request_body, token)
response = self.make_post_request(request_body, self.token)

self.assertEqual(response.status_code, 400)

Expand Down Expand Up @@ -228,9 +223,6 @@ def test_acs_base_parameter_missing_errors(self,
# Assert the correct error is thrown in the response with status 400
mock_get_attempt.return_value = self.attempt
mock_permissions.return_value = True

token = self.make_access_token('https://purl.imsglobal.org/spec/lti-ap/scope/control.all')

request_body = self.create_request_body(
self.attempt.attempt_number,
'terminate',
Expand All @@ -244,7 +236,7 @@ def test_acs_base_parameter_missing_errors(self,
del request_body[acs_parameter][acs_sub_parameter]
key_to_fail = acs_sub_parameter

response = self.make_post_request(request_body, token)
response = self.make_post_request(request_body, self.token)

self.attempt.refresh_from_db()
self.assertEqual(response.data, f'ERROR: required parameter \'{key_to_fail}\' was not found.')
Expand Down Expand Up @@ -272,9 +264,6 @@ def test_acs_terminate_parameter_errors(self,
# Assert the correct error is thrown in the response with status 400
mock_get_attempt.return_value = self.attempt
mock_permissions.return_value = True

token = self.make_access_token('https://purl.imsglobal.org/spec/lti-ap/scope/control.all')

request_body = self.create_request_body(
self.attempt.attempt_number,
action='terminate',
Expand All @@ -284,7 +273,7 @@ def test_acs_terminate_parameter_errors(self,

del request_body[acs_parameter]

response = self.make_post_request(request_body, token)
response = self.make_post_request(request_body, self.token)
self.attempt.refresh_from_db()
self.assertEqual(response.data, f'ERROR: required parameter \'{acs_parameter}\' was not found.')

Expand Down Expand Up @@ -320,17 +309,14 @@ def test_acs_terminate(self,

mock_get_attempt.return_value = self.attempt
mock_permissions.return_value = True

token = self.make_access_token('https://purl.imsglobal.org/spec/lti-ap/scope/control.all')

request_body = self.create_request_body(
self.attempt.attempt_number,
'terminate',
reason_code,
incident_severity
)

self.make_post_request(request_body, token)
self.make_post_request(request_body, self.token)
self.attempt.refresh_from_db()

self.assertEqual(self.attempt.status, expected_attempt_status)
Expand Down

0 comments on commit 664e893

Please sign in to comment.