| | 2 | |
| | 3 | Example: |
| | 4 | |
| | 5 | |
| | 6 | {{{ |
| | 7 | # model |
| | 8 | class Worker(models.Model): |
| | 9 | ... |
| | 10 | disabled = models.BooleanField(default=False) |
| | 11 | max_execution = models.PositiveSmallIntegerField(default=3600, null=False) |
| | 12 | |
| | 13 | |
| | 14 | # testcase |
| | 15 | class TestModelWorker(unittest.TestCase): |
| | 16 | |
| | 17 | def test_max_execution(self): |
| | 18 | # Here we expect a Python ValueError to be raised when providing a string |
| | 19 | # as an argument to what is a `PositiveSmallIntegerField` |
| | 20 | with self.assertRaises(ValueError) as e: |
| | 21 | Worker.create( |
| | 22 | name="Worker", |
| | 23 | max_execution='s' |
| | 24 | ) |
| | 25 | |
| | 26 | self.assertIn('invalid literal for int() with base 10', str(e.exception)) |
| | 27 | |
| | 28 | def test_disabled(self): |
| | 29 | # While here we can expect a `ValidationError` when providing a string to a `BooleanField` |
| | 30 | with self.assertRaises(ValidationError) as e: |
| | 31 | Worker.create( |
| | 32 | name="Worker", |
| | 33 | disabled='s' |
| | 34 | ) |
| | 35 | }}} |
| | 36 | |