transport-accessibility/transport_accessibility/pt_map/tests.py
Johannes Randerath 7962ec4b6c Added prerequisites to add tests and db convenience
- api/convenience will hold convenience functions for database lookup
  and data grouping
- pt_map/model_test_fields holds the data from the GTFS reference
  relevant to model development
- pt_map/test_data holds example data to be used to test models
2024-06-26 15:34:02 +02:00

36 lines
1.3 KiB
Python

from django.test import TestCase
from pt_map.test_data import *
from pt_map.models import *
import unittest
from django.db import models
import random
class AgencyTestCase(TestCase):
def setUp(self):
self.model_fields = [f.name for f in Agency._meta.fields]
self.gtfs_fields = get_all_fields("Agency")
def test_all_fields_present(self):
"""Make sure the model has properties for all fields - regardless if required - provided by the GTFS standard."""
for f in self.gtfs_fields:
with self.subTest(f=f):
self.assertIn(f["name"], self.model_fields)
def test_constructor_all_fields(self):
"""Make sure all of the models fields of the model are initializable"""
with self.subTest(name="fixed"):
"""Fixed subTest"""
d = data[0]
values = {f["name"]: d[f["type"]] for f in self.gtfs_fields}
obj = Agency(**values)
self.assertIsNotNone(obj)
self.assertIsInstance(obj, models.Model)
with self.subTest(name="other"):
d = data[random.randint(0,len(data))]
values = {f["name"]: d[f["type"]] for f in self.gtfs_fields}
obj = Agency(**values)
self.assertIsNotNone(obj)
self.assertIsInstance(obj, models.Model)