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)

