Coverage for test_models.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-23 11:16 -0600

1import pytest 

2from app.examples.models import Car 

3 

4from plain.exceptions import ValidationError 

5 

6 

7def test_create_unique_constraint(db): 

8 Car.objects.create(make="Toyota", model="Tundra") 

9 

10 with pytest.raises(ValidationError) as e: 

11 Car.objects.create(make="Toyota", model="Tundra") 

12 

13 assert ( 

14 str(e) 

15 == "<ExceptionInfo ValidationError({'__all__': ['A car with this make and model already exists.']}) tblen=5>" 

16 ) 

17 

18 assert Car.objects.count() == 1 

19 

20 

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") 

24 

25 assert Car.objects.count() == 1