diff --git a/api/models.py b/api/models.py index 7757914..6d0f555 100644 --- a/api/models.py +++ b/api/models.py @@ -95,7 +95,7 @@ def save(self, *args, **kwargs): # Accessing the authenticated user's username and token username = self.data_owner.bro_user_token password = self.data_owner.bro_user_password - + # Start the celery task tasks.upload_bro_data_task.delay(self.uuid, username, password) diff --git a/api/tests/test_models.py b/api/tests/test_models.py index 431c157..bca6cc4 100644 --- a/api/tests/test_models.py +++ b/api/tests/test_models.py @@ -4,17 +4,19 @@ from gmn import models as gmn_models from gmw import models as gmw_models + @pytest.fixture def organisation(): organisation = api_models.Organisation.objects.create( name="Nieuwegein", - kvk_number = "12345678", - bro_user_token = "secret", - bro_user_password = "secret", + kvk_number="12345678", + bro_user_token="secret", + bro_user_password="secret", ) organisation.save() return organisation + @pytest.fixture def gmn(organisation): return gmn_models.GMN( @@ -22,6 +24,7 @@ def gmn(organisation): bro_id="GMN123456789", ) + @pytest.fixture def gmw(organisation): return gmw_models.GMW( @@ -29,10 +32,12 @@ def gmw(organisation): bro_id="GMW123456789", ) + @pytest.mark.django_db def test_organisation_name(organisation): assert str(organisation) == "Nieuwegein" + @pytest.mark.django_db def test_import_task_name(organisation): import_task = api_models.ImportTask( @@ -43,10 +48,11 @@ def test_import_task_name(organisation): assert str(import_task) == "GMN import - Nieuwegein" + @pytest.mark.django_db def test_import_task_save_method(organisation): import_task = api_models.ImportTask.objects.create( - data_owner = organisation, + data_owner=organisation, bro_domain="gmn", kvk_number="12345678", status="", @@ -55,6 +61,7 @@ def test_import_task_save_method(organisation): import_task.refresh_from_db() assert api_models.ImportTask.objects.count() == 1 + @pytest.mark.django_db def test_upload_task_name(organisation): upload_task = api_models.UploadTask( @@ -67,27 +74,29 @@ def test_upload_task_name(organisation): assert str(upload_task) == "Nieuwegein: GMN_StartRegistration (registration)" + @pytest.mark.django_db def test_upload_task_save_method(organisation): upload_task = api_models.UploadTask.objects.create( - data_owner = organisation, + data_owner=organisation, bro_domain="gmn", project_number="1", status="PENDING", - registration_type = "GMN_StartRegistration", - request_type = "registration", + registration_type="GMN_StartRegistration", + request_type="registration", metadata={}, sourcedocument_data={}, - ) upload_task.save() upload_task.refresh_from_db() assert api_models.UploadTask.objects.count() == 1 + @pytest.mark.django_db def test_gmn_name(gmn): assert str(gmn) == "GMN123456789" + @pytest.mark.django_db def test_measuringpoint_name(organisation, gmn): measuringpoint = gmn_models.Measuringpoint( @@ -97,11 +106,11 @@ def test_measuringpoint_name(organisation, gmn): assert str(measuringpoint) == "MP1234" - @pytest.mark.django_db def test_gmw_name(gmw): assert str(gmw) == "GMW123456789" + @pytest.mark.django_db def test_monitoringtube_name(organisation, gmw): monitoring_tube = gmw_models.MonitoringTube(