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

Add tests for models in the core app #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
add tests for the dataset model in the core app
- modify the dataset model with a __str__ return
- modify .gitignore by adding env folders
  • Loading branch information
tony-nyagah committed Mar 12, 2024
commit 804e4768a95e06028cb104ff84f39a669aaa5dbc
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -49,3 +49,7 @@ trainings/*
backend/.env
backend/config.txt
backend/postgres-data

# virtualenvs
.venv/
.env/
3 changes: 3 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@ class DatasetStatus(models.IntegerChoices):
default=-1, choices=DatasetStatus.choices
) # 0 for active , 1 for archieved

def __str__(self):
return self.name


class AOI(models.Model):
class DownloadStatus(models.IntegerChoices):
40 changes: 40 additions & 0 deletions backend/tests/test_core_dataset_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from core.models import Dataset
from django.test import TestCase
from login.models import OsmUser


class DatasetModelTest(TestCase):
@classmethod
def setUpTestData(cls):
# Set up non-modified objects used by all test methods
cls.osm_user = OsmUser.objects.create(osm_id="123456789", username="testuser")
cls.dataset = Dataset.objects.create(
name="Test Dataset",
created_by=cls.osm_user,
source_imagery="http://example.com/image.png",
status=Dataset.DatasetStatus.ACTIVE,
)

def test_dataset_creation(self):
# Test the Dataset instance has been created properly.
self.assertTrue(isinstance(self.dataset, Dataset))
self.assertEqual(self.dataset.__str__(), self.dataset.name)

def test_dataset_status(self):
# Test the status field works as expected
self.assertEqual(self.dataset.status, Dataset.DatasetStatus.ACTIVE)

def test_dataset_fields(self):
# Test all fields for correct values
self.assertEqual(self.dataset.name, "Test Dataset")
self.assertEqual(self.dataset.created_by, self.osm_user)
self.assertEqual(self.dataset.source_imagery, "http://example.com/image.png")
self.assertEqual(self.dataset.status, Dataset.DatasetStatus.ACTIVE)
# Ensure auto_now_add fields are populated
self.assertIsNotNone(self.dataset.created_at)
# Ensure auto_now fields are populated
self.assertIsNotNone(self.dataset.last_modified)

def test_string_representation(self):
# Test the string representation of a Dataset instance
self.assertEqual(str(self.dataset), "Test Dataset")