31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import pytest
|
|
from birds.models import Bird
|
|
|
|
|
|
class TestBirdModel:
|
|
def test_create_bird(self, db):
|
|
bird = Bird.objects.create(common_name="Blue Jay")
|
|
assert bird.common_name == "Blue Jay"
|
|
assert bird.uuid is not None
|
|
assert str(bird) == "Blue Jay"
|
|
|
|
def test_find_or_create_new(self, db):
|
|
bird = Bird.find_or_create("American Robin")
|
|
assert bird.common_name == "American Robin"
|
|
|
|
def test_find_or_create_existing(self, db, bird):
|
|
result = Bird.find_or_create("Northern Cardinal")
|
|
assert result.id == bird.id
|
|
assert result.common_name == "Northern Cardinal"
|
|
|
|
def test_find_or_create_case_insensitive(self, db, bird):
|
|
result = Bird.find_or_create("northern cardinal")
|
|
assert result.id == bird.id
|
|
|
|
def test_bird_str(self, db):
|
|
bird = Bird.objects.create(common_name="Mourning Dove")
|
|
assert str(bird) == "Mourning Dove"
|
|
|
|
def test_bird_scientific_name(self, db, bird):
|
|
assert bird.scientific_name == "Cardinalis cardinalis"
|