예제 #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))