diff --git a/backend/tests/factories.py b/backend/tests/factories.py new file mode 100644 index 00000000..243db6f5 --- /dev/null +++ b/backend/tests/factories.py @@ -0,0 +1,32 @@ +import factory + +from login.models import OsmUser +from core.models import Dataset, AOI + +from django.contrib.gis.geos import GEOSGeometry + + +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 + + +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 diff --git a/backend/tests/test_core_model.py b/backend/tests/test_core_model.py new file mode 100644 index 00000000..5fc09afb --- /dev/null +++ b/backend/tests/test_core_model.py @@ -0,0 +1,19 @@ +from django.test import TestCase + +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): + self.assertEqual(self.dataset.name, "Test Dataset") + self.assertEqual(self.dataset.created_by, self.user) + + def test_aoi_creation(self): + self.assertEqual(self.aoi.dataset, self.dataset) + self.assertEqual(self.aoi.label_status, -1) diff --git a/backend/tests/test_login_model.py b/backend/tests/test_login_model.py new file mode 100644 index 00000000..8ddc4136 --- /dev/null +++ b/backend/tests/test_login_model.py @@ -0,0 +1,12 @@ +from django.test import TestCase + +from .factories import OsmUserFactory + + +class TestLoginModels(TestCase): + + def test_OsmUser_creation(self): + osm_user = OsmUserFactory() + + self.assertEqual(str(osm_user), "Test User") + self.assertEqual(osm_user.osm_id, 123456)