37 lines
1.7 KiB
Plaintext
37 lines
1.7 KiB
Plaintext
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
|
|
define(`models', `Agency, Area, Attribution, BookingRule, Calendar, CalendarDate, FareAttribute, FareLegRule, FareMedium, FareProduct, FareRule, FareTransferRule, FeedInfo, Frequency, Level, LocationGroup, LocationGroupStop, LocationsGeojson, Network, Pathway, Route, RouteNetwork, Shape, Stop, StopArea, StopTime, Timeframe, Transfer, Translation, Trip')
|
|
define(`foreach', `ifelse(`$#', `1',``, `$1' `$2' `foreach(shift($@)', `$2'')')')
|
|
foreach(models, `echo(`class $1TestCase(TestCase):
|
|
def setUp(self):
|
|
self.model_fields = [f.name for f in $1._meta.fields]
|
|
self.gtfs_fields = get_all_fields("$1")
|
|
|
|
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 = $1(**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 = $1(**values)
|
|
self.assertIsNotNone(obj)
|
|
self.assertIsInstance(obj, models.Model)')')
|
|
|