From 556c1625514b7106cad67b2ebe3ccf1c241f02f6 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:51:59 +0100 Subject: [PATCH 1/6] added login model test --- backend/tests/test_login_model.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 backend/tests/test_login_model.py diff --git a/backend/tests/test_login_model.py b/backend/tests/test_login_model.py new file mode 100644 index 00000000..3f63d864 --- /dev/null +++ b/backend/tests/test_login_model.py @@ -0,0 +1,11 @@ +from django.test import TestCase +from login.models import OsmUser + + +class TestLoginModels(TestCase): + + def test_OsmUser_creation(self): + osm_user = OsmUser.objects.create(username="Test User", osm_id=123456) + + self.assertEqual(str(osm_user), "Test User") + self.assertEqual(osm_user.osm_id, 123456) From 1a9b4194fb19d4df3cbb8e601452466c85b42d93 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:08:10 +0100 Subject: [PATCH 2/6] added factory boy --- backend/tests/factories.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 backend/tests/factories.py diff --git a/backend/tests/factories.py b/backend/tests/factories.py new file mode 100644 index 00000000..eca34494 --- /dev/null +++ b/backend/tests/factories.py @@ -0,0 +1,21 @@ +import factory + +from login.models import OsmUser +from core.models import Dataset + + +class OsmUserFactory(factory.django.DjangoModelFactory): + class Meta: + model = OsmUser + + username = "Test User" + osm_id = 123456 + + +class DatasetFactory(factory.django.DjangoModelFactory): + class Meta: + model = Dataset + + name = "Test Dataset" + created_by = factory.SubFactory(OsmUserFactory) + status = -1 From 7a47d11c35d720bfc20a82c38f0470c61c47f810 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:11:43 +0100 Subject: [PATCH 3/6] added dataset creation test --- backend/tests/test_core_model.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 backend/tests/test_core_model.py diff --git a/backend/tests/test_core_model.py b/backend/tests/test_core_model.py new file mode 100644 index 00000000..58e299cb --- /dev/null +++ b/backend/tests/test_core_model.py @@ -0,0 +1,13 @@ +from django.test import TestCase + +from .factories import DatasetFactory, OsmUserFactory + + +class TestCoreModels(TestCase): + + def test_dataset_creation(self): + user = OsmUserFactory(username="Test User 2", osm_id=123) + dataset = DatasetFactory(created_by=user) + + self.assertEqual(dataset.name, "Test Dataset") + self.assertEqual(dataset.created_by, user) From 4aba08cb50827ba427a5244c84d37d1c31e89cbd Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:52:41 +0100 Subject: [PATCH 4/6] updated test to use OsmUserFactory --- backend/tests/test_login_model.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/tests/test_login_model.py b/backend/tests/test_login_model.py index 3f63d864..8ddc4136 100644 --- a/backend/tests/test_login_model.py +++ b/backend/tests/test_login_model.py @@ -1,11 +1,12 @@ from django.test import TestCase -from login.models import OsmUser + +from .factories import OsmUserFactory class TestLoginModels(TestCase): def test_OsmUser_creation(self): - osm_user = OsmUser.objects.create(username="Test User", osm_id=123456) + osm_user = OsmUserFactory() self.assertEqual(str(osm_user), "Test User") self.assertEqual(osm_user.osm_id, 123456) From f8d78dac3d914d2e688ac84faa9ffb23e18a2a35 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:22:11 +0100 Subject: [PATCH 5/6] added aoi factory --- backend/tests/factories.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/tests/factories.py b/backend/tests/factories.py index eca34494..243db6f5 100644 --- a/backend/tests/factories.py +++ b/backend/tests/factories.py @@ -1,7 +1,9 @@ import factory from login.models import OsmUser -from core.models import Dataset +from core.models import Dataset, AOI + +from django.contrib.gis.geos import GEOSGeometry class OsmUserFactory(factory.django.DjangoModelFactory): @@ -19,3 +21,12 @@ class Meta: name = "Test Dataset" created_by = factory.SubFactory(OsmUserFactory) status = -1 + + +class AoiFactory(factory.django.DjangoModelFactory): + class Meta: + model = AOI + + geom = GEOSGeometry("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))", srid=4326) + dataset = factory.SubFactory(DatasetFactory) + label_status = -1 From 094d395a9cecc479ecb7ee900f77953abe32e938 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:23:07 +0100 Subject: [PATCH 6/6] added test set up --- backend/tests/test_core_model.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/tests/test_core_model.py b/backend/tests/test_core_model.py index 58e299cb..5fc09afb 100644 --- a/backend/tests/test_core_model.py +++ b/backend/tests/test_core_model.py @@ -1,13 +1,19 @@ from django.test import TestCase -from .factories import DatasetFactory, OsmUserFactory +from .factories import DatasetFactory, OsmUserFactory, AoiFactory class TestCoreModels(TestCase): + def setUp(self): + self.user = OsmUserFactory(username="Test User 2", osm_id=123) + self.dataset = DatasetFactory(created_by=self.user) + self.aoi = AoiFactory(dataset=self.dataset) + def test_dataset_creation(self): - user = OsmUserFactory(username="Test User 2", osm_id=123) - dataset = DatasetFactory(created_by=user) + self.assertEqual(self.dataset.name, "Test Dataset") + self.assertEqual(self.dataset.created_by, self.user) - self.assertEqual(dataset.name, "Test Dataset") - self.assertEqual(dataset.created_by, user) + def test_aoi_creation(self): + self.assertEqual(self.aoi.dataset, self.dataset) + self.assertEqual(self.aoi.label_status, -1)