Пример #1
0
    def clean(self, value):
        value = super().clean(value)
        if value is not None:
            # Exit early if this is percentage value.
            if is_percentage(value):
                return value
            else:
                value = machine_readable_bytes(value)

        # Run validation again, but with the min and max validators. This is
        # because the value has now been converted to an integer.
        self.validators = []
        if self.min_value is not None:
            self.validators.append(MinValueValidator(self.min_value))
        if self.max_value is not None:
            self.validators.append(MaxValueValidator(self.max_value))
        self.run_validators(value)
        return value
Пример #2
0
    def test_suffixes(self):
        self.assertEqual(machine_readable_bytes("987"), 987)
        self.assertEqual(machine_readable_bytes("987K"), 987000)
        self.assertEqual(machine_readable_bytes("987M"), 987000000)
        self.assertEqual(machine_readable_bytes("987G"), 987000000000)
        self.assertEqual(machine_readable_bytes("987T"), 987000000000000)
        self.assertEqual(machine_readable_bytes("987P"), 987000000000000000)
        self.assertEqual(machine_readable_bytes("987E"), 987000000000000000000)
        self.assertEqual(machine_readable_bytes("987k"), 987000)
        self.assertEqual(machine_readable_bytes("987m"), 987000000)
        self.assertEqual(machine_readable_bytes("987g"), 987000000000)
        self.assertEqual(machine_readable_bytes("987t"), 987000000000000)
        self.assertEqual(machine_readable_bytes("987p"), 987000000000000000)
        self.assertEqual(machine_readable_bytes("987e"), 987000000000000000000)

        self.assertRaises(ValueError, machine_readable_bytes, "987Z")
Пример #3
0
    def test_suffixes(self):
        self.assertEqual(machine_readable_bytes('987'), 987)
        self.assertEqual(machine_readable_bytes('987K'), 987000)
        self.assertEqual(machine_readable_bytes('987M'), 987000000)
        self.assertEqual(machine_readable_bytes('987G'), 987000000000)
        self.assertEqual(machine_readable_bytes('987T'), 987000000000000)
        self.assertEqual(machine_readable_bytes('987P'), 987000000000000000)
        self.assertEqual(machine_readable_bytes('987E'), 987000000000000000000)
        self.assertEqual(machine_readable_bytes('987k'), 987000)
        self.assertEqual(machine_readable_bytes('987m'), 987000000)
        self.assertEqual(machine_readable_bytes('987g'), 987000000000)
        self.assertEqual(machine_readable_bytes('987t'), 987000000000000)
        self.assertEqual(machine_readable_bytes('987p'), 987000000000000000)
        self.assertEqual(machine_readable_bytes('987e'), 987000000000000000000)

        self.assertRaises(ValueError, machine_readable_bytes, '987Z')