Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests/dataset model #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions backend/tests/factories.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions backend/tests/test_core_model.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions backend/tests/test_login_model.py
Original file line number Diff line number Diff line change
@@ -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)