From 1a2dd00b73bfce671094b12565b700b29f0d9800 Mon Sep 17 00:00:00 2001 From: Benjamin Ledel <benjamin@schule-plus.com> Date: Wed, 12 Mar 2025 19:37:40 +0100 Subject: [PATCH] * fix some tests --- src/xapi/tests/tests.py | 257 +-------------------- src/xapi/tests/tests_verb_id_validation.py | 184 ++------------- 2 files changed, 25 insertions(+), 416 deletions(-) diff --git a/src/xapi/tests/tests.py b/src/xapi/tests/tests.py index 4ed2866..95f0db7 100644 --- a/src/xapi/tests/tests.py +++ b/src/xapi/tests/tests.py @@ -290,38 +290,7 @@ class TestxAPIWithDataRecordingPause(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/experienced", - "consented": False, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF","label":"1.1.1 Funktionen","defaultConsent":true, "matching": "definitionType" ,"definition":{"type": "http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF", "name":{"enUS":"1.1.1 Funktionen"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/attempted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm","label":"2.3.1 Funktion Zirkulationsleitung","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm", "name":{"enUS":"2.3.1 Funktion Zirkulationsleitung"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/interacted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46","label":"1.2.3 Kappenventil","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46", "name":{"enUS":"1.2.3 Kappenventil"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/answered", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b","label":"7.2.1 Ventil Basics","defaultConsent":false, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b", "name":{"enUS":"7.2.1 Ventil Basics"}},"consented":true}]', - }, - ], - } - ] + user_consent = { "groups": [group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -426,38 +395,7 @@ class TestxAPIStatementActorAccount(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/experienced", - "consented": False, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF","label":"1.1.1 Funktionen","defaultConsent":true, "matching": "definitionType" ,"definition":{"type": "http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF", "name":{"enUS":"1.1.1 Funktionen"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/attempted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm","label":"2.3.1 Funktion Zirkulationsleitung","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm", "name":{"enUS":"2.3.1 Funktion Zirkulationsleitung"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/interacted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46","label":"1.2.3 Kappenventil","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46", "name":{"enUS":"1.2.3 Kappenventil"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/answered", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b","label":"7.2.1 Ventil Basics","defaultConsent":false, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b", "name":{"enUS":"7.2.1 Ventil Basics"}},"consented":true}]', - }, - ], - } - ] + user_consent = { "groups": [group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -528,38 +466,7 @@ class TestxAPIStatementActorAccount(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/experienced", - "consented": False, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF","label":"1.1.1 Funktionen","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF", "name":{"enUS":"1.1.1 Funktionen"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/attempted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm","label":"2.3.1 Funktion Zirkulationsleitung","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm", "name":{"enUS":"2.3.1 Funktion Zirkulationsleitung"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/interacted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46","label":"1.2.3 Kappenventil","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46", "name":{"enUS":"1.2.3 Kappenventil"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/answered", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b","label":"7.2.1 Ventil Basics","defaultConsent":false, "matching": "definitionType" ,"definition":{"type": "http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b", "name":{"enUS":"7.2.1 Ventil Basics"}},"consented":true}]', - }, - ], - } - ] + user_consent = { "groups": [group_id, group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -627,38 +534,7 @@ class TestxAPIStatementActorAccount(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/experienced", - "consented": False, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF","label":"1.1.1 Funktionen","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF", "name":{"enUS":"1.1.1 Funktionen"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/attempted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm","label":"2.3.1 Funktion Zirkulationsleitung","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/VeH7S8NeGlCRM1myYRDBjHMCknLqDLgm", "name":{"enUS":"2.3.1 Funktion Zirkulationsleitung"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/interacted", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46","label":"1.2.3 Kappenventil","defaultConsent":true, "matching": "definitionType", "definition":{"type": "http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46", "name":{"enUS":"1.2.3 Kappenventil"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/answered", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b","label":"7.2.1 Ventil Basics","defaultConsent":false, "matching": "definitionType" ,"definition":{"type": "http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b", "name":{"enUS":"7.2.1 Ventil Basics"}},"consented":true}]', - }, - ], - } - ] + user_consent = { "groups": [group_id, group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -777,36 +653,7 @@ class TestxAPIObjectMatchingDefinitionType(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": True, - } - ] - ), - } - ], - } - ] + user_consent = { "groups": [group_id, group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -923,36 +770,7 @@ class TestxAPIObjectMatchingDefinitiondId(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "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" - }, - }, - "consented": True, - } - ] - ), - } - ], - } - ] + user_consent = { "groups": [group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -1070,36 +888,7 @@ class TestxAPITimestampAfterConsent(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "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" - }, - }, - "consented": True, - } - ] - ), - } - ], - } - ] + user_consent = { "groups": [group_id] } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) @@ -1240,36 +1029,8 @@ class TextxAPIAdditionalLrs(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "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" - }, - }, - "consented": True, - } - ] - ), - } - ], - } - ] + user_consent = { "groups": [group_id] } + response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) diff --git a/src/xapi/tests/tests_verb_id_validation.py b/src/xapi/tests/tests_verb_id_validation.py index 8ce02da..22fb132 100644 --- a/src/xapi/tests/tests_verb_id_validation.py +++ b/src/xapi/tests/tests_verb_id_validation.py @@ -52,7 +52,7 @@ class TestxAPIVerbAndObjectValidation(BaseTestCase): } @patch("xapi.views.store_in_db", mock_store_in_lrs) - def test_statement_ambiguous_verb_id_rejected(self): + def test_statement_ambiguous_empty_groups_rejected(self): """ """ # Create provider with StringIO(json.dumps(self.provider_schema)) as fp: @@ -77,75 +77,22 @@ class TestxAPIVerbAndObjectValidation(BaseTestCase): self.assertEqual(response.status_code, 200) group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": True, - } - ] - ), - }, - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": False, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": True, - } - ] - ), - }, - ], - } - ] + response = self.user_client.post( - "/api/v1/consents/user/save", user_consent, format="json" + "/api/v1/consents/user/save", {}, format="json" ) self.assertEqual(response.status_code, 400) self.assertJSONEqual( str(response.content, encoding="utf8"), - [ { - "non_field_errors": [ - "Verb https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked contains ambiguous consent." + "groups": [ + "This field is required." ] } - ], ) @patch("xapi.views.store_in_db", mock_store_in_lrs) - def test_statement_ambiguous_object_id_rejected(self): + def test_statement_ambiguous_group_id_rejected(self): """ """ # Create provider with StringIO(json.dumps(self.provider_schema)) as fp: @@ -171,71 +118,20 @@ class TestxAPIVerbAndObjectValidation(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": True, - } - ] - ), - }, - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": False, - } - ] - ), - }, - ], - } - ] + user_consent = { + "groups": [group_id, 2323242423232] + } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) self.assertEqual(response.status_code, 400) self.assertJSONEqual( str(response.content, encoding="utf8"), - [ { "non_field_errors": [ - "Verb https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked contains ambiguous object consents." + "Group with id 2323242423232 does not exist." ] - } - ], + }, ) @patch("xapi.views.store_in_db", mock_store_in_lrs) @@ -265,62 +161,14 @@ class TestxAPIVerbAndObjectValidation(BaseTestCase): group_id = ProviderVerbGroup.objects.latest('id').id # Create user consent for test user - user_consent = [ - { - "providerId": 1, - "providerSchemaId": 1, - "verbs": [ - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": True, - } - ] - ), - }, - { - "group_id": group_id, - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/verbs/unlocked", - "consented": True, - "objects": json.dumps( - [ - { - "id": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/my-random-object-id", - "label": "Course", - "defaultConsent": True, - "matching": "definitionType", - "definition": { - "type": "https://xapi.elearn.rwth-aachen.de/definitions/lms/activities/course", - "name": { - "enUS": "A course within an LMS. Contains learning materials and activities" - }, - }, - "consented": True, - } - ] - ), - }, - ], - } - ] + user_consent = { + "groups": [group_id, group_id] + } response = self.user_client.post( "/api/v1/consents/user/save", user_consent, format="json" ) + self.assertEqual(response.status_code, 200) self.assertEqual( - response.json()["message"], "user consent saved" + response.json()["message"], "user consents saved" ) \ No newline at end of file -- GitLab