Skip to content

Commit

Permalink
fix docstring in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danangmassandy committed Jun 25, 2024
1 parent 5002247 commit a3cfd60
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
12 changes: 11 additions & 1 deletion django_project/gap/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# ground_observations/factories.py
# coding=utf-8
"""
Tomorrow Now GAP.
.. note:: Factory classes for Models
"""
import factory
from factory.django import DjangoModelFactory
from gap.models import (
Expand All @@ -8,6 +13,7 @@


class ProviderFactory(DjangoModelFactory):
"""Factory class for Provider model."""
class Meta:
model = Provider

Expand All @@ -16,6 +22,7 @@ class Meta:


class AttributeFactory(DjangoModelFactory):
"""Factory class for Attribute model."""
class Meta:
model = Attribute

Expand All @@ -26,6 +33,7 @@ class Meta:


class CountryFactory(DjangoModelFactory):
"""Factory class for Country model."""
class Meta:
model = Country

Expand All @@ -40,6 +48,7 @@ class Meta:


class StationFactory(DjangoModelFactory):
"""Factory class for Station model."""
class Meta:
model = Station

Expand All @@ -54,6 +63,7 @@ class Meta:


class MeasurementFactory(DjangoModelFactory):
"""Factory class for Measurement model."""
class Meta:
model = Measurement

Expand Down
3 changes: 3 additions & 0 deletions django_project/gap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

class Provider(Definition):
"""Model representing a data provider."""

pass


class Attribute(Definition):
"""Model representing an attribute of a measurement."""

pass


Expand All @@ -29,6 +31,7 @@ class Country(Definition):
geometry (Polygon):
MultiPolygonField geometry representing the country boundaries.
"""

iso_a3 = models.CharField(
unique=True,
max_length=255
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# coding=utf-8
"""
Tomorrow Now GAP.
.. note:: Unit tests for GAP Models.
"""

from django.test import TestCase
from gap.models import (
Provider, Attribute, Country, Station, Measurement
Expand All @@ -15,16 +22,19 @@ class ProviderCRUDTest(TestCase):
"""Provider test case"""

def test_create_provider(self):
"""Test create provider object."""
provider = ProviderFactory()
self.assertIsInstance(provider, Provider)
self.assertTrue(Provider.objects.filter(id=provider.id).exists())

def test_read_provider(self):
"""Test read provider object."""
provider = ProviderFactory()
fetched_provider = Provider.objects.get(id=provider.id)
self.assertEqual(provider, fetched_provider)

def test_update_provider(self):
"""Test update provider object."""
provider = ProviderFactory()
new_name = "Updated Provider Name"
provider.name = new_name
Expand All @@ -33,6 +43,7 @@ def test_update_provider(self):
self.assertEqual(updated_provider.name, new_name)

def test_delete_provider(self):
"""Test delete provider object."""
provider = ProviderFactory()
provider_id = provider.id
provider.delete()
Expand All @@ -43,16 +54,19 @@ class AttributeCRUDTest(TestCase):
"""Attribute test case"""

def test_create_attribute(self):
"""Test create attribute object."""
attribute = AttributeFactory()
self.assertIsInstance(attribute, Attribute)
self.assertTrue(Attribute.objects.filter(id=attribute.id).exists())

def test_read_attribute(self):
"""Test read attribute object."""
attribute = AttributeFactory()
fetched_attribute = Attribute.objects.get(id=attribute.id)
self.assertEqual(attribute, fetched_attribute)

def test_update_attribute(self):
"""Test update attribute object."""
attribute = AttributeFactory()
new_name = "Updated Attribute Name"
attribute.name = new_name
Expand All @@ -61,6 +75,7 @@ def test_update_attribute(self):
self.assertEqual(updated_attribute.name, new_name)

def test_delete_attribute(self):
"""Test delete attribute object."""
attribute = AttributeFactory()
attribute_id = attribute.id
attribute.delete()
Expand All @@ -71,16 +86,19 @@ class CountryCRUDTest(TestCase):
"""Country test case"""

def test_create_country(self):
"""Test create country object."""
country = CountryFactory()
self.assertIsInstance(country, Country)
self.assertTrue(Country.objects.filter(id=country.id).exists())

def test_read_country(self):
"""Test read country object."""
country = CountryFactory()
fetched_country = Country.objects.get(id=country.id)
self.assertEqual(country, fetched_country)

def test_update_country(self):
"""Test update country object."""
country = CountryFactory()
new_name = "Updated Country Name"
country.name = new_name
Expand All @@ -89,6 +107,7 @@ def test_update_country(self):
self.assertEqual(updated_country.name, new_name)

def test_delete_country(self):
"""Test delete country object."""
country = CountryFactory()
country_id = country.id
country.delete()
Expand All @@ -99,16 +118,19 @@ class StationCRUDTest(TestCase):
"""Station test case"""

def test_create_station(self):
"""Test create station object."""
station = StationFactory()
self.assertIsInstance(station, Station)
self.assertTrue(Station.objects.filter(id=station.id).exists())

def test_read_station(self):
"""Test read station object."""
station = StationFactory()
fetched_station = Station.objects.get(id=station.id)
self.assertEqual(station, fetched_station)

def test_update_station(self):
"""Test update station object."""
station = StationFactory()
new_name = "Updated Station Name"
station.name = new_name
Expand All @@ -117,6 +139,7 @@ def test_update_station(self):
self.assertEqual(updated_station.name, new_name)

def test_delete_station(self):
"""Test delete station object."""
station = StationFactory()
station_id = station.id
station.delete()
Expand All @@ -127,16 +150,19 @@ class MeasurementCRUDTest(TestCase):
"""Measurement test case"""

def test_create_measurement(self):
"""Test create measurement object."""
measurement = MeasurementFactory()
self.assertIsInstance(measurement, Measurement)
self.assertTrue(Measurement.objects.filter(id=measurement.id).exists())

def test_read_measurement(self):
"""Test read measurement object."""
measurement = MeasurementFactory()
fetched_measurement = Measurement.objects.get(id=measurement.id)
self.assertEqual(measurement, fetched_measurement)

def test_update_measurement(self):
"""Test update measurement object."""
measurement = MeasurementFactory()
new_value = 42.0
measurement.value = new_value
Expand All @@ -145,6 +171,7 @@ def test_update_measurement(self):
self.assertEqual(updated_measurement.value, new_value)

def test_delete_measurement(self):
"""Test delete measurement object."""
measurement = MeasurementFactory()
measurement_id = measurement.id
measurement.delete()
Expand Down

0 comments on commit a3cfd60

Please sign in to comment.