Пример #1
0
    def test_ok02(self):
        "Minutes"
        period = DatePeriodField().clean(['minutes', '5'])
        self.assertIsInstance(period, DatePeriod)

        create_dt = self.create_datetime
        self.assertEqual(
            create_dt(year=2014, month=7, day=2, hour=22, minute=14),
            create_dt(year=2014, month=7, day=2, hour=22, minute=9) +
            period.as_timedelta())
Пример #2
0
 def test_period_names_2(self):
     field = DatePeriodField()
     field.period_names = names = (MinutesPeriod.name, HoursPeriod.name)
     self.assertListEqual(
         [*date_period_registry.choices(choices=names)],
         [*field.choices],
     )
Пример #3
0
    def test_invalid(self):
        clean = DatePeriodField().clean
        self.assertFieldValidationError(IntegerField, 'invalid', clean, ['years', 'notint'])

        name = 'unknownperiod'
        self.assertFieldValidationError(ChoiceField, 'invalid_choice', clean,
                                        [name, '2'], message_args={'value': name},
                                       )
Пример #4
0
 def test_not_required(self):
     clean = DatePeriodField(required=False).clean
     self.assertIsNone(clean(['', '']))
     self.assertIsNone(clean(['']))
     self.assertIsNone(clean([]))
     self.assertIsNone(clean(['days', '']))
     self.assertIsNone(clean(['days']))
     self.assertIsNone(clean(['', 2]))
Пример #5
0
    def test_period_names(self):
        clean = DatePeriodField(period_names=('months',)).clean
        period = clean(['months', '5'])
        self.assertIsInstance(period, DatePeriod)

        name = 'years'
        self.assertFieldValidationError(ChoiceField, 'invalid_choice', clean,
                                        [name, '2'], message_args={'value': name},
                                       )
Пример #6
0
    def test_notnull(self):
        with self.assertRaises(ValidationError) as cm:
            DatePeriodField().clean(['days', '0'])

        self.assertEqual([
            _(u'Ensure this value is greater than or equal to %(limit_value)s.'
              ) % {
                  'limit_value': 1
              },
        ], cm.exception.messages)
Пример #7
0
 def test_choices(self):
     choices = [*DatePeriodField().choices]
     self.assertInChoices(
         value=MinutesPeriod.name, label=MinutesPeriod.verbose_name, choices=choices,
     )
     self.assertInChoices(
         value=HoursPeriod.name, label=HoursPeriod.verbose_name, choices=choices,
     )
     self.assertInChoices(
         value=DaysPeriod.name, label=DaysPeriod.verbose_name, choices=choices,
     )
Пример #8
0
 def test_required(self):
     clean = DatePeriodField().clean
     self.assertFieldValidationError(DatePeriodField, 'required', clean,
                                     ['', ''])
     self.assertFieldValidationError(DatePeriodField, 'required', clean,
                                     None)
Пример #9
0
 def test_period_names_2(self):
     field = DatePeriodField()
     field.period_names = names = (MinutesPeriod.name, HoursPeriod.name)
     self.assertEqual(list(date_period_registry.choices(choices=names)),
                      list(field.choices))
Пример #10
0
 def test_registry_1(self):
     self.assertListEqual([*date_period_registry.choices()],
                          [*DatePeriodField().choices]
                         )
Пример #11
0
 def test_registry_3(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     field = DatePeriodField()
     field.period_registry = registry
     self.assertEqual(list(registry.choices()), list(field.choices))
Пример #12
0
 def test_period_names_1(self):
     names = (MinutesPeriod.name, HoursPeriod.name)
     self.assertEqual(list(date_period_registry.choices(choices=names)),
                      list(DatePeriodField(period_names=names).choices))
Пример #13
0
 def test_registry_2(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     self.assertEqual(
         list(registry.choices()),
         list(DatePeriodField(period_registry=registry).choices))
Пример #14
0
 def test_period_names_1(self):
     names = (MinutesPeriod.name, HoursPeriod.name)
     self.assertListEqual(
         [*date_period_registry.choices(choices=names)],
         [*DatePeriodField(period_names=names).choices],
     )
Пример #15
0
 def test_empty(self):
     self.assertIsNone(DatePeriodField(required=False).clean(None))
Пример #16
0
 def test_registry_3(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     field = DatePeriodField()
     field.period_registry = registry
     self.assertListEqual([*registry.choices()], [*field.choices])
Пример #17
0
 def test_registry_2(self):
     registry = DatePeriodRegistry(MinutesPeriod, HoursPeriod)
     self.assertListEqual(
         [*registry.choices()],
         [*DatePeriodField(period_registry=registry).choices]
     )
Пример #18
0
 def test_choices(self):
     choices = list(DatePeriodField().choices)
     self.assertIn((MinutesPeriod.name, MinutesPeriod.verbose_name),
                   choices)
     self.assertIn((HoursPeriod.name, HoursPeriod.verbose_name), choices)
     self.assertIn((DaysPeriod.name, DaysPeriod.verbose_name), choices)
Пример #19
0
 def test_registry_1(self):
     self.assertEqual(list(date_period_registry.choices()),
                      list(DatePeriodField().choices))