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
This commit is contained in:
parent
6472673d0a
commit
7962ec4b6c
4
transport_accessibility/api/convenience.py
Normal file
4
transport_accessibility/api/convenience.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from pt_map.models import *
|
||||
import osmnx
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
169
transport_accessibility/pt_map/test_data.py
Normal file
169
transport_accessibility/pt_map/test_data.py
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
from pt_map.models import *
|
||||
from pt_map.model_test_fields import field_requirements
|
||||
|
||||
def get_all_fields(model_name):
|
||||
for m in field_requirements:
|
||||
if m["model"] == model_name:
|
||||
return m["fields"]
|
||||
|
||||
def get_required_fields(model_name):
|
||||
required_fields = []
|
||||
for field in get_all_fields(model_name):
|
||||
if field["required"] == "true":
|
||||
required_fields.append(field)
|
||||
return required_fields
|
||||
|
||||
def get_optional_fields(model_name):
|
||||
optional_fields = []
|
||||
for field in get_all_fields(model_name):
|
||||
if field["required"] == "false":
|
||||
optional_fields.append(field)
|
||||
return optional_fields
|
||||
|
||||
def get_conditionally_required_fields(model_name):
|
||||
conditionally_required_fields = []
|
||||
for field in get_all_fields(model_name):
|
||||
if field["required"] == "if":
|
||||
conditionally_required_fields.append(field)
|
||||
return conditionally_required_fields
|
||||
|
||||
def get_conditionally_forbidden_fields(model_name):
|
||||
conditionally_forbidden_fields = []
|
||||
for field in get_all_fields(model_name):
|
||||
if field.get("forbidden_if") or field.get("forbidden_if_not") or field.get("forbidden_if_eq") or field.get("forbidden_if_not_eq"):
|
||||
conditionally_forbidden_fields.append(field)
|
||||
return conditionally_forbidden_fields
|
||||
|
||||
data = [
|
||||
{
|
||||
"name": "Fulton Conley",
|
||||
"telephone": "1-538-373-2858",
|
||||
"email": "duis@google.net",
|
||||
"url": "http://bbc.co.uk",
|
||||
"pk": "WKQ42OFT7XX",
|
||||
"str": "tincidunt orci quis lectus. Nullam suscipit, est ac",
|
||||
"time": "00:34:56",
|
||||
"date": "20231223",
|
||||
"curcode": "TRY",
|
||||
"timezone": "Europe/Paris",
|
||||
"langcode": "ZO"
|
||||
},
|
||||
{
|
||||
"name": "Donna Collins",
|
||||
"telephone": "1-858-166-4735",
|
||||
"email": "arcu.vestibulum.ante@yahoo.org",
|
||||
"url": "http://youtube.com",
|
||||
"pk": "TEP72JJR8XE",
|
||||
"str": "gravida molestie arcu. Sed eu nibh vulputate mauris",
|
||||
"time": "04:14:54",
|
||||
"date": "20240903",
|
||||
"curcode": "HKD",
|
||||
"timezone": "Africa/Abidjan",
|
||||
"langcode": "RQ"
|
||||
},
|
||||
{
|
||||
"name": "Tad Jensen",
|
||||
"telephone": "(767) 770-8531",
|
||||
"email": "dolor.egestas.rhoncus@icloud.com",
|
||||
"url": "http://baidu.com",
|
||||
"pk": "UVO18XXG8IB",
|
||||
"str": "montes, nascetur ridiculus mus. Aenean eget magna. Suspendisse tristique",
|
||||
"time": "20:27:48",
|
||||
"date": "20240322",
|
||||
"curcode": "KZT",
|
||||
"timezone": "Europe/Paris",
|
||||
"langcode": "GI"
|
||||
},
|
||||
{
|
||||
"name": "Calvin Harrison",
|
||||
"telephone": "1-547-884-7735",
|
||||
"email": "etiam.laoreet@google.net",
|
||||
"url": "https://instagram.com",
|
||||
"pk": "NCV69RJX3HR",
|
||||
"str": "aptent taciti sociosqu ad litora",
|
||||
"time": "18:55:30",
|
||||
"date": "20240720",
|
||||
"curcode": "PLN",
|
||||
"timezone": "Asia/Atyrau",
|
||||
"langcode": "DP"
|
||||
},
|
||||
{
|
||||
"name": "Phillip Britt",
|
||||
"telephone": "(445) 832-4949",
|
||||
"email": "nulla.tincidunt@protonmail.net",
|
||||
"url": "http://naver.com",
|
||||
"pk": "HGW71LUD1QL",
|
||||
"str": "ultricies dignissim",
|
||||
"time": "00:42:36",
|
||||
"date": "20230627",
|
||||
"curcode": "CHF",
|
||||
"timezone": "Africa/Addis_Ababa",
|
||||
"langcode": "CB"
|
||||
},
|
||||
{
|
||||
"name": "Branden Leblanc",
|
||||
"telephone": "(621) 519-7201",
|
||||
"email": "erat.etiam@google.edu",
|
||||
"url": "https://google.com",
|
||||
"pk": "BIT71WZZ5MT",
|
||||
"str": "Nunc pulvinar arcu et pede.",
|
||||
"time": "13:57:23",
|
||||
"date": "20250116",
|
||||
"curcode": "MUR",
|
||||
"timezone": "Asia/Atyrau",
|
||||
"langcode": "YD"
|
||||
},
|
||||
{
|
||||
"name": "Bradley Larson",
|
||||
"telephone": "1-699-788-9354",
|
||||
"email": "et.commodo@icloud.edu",
|
||||
"url": "https://whatsapp.com",
|
||||
"pk": "UON48QSJ0RD",
|
||||
"str": "dui,",
|
||||
"time": "01:26:35",
|
||||
"date": "20231004",
|
||||
"curcode": "EUR",
|
||||
"timezone": "Europe/Berlin",
|
||||
"langcode": "BU"
|
||||
},
|
||||
{
|
||||
"name": "Scarlet Patterson",
|
||||
"telephone": "(451) 444-7817",
|
||||
"email": "scelerisque.scelerisque@outlook.edu",
|
||||
"url": "http://wikipedia.org",
|
||||
"pk": "LHE29UCR4BJ",
|
||||
"str": "lacus. Cras",
|
||||
"time": "13:51:51",
|
||||
"date": "20240602",
|
||||
"curcode": "SEK",
|
||||
"timezone": "Asia/Damascus",
|
||||
"langcode": "DY"
|
||||
},
|
||||
{
|
||||
"name": "Latifah Alvarez",
|
||||
"telephone": "(266) 713-8186",
|
||||
"email": "mauris.magna@icloud.edu",
|
||||
"url": "https://youtube.com",
|
||||
"pk": "VOQ57DYR9CU",
|
||||
"str": "orci tincidunt adipiscing. Mauris molestie pharetra nibh. Aliquam ornare,",
|
||||
"time": "03:54:44",
|
||||
"date": "20240923",
|
||||
"curcode": "XCD",
|
||||
"timezone": "Africa/Addis_Ababa",
|
||||
"langcode": "OT"
|
||||
},
|
||||
{
|
||||
"name": "Thane Moran",
|
||||
"telephone": "1-674-463-6771",
|
||||
"email": "odio.etiam.ligula@icloud.edu",
|
||||
"url": "https://pinterest.com",
|
||||
"pk": "CGR74BDF1DH",
|
||||
"str": "eu metus. In lorem. Donec elementum,",
|
||||
"time": "15:58:50",
|
||||
"date": "20231225",
|
||||
"curcode": "RUB",
|
||||
"timezone": "Africa/Abidjan",
|
||||
"langcode": "KS"
|
||||
}
|
||||
]
|
||||
|
||||
|
|
@ -1,26 +1,35 @@
|
|||
from django.test import TestCase
|
||||
from pt_map.models import Agency, FeedInfo, Level, Stop, Route, Shape, Calendar, CalendarDate, LocationGroup, LocationGroupStop, LocationsGeojson, Trip, StopArea, StopTime, FareAttribute, FareLegRule, FareMedium, FareProduct, FareTransferRule, FareRule, Frequency, Transfer, Pathway, BookingRule, Translation, Attribution, Network, RouteNetwork, Area, Timeframe
|
||||
from datetime import date, datetime
|
||||
|
||||
# Create your tests here.
|
||||
class FeedInfoTestCase(TestCase):
|
||||
def setUp(self):
|
||||
FeedInfo.objects.create(feed_publisher_name="All fields", feed_publisher_url='example.com', feed_lang='pl', default_lang='pl', feed_start_date=datetime(2024, 1, 1), feed_end_date=datetime.now(), feed_version='1.0', feed_contact_email='me@example.com', feed_contact_url='example.com')
|
||||
def test_ok(self):
|
||||
FeedInfo.objects.get(feed_publisher_name="All fields")
|
||||
FeedInfo.objects.get(feed_publisher_url='example.com')
|
||||
FeedInfo.objects.get(feed_lang='pl')
|
||||
FeedInfo.objects.get(default_lang='pl')
|
||||
FeedInfo.objects.get(feed_start_date=datetime(2024, 1, 1))
|
||||
FeedInfo.objects.get(feed_end_date=datetime.now())
|
||||
FeedInfo.objects.get(feed_version='1.0')
|
||||
FeedInfo.objects.get(feed_contact_email='me@example.com')
|
||||
FeedInfo.objects.get(feed_contact_email='me@example.com')
|
||||
|
||||
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):
|
||||
FeedInfo.objects.create(feed_publisher_name="All fields", feed_publisher_url='example.com', feed_lang='pl', default_lang='pl', feed_start_date=datetime(2024, 1, 1), feed_end_date=datetime.now(), feed_version='1.0', feed_contact_email='me@example.com', feed_contact_url='example.com')
|
||||
Agency.objects.create(agency_name='test', agency_url='example.com', agency_timezone='Europe/Berlin', agency_lang='pl', agency_phone='0123456574', agency_fare_url='example.com', agency_email='me@example.com', feed_info_id=FeedInfo.objects.get(feed_publisher_name="All fields"))
|
||||
def test_ok(self):
|
||||
print(Agency.objects.get(agency_name='test').feed_info_id.feed_id)
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user