From 8aa90fd0fecab901b1691c337ad90562165f2ecd Mon Sep 17 00:00:00 2001 From: Benjamin Ledel <benjamin@schule-plus.com> Date: Wed, 12 Mar 2025 19:56:26 +0100 Subject: [PATCH] * fix more tests --- .../tests/tests_consent_operations.py | 78 ++++--------------- src/consents/tests/tests_third_party.py | 2 + src/providers/tests.py | 2 + src/users/tests.py | 4 +- 4 files changed, 22 insertions(+), 64 deletions(-) diff --git a/src/consents/tests/tests_consent_operations.py b/src/consents/tests/tests_consent_operations.py index 6b1ad22..926b613 100644 --- a/src/consents/tests/tests_consent_operations.py +++ b/src/consents/tests/tests_consent_operations.py @@ -5,6 +5,7 @@ from io import StringIO from django.test import TransactionTestCase from rest_framework.test import APIClient from rolepermissions.roles import assign_role +from django.core.management import call_command from providers.models import Provider, ProviderAuthorization, ProviderSchema, ProviderVerbGroup from users.models import CustomUser @@ -476,38 +477,9 @@ class TestUserConsentCreate(BaseTestCase): ) self.assertEqual(response.status_code, 200) group_id = ProviderVerbGroup.objects.latest('id').id - payload = [ - { - "providerId": Provider.objects.latest('id').id, - "providerSchemaId": ProviderSchema.objects.latest('id').id, - "verbs": [ - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/experienced", - "consented": True, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/QKGPPiIhI4zx9YAZZksLKigqyf7yW4WF","label":"1.1.1 Funktionen","defaultConsent":true,"definition":{"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,"definition":{"name":{"enUS":"2.3.1 Funktion Zirkulationsleitung"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/interacted", - "consented": False, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/ofN2ODcnLRaVu30lUpzrWPqF2AcG7g46","label":"1.2.3 Kappenventil","defaultConsent":true,"definition":{"name":{"enUS":"1.2.3 Kappenventil"}},"consented":true}]', - }, - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/answered", - "consented": False, - "objects": '[{"id":"http://h5p.example.com/expapi/activity/K34IszYvGE4R0cC72Ean6msLfLCJtQ8b","label":"7.2.1 Ventil Basics","defaultConsent":false,"definition":{"name":{"enUS":"7.2.1 Ventil Basics"}},"consented":true}]', - }, - ], - } - ] + payload = { + "groups": [group_id] + } response = self.user_client.post( @@ -529,13 +501,13 @@ class TestUserConsentCreate(BaseTestCase): active=True ).consented ) - self.assertFalse( + self.assertTrue( UserConsents.objects.get( verb__verb_id="http://h5p.example.com/expapi/verbs/interacted", active=True ).consented ) - self.assertFalse( + self.assertTrue( UserConsents.objects.get( verb__verb_id="http://h5p.example.com/expapi/verbs/answered", active=True @@ -974,6 +946,7 @@ class TestMultiUserConsent(BaseTestCase): user_email_2 = "user2@polaris.com" def setUp(self): + call_command('check_and_apply_migrations') CustomUser.objects.create_user(self.user_email_1, "polaris321") CustomUser.objects.create_user(self.user_email_2, "polaris321") # Obtain token for user 1 @@ -1016,7 +989,7 @@ class TestMultiUserConsent(BaseTestCase): self.provider_client = APIClient() self.provider_client.credentials(HTTP_AUTHORIZATION="Bearer " + provider_token) - def test_two_users_consent_same_verb(self): + def test_two_users_consent_same_group(self): """ Ensure users can consent to same verb. """ @@ -1043,34 +1016,13 @@ class TestMultiUserConsent(BaseTestCase): self.assertEqual(response.status_code, 200) group_id = ProviderVerbGroup.objects.latest('id').id - user_consent_1 = [ - { - "providerId": Provider.objects.latest('id').id, - "providerSchemaId": ProviderSchema.objects.latest('id').id, - "verbs": [ - { - "group_id": group_id, - "id": "http://h5p.example.com/expapi/verbs/experienced", - "consented": True, - "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}]', - } - ], - } - ] - user_consent_2 = [ - { - "providerId": Provider.objects.latest('id').id, - "providerSchemaId": ProviderSchema.objects.latest('id').id, - "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}]', - } - ], - } - ] + user_consent_1 = { + "groups": [group_id], + } + + user_consent_2 = { + "groups": [group_id], + } response = self.user_client_1.post( "/api/v1/consents/user/save", data=user_consent_1, format="json" diff --git a/src/consents/tests/tests_third_party.py b/src/consents/tests/tests_third_party.py index ffed8a1..ac44d8e 100644 --- a/src/consents/tests/tests_third_party.py +++ b/src/consents/tests/tests_third_party.py @@ -8,6 +8,7 @@ from django.core.management import call_command from consents.tests.tests_consent_operations import BaseTestCase from providers.models import ProviderAuthorization, Provider, ProviderVerbGroup, ProviderSchema from users.models import CustomUser +from django.core.management import call_command PROJECT_PATH = os.path.abspath(os.path.dirname(__name__)) @@ -201,6 +202,7 @@ class TestThirdPartyUserConsentUpdate(BaseTestCase): }, ] def setUp(self): + call_command('check_and_apply_migrations') normal_user = CustomUser.objects.create_user( self.test_user_email, self.test_user_password ) diff --git a/src/providers/tests.py b/src/providers/tests.py index 0051276..c7d75f0 100644 --- a/src/providers/tests.py +++ b/src/providers/tests.py @@ -4,6 +4,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.test import TestCase from rest_framework.test import APIClient from rolepermissions.roles import assign_role +from django.core.management import call_command from users.models import CustomUser @@ -20,6 +21,7 @@ class ProviderTestCase(TestCase): test_provider_password = "test123" def setUp(self): + call_command('check_and_apply_migrations') normal_user = CustomUser.objects.create_user(self.test_user_email, self.test_user_password) provider_user = CustomUser.objects.create_user(self.test_provider_email, self.test_provider_password) diff --git a/src/users/tests.py b/src/users/tests.py index afc4b76..6a49d12 100644 --- a/src/users/tests.py +++ b/src/users/tests.py @@ -1,6 +1,7 @@ from django.test import TestCase from rest_framework.test import APIClient from rolepermissions.roles import assign_role +from django.core.management import call_command from .models import CustomUser @@ -10,10 +11,11 @@ class UserTests(TestCase): test_provider_password = "test123" def setUp(self): + call_command('check_and_apply_migrations') provider_user = CustomUser.objects.create_user(self.test_provider_email, self.test_provider_password) assign_role(provider_user, 'user') - assign_role(provider_user, 'provider_manager') + assign_role(provider_user, 'polaris_administrator') def test_get_token(self): -- GitLab