Esempio n. 1
0
    def test_url_field_invalid(self):
        """
        Ensure that invalid URL fields are detected.
        """

        duration_field = DurationField("test_url_field_invalid", "title", "this is a test")

        self.assertRaises(FieldValidationException, lambda: duration_field.to_python("1 treefrog"))
        self.assertRaises(FieldValidationException, lambda: duration_field.to_python("minute"))
Esempio n. 2
0
    def test_url_field_invalid(self):
        """
        Ensure that invalid URL fields are detected.
        """

        duration_field = DurationField("test_url_field_invalid", "title",
                                       "this is a test")

        self.assertRaises(FieldValidationException,
                          lambda: duration_field.to_python("1 treefrog"))
        self.assertRaises(FieldValidationException,
                          lambda: duration_field.to_python("minute"))
Esempio n. 3
0
    def test_duration_valid(self):
        """
        Tests the conversion of the duration string to an integer.
        """
        duration_field = DurationField("test_duration_valid", "title", "this is a test")

        self.assertEqual(duration_field.to_python("1m"), 60)
        self.assertEqual(duration_field.to_python("5m"), 300)
        self.assertEqual(duration_field.to_python("5 minute"), 300)
        self.assertEqual(duration_field.to_python("5"), 5)
        self.assertEqual(duration_field.to_python("5h"), 18000)
        self.assertEqual(duration_field.to_python("2d"), 172800)
        self.assertEqual(duration_field.to_python("2w"), 86400 * 7 * 2)
Esempio n. 4
0
    def test_duration_valid(self):
        """
        Tests the conversion of the duration string to an integer.
        """
        duration_field = DurationField("test_duration_valid", "title",
                                       "this is a test")

        self.assertEqual(duration_field.to_python("1m"), 60)
        self.assertEqual(duration_field.to_python("5m"), 300)
        self.assertEqual(duration_field.to_python("5 minute"), 300)
        self.assertEqual(duration_field.to_python("5"), 5)
        self.assertEqual(duration_field.to_python("5h"), 18000)
        self.assertEqual(duration_field.to_python("2d"), 172800)
        self.assertEqual(duration_field.to_python("2w"), 86400 * 7 * 2)