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/4] 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/4] 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/4] 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/4] 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)