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 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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) From 57fbc02eab492acdaa4a5fd62efbe193ca937c14 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:59:14 +0100 Subject: [PATCH 07/12] added Label factory --- backend/tests/factories.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/tests/factories.py b/backend/tests/factories.py index 243db6f5..b9d2b821 100644 --- a/backend/tests/factories.py +++ b/backend/tests/factories.py @@ -1,9 +1,7 @@ import factory from login.models import OsmUser -from core.models import Dataset, AOI - -from django.contrib.gis.geos import GEOSGeometry +from core.models import Dataset, AOI, Label class OsmUserFactory(factory.django.DjangoModelFactory): @@ -27,6 +25,15 @@ class AoiFactory(factory.django.DjangoModelFactory): class Meta: model = AOI - geom = GEOSGeometry("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))", srid=4326) + geom = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))" dataset = factory.SubFactory(DatasetFactory) label_status = -1 + + +class LabelFactory(factory.django.DjangoModelFactory): + + class Meta: + model = Label + + aoi = factory.SubFactory(AoiFactory) + geom = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))" From e0d557403f980445bf363ebfe639e52874e2729a Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:59:38 +0100 Subject: [PATCH 08/12] added label creation test --- backend/tests/test_core_model.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/tests/test_core_model.py b/backend/tests/test_core_model.py index 5fc09afb..c808ae6b 100644 --- a/backend/tests/test_core_model.py +++ b/backend/tests/test_core_model.py @@ -1,6 +1,6 @@ from django.test import TestCase -from .factories import DatasetFactory, OsmUserFactory, AoiFactory +from .factories import DatasetFactory, OsmUserFactory, AoiFactory, LabelFactory class TestCoreModels(TestCase): @@ -9,6 +9,7 @@ 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) + self.label = LabelFactory(aoi=self.aoi) def test_dataset_creation(self): self.assertEqual(self.dataset.name, "Test Dataset") @@ -17,3 +18,6 @@ def test_dataset_creation(self): def test_aoi_creation(self): self.assertEqual(self.aoi.dataset, self.dataset) self.assertEqual(self.aoi.label_status, -1) + + def test_label_creation(self): + self.assertEqual(self.label.aoi, self.aoi) From b8672fc11c940312dc5ba23b531fd522c077927f Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:18:26 +0100 Subject: [PATCH 09/12] added Model 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 b9d2b821..651140c9 100644 --- a/backend/tests/factories.py +++ b/backend/tests/factories.py @@ -1,7 +1,7 @@ import factory from login.models import OsmUser -from core.models import Dataset, AOI, Label +from core.models import Dataset, AOI, Label, Model class OsmUserFactory(factory.django.DjangoModelFactory): @@ -37,3 +37,14 @@ class Meta: aoi = factory.SubFactory(AoiFactory) geom = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))" + + +class ModelFactory(factory.django.DjangoModelFactory): + + class Meta: + model = Model + + dataset = factory.SubFactory(DatasetFactory) + name = "Test Model" + created_by = factory.SubFactory(OsmUserFactory) + status = -1 From 93965fdbf92f4645cd27cb6f9620054468b46595 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:18:50 +0100 Subject: [PATCH 10/12] added Model creation test --- backend/tests/test_core_model.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/tests/test_core_model.py b/backend/tests/test_core_model.py index c808ae6b..49673a99 100644 --- a/backend/tests/test_core_model.py +++ b/backend/tests/test_core_model.py @@ -1,6 +1,12 @@ from django.test import TestCase -from .factories import DatasetFactory, OsmUserFactory, AoiFactory, LabelFactory +from .factories import ( + DatasetFactory, + OsmUserFactory, + AoiFactory, + LabelFactory, + ModelFactory, +) class TestCoreModels(TestCase): @@ -10,6 +16,7 @@ def setUp(self): self.dataset = DatasetFactory(created_by=self.user) self.aoi = AoiFactory(dataset=self.dataset) self.label = LabelFactory(aoi=self.aoi) + self.model = ModelFactory(dataset=self.dataset, created_by=self.user) def test_dataset_creation(self): self.assertEqual(self.dataset.name, "Test Dataset") @@ -21,3 +28,9 @@ def test_aoi_creation(self): def test_label_creation(self): self.assertEqual(self.label.aoi, self.aoi) + + def test_model_creation(self): + self.assertEqual(self.model.name, "Test Model") + self.assertEqual(self.model.dataset, self.dataset) + self.assertEqual(self.model.created_by, self.user) + self.assertEqual(self.model.status, -1) From e1cb21a15f3385104403fc70bcced405e452a81b Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:12:42 +0100 Subject: [PATCH 11/12] added training factory --- backend/tests/factories.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/tests/factories.py b/backend/tests/factories.py index 651140c9..fd089b12 100644 --- a/backend/tests/factories.py +++ b/backend/tests/factories.py @@ -1,7 +1,7 @@ import factory from login.models import OsmUser -from core.models import Dataset, AOI, Label, Model +from core.models import Dataset, AOI, Label, Model, Training class OsmUserFactory(factory.django.DjangoModelFactory): @@ -48,3 +48,16 @@ class Meta: name = "Test Model" created_by = factory.SubFactory(OsmUserFactory) status = -1 + + +class TrainingFactory(factory.django.DjangoModelFactory): + + class Meta: + model = Training + + model = factory.SubFactory(ModelFactory) + status = "SUBMITTED" + zoom_level = [20, 21] + created_by = factory.SubFactory(OsmUserFactory) + epochs = 3 + batch_size = 24 From af30aca031562346577d97994b5bfbe1fc6164c8 Mon Sep 17 00:00:00 2001 From: Oluwanifemi Daramola <76186151+nifedara@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:13:05 +0100 Subject: [PATCH 12/12] added training test --- backend/tests/test_core_model.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/tests/test_core_model.py b/backend/tests/test_core_model.py index 49673a99..6dd89886 100644 --- a/backend/tests/test_core_model.py +++ b/backend/tests/test_core_model.py @@ -6,6 +6,7 @@ AoiFactory, LabelFactory, ModelFactory, + TrainingFactory, ) @@ -17,6 +18,7 @@ def setUp(self): self.aoi = AoiFactory(dataset=self.dataset) self.label = LabelFactory(aoi=self.aoi) self.model = ModelFactory(dataset=self.dataset, created_by=self.user) + self.training = TrainingFactory(model=self.model, created_by=self.user) def test_dataset_creation(self): self.assertEqual(self.dataset.name, "Test Dataset") @@ -34,3 +36,11 @@ def test_model_creation(self): self.assertEqual(self.model.dataset, self.dataset) self.assertEqual(self.model.created_by, self.user) self.assertEqual(self.model.status, -1) + + def test_training_creation(self): + self.assertEqual(self.training.model, self.model) + self.assertEqual(self.training.status, "SUBMITTED") + self.assertEqual(self.training.zoom_level, [20, 21]) + self.assertEqual(self.training.created_by, self.user) + self.assertEqual(self.training.epochs, 3) + self.assertEqual(self.training.batch_size, 24)