Ejemplo n.º 1
0
    def test_registry01(self):
        "Register in __init__"
        registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)

        period1 = registry.get_period(MinutesPeriod.name, 1)
        self.assertIsInstance(period1, MinutesPeriod)

        period2 = registry.get_period(HoursPeriod.name, 1)
        self.assertIsInstance(period2, HoursPeriod)

        self.assertIsNone(registry.get_period('invalid', 1))
Ejemplo n.º 2
0
    def setUpClass(cls):
        super().setUpClass()

        cls.registry = DatePeriodRegistry(
            MinutesPeriod,
            HoursPeriod,
            DaysPeriod,
            WeeksPeriod,
            MonthsPeriod,
            YearsPeriod,
        )
Ejemplo n.º 3
0
    def test_registry02(self):
        "register() method"
        registry = DatePeriodRegistry()
        registry.register(DaysPeriod, WeeksPeriod)

        period = registry.get_period(DaysPeriod.name, 1)
        self.assertIsInstance(period, DaysPeriod)

        self.assertIsNone(registry.get_period(MinutesPeriod.name, 1))
Ejemplo n.º 4
0
    def test_registry03(self):
        "Duplicates"
        registry = DatePeriodRegistry()

        with self.assertRaises(registry.RegistrationError):
            registry.register(DaysPeriod, WeeksPeriod, DaysPeriod)
Ejemplo n.º 5
0
 def test_registry_3(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     field = DatePeriodField()
     field.period_registry = registry
     self.assertEqual(list(registry.choices()), list(field.choices))
Ejemplo n.º 6
0
 def test_registry_2(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     self.assertEqual(
         list(registry.choices()),
         list(DatePeriodField(period_registry=registry).choices))
Ejemplo n.º 7
0
 def test_registry_3(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     field = DatePeriodField()
     field.period_registry = registry
     self.assertListEqual([*registry.choices()], [*field.choices])
Ejemplo n.º 8
0
 def test_registry_2(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     self.assertListEqual(
         [*registry.choices()],
         [*DatePeriodField(period_registry=registry).choices]
     )