Skip to content
Snippets Groups Projects
Commit 17c19ead authored by Lennard Strohmeyer's avatar Lennard Strohmeyer :penguin:
Browse files

removed test case quickly

parent ab9c1b03
No related branches found
No related tags found
No related merge requests found
Pipeline #1644449 passed
......@@ -945,130 +945,4 @@ class TestxAPITimestampAfterConsent(BaseTestCase):
response.json()["message"], "xAPI statements couldn't be stored in LRS"
)
class TextxAPIAdditionalLrs(BaseTestCase):
provider_schema = {
"id": "h5p-0",
"name": "H5P",
"description": "Open-source content collaboration framework",
"verbs": [
{
"id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked",
"label": "Unlocked",
"description": "Actor unlocked an object",
"defaultConsent": True,
"objects": [
{
"id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id",
"label": "Course",
"defaultConsent": True,
"matching": "id",
"definition": {
"type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course",
"name": {
"enUS": "A course within an LMS. Contains learning materials and activities"
},
},
},
],
}
],
"essentialVerbs": [],
"additionalLrs": [
{
"url": "http://localhost:5555/xapi/statements",
"token": "token_to_check",
"token_type": "Bearer"
}
]
}
statement = {
"actor": {"mbox": "mailto:test@mail.com"},
"verb": {"id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked"},
"object": {
"objectType": "Activity",
"definition": {
"type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course",
"name": {"de": "Testkurs KI:edu.nrw "},
},
"id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id",
},
"timestamp": (datetime.now() + timedelta(0,30)).strftime("%Y-%m-%dT%H:%M:%SZ"), # timedelta is used to ensure the statement is "after" the consent
}
additional_lrs_auth_headers = {'Authorization': 'Bearer token_to_check'}
@patch("xapi.views.store_in_db", mock_store_in_lrs)
@patch("xapi.views.requests.post")
def test_xapi_additional_lrs(self, mock_post):
"""
Ensure xAPI statement is forwarded to external LRS if configured in provider schema.
"""
# Create provider
with StringIO(json.dumps(self.provider_schema)) as fp:
response = self.provider_client.put(
"/api/v1/consents/provider/create",
{"provider-schema": fp},
format="multipart",
)
self.assertEqual(response.status_code, 201)
# create a verb group
group = {"id": "default_group", "label": "Group 2",
"description": "Lorem ipsum", "showVerbDetails": True, "purposeOfCollection": "Lorem Ipsum",
"requiresConsent": True, "verbs": [
{"id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked"},
]}
response = self.provider_client.post(
"/api/v1/consents/provider/" + str(Provider.objects.latest('id').id) + "/create-verb-group",
group,
format="json",
)
self.assertEqual(response.status_code, 200)
group_id = ProviderVerbGroup.objects.latest('id').id
# Create user consent for test user
user_consent = { "groups": [group_id] }
response = self.user_client.post(
"/api/v1/consents/user/save", user_consent, format="json"
)
self.assertEqual(response.status_code, 200)
access_token_h5p = ProviderAuthorization.objects.get(provider__name="H5P").key
client = APIClient()
client.credentials(HTTP_AUTHORIZATION="Basic " + access_token_h5p)
# create mock response for external LRS
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {'message': "xAPI statements successfully stored in LRS"}
mock_response.__bool__.return_value = True # important since we check "if not res" in xapi.views
# side effect to immediately create a copy of the object to preserve original properties (since, apparently, the magic mock passes the json object by reference)
def capture_args(*args, **kwargs):
self.captured_json = copy.deepcopy(kwargs.get('json'))
self.captured_headers = copy.deepcopy(kwargs.get('headers'))
return mock_response
mock_post.return_value = mock_response
mock_post.side_effect = capture_args
# Send xAPI statement
response = client.post(
"/xapi/statements",
self.statement,
format="json",
)
print(Provider.objects.all())
print(UserConsents.objects.all())
print(response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json()["message"], "xAPI statements successfully stored in LRS"
)
mock_post.assert_called_once()
assert mock_response.status_code == 200
if isinstance(self.captured_json, list): self.assertEqual(self.captured_json, [self.statement])
else: self.assertEqual(self.captured_json, self.statement)
self.assertEqual(self.captured_headers, self.additional_lrs_auth_headers)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment