Coverage for test_models.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
1import pytest
2from app.examples.models import Car
4from plain.exceptions import ValidationError
7def test_create_unique_constraint(db):
8 Car.objects.create(make="Toyota", model="Tundra")
10 with pytest.raises(ValidationError) as e:
11 Car.objects.create(make="Toyota", model="Tundra")
13 assert (
14 str(e)
15 == "<ExceptionInfo ValidationError({'__all__': ['A car with this make and model already exists.']}) tblen=5>"
16 )
18 assert Car.objects.count() == 1
21def test_update_or_create_unique_constraint(db):
22 Car.objects.update_or_create(make="Toyota", model="Tundra")
23 Car.objects.update_or_create(make="Toyota", model="Tundra")
25 assert Car.objects.count() == 1