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 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) 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)