diff --git a/dragonroost/animals/forms.py b/dragonroost/animals/forms.py index 93474c1..3d20ea6 100644 --- a/dragonroost/animals/forms.py +++ b/dragonroost/animals/forms.py @@ -131,6 +131,11 @@ class Meta: class MedicalRecordForm(forms.ModelForm): + current_weight = MeasurementField( + measurement=Weight, + unit_choices=(("lb", "lb"), ("kg", "kg"), ("g", "g")), + ) + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper(self) diff --git a/dragonroost/animals/managers.py b/dragonroost/animals/managers.py index b7a4c2c..17a431f 100644 --- a/dragonroost/animals/managers.py +++ b/dragonroost/animals/managers.py @@ -11,4 +11,4 @@ def get_animals_needing_medical_attention(self): i.e. where the status is "MEDICAL_HOLD". """ - return self.filter(status="MEDICAL_HOLD" / "QUARANTINE") + return self.filter(status="QUARANTINE") diff --git a/dragonroost/animals/models.py b/dragonroost/animals/models.py index b848fb8..dac24f4 100644 --- a/dragonroost/animals/models.py +++ b/dragonroost/animals/models.py @@ -46,7 +46,7 @@ def __str__(self): return self.name def get_absolute_url(self): - return reverse("species_detail", args=[str(self.id)]) + return reverse("animals:species-detail", args=[str(self.id)]) class Breed(models.Model): @@ -75,7 +75,7 @@ def __str__(self): return self.name def get_absolute_url(self): - return reverse("breed_detail", args=[str(self.id)]) + return reverse("animals:breed-detail", args=[str(self.id)]) class Animal(models.Model): @@ -190,7 +190,7 @@ def animal_tag(self): @property def is_available(self): - return self.status != "ADOPTED" + return self.status == "AVAILABLE" @property def days_since_intake(self): diff --git a/dragonroost/animals/tests/factories.py b/dragonroost/animals/tests/factories.py index 17f60d8..01d4999 100644 --- a/dragonroost/animals/tests/factories.py +++ b/dragonroost/animals/tests/factories.py @@ -1,7 +1,10 @@ import factory +from measurement.measures import Weight +from dragonroost.animals.models import Breed from dragonroost.animals.models import Species from dragonroost.business.tests.factories import LocationFactory +from dragonroost.people.tests.factories import PersonFactory class SpeciesFactory(factory.django.DjangoModelFactory): @@ -21,6 +24,19 @@ class Meta: is_ohio_native = factory.Iterator([True, False]) +class BreedFactory(factory.django.DjangoModelFactory): + class Meta: + model = "animals.Breed" + django_get_or_create = ("name", "origin", "temperament") + + name = factory.Sequence(lambda n: f"Breed {n}") + origin = factory.Faker("country") + temperament = factory.Faker( + "random_element", + elements=[x[0] for x in Breed.TEMPERAMENT_CHOICES], + ) + + class AnimalFactory(factory.django.DjangoModelFactory): class Meta: model = "animals.Animal" @@ -29,3 +45,17 @@ class Meta: name = factory.Faker("first_name") species = factory.SubFactory(SpeciesFactory) location = factory.SubFactory(LocationFactory) + breed = None + starting_weight = Weight(lb=10) + status = factory.Iterator(["AVAILABLE", "QUARANTINE"]) + + +class MedicalRecordFactory(factory.django.DjangoModelFactory): + class Meta: + model = "animals.MedicalRecord" + django_get_or_create = ("animal", "notes") + + notes = factory.Faker("text") + current_weight = Weight(lb=15) + animal = factory.SubFactory(AnimalFactory) + q_volunteer = factory.SubFactory(PersonFactory) diff --git a/dragonroost/animals/tests/test_models.py b/dragonroost/animals/tests/test_models.py index e69de29..ddde78d 100644 --- a/dragonroost/animals/tests/test_models.py +++ b/dragonroost/animals/tests/test_models.py @@ -0,0 +1,72 @@ +import pytest + +from dragonroost.animals.models import Animal +from dragonroost.animals.models import MedicalRecord + + +# Animal model tests +@pytest.mark.django_db +def test_animal_queryset_get_available_animals(animals): + qs = Animal.objects.get_available_animals() + assert qs.count() > 0 + assert all(animal.status == "AVAILABLE" for animal in qs) + + +@pytest.mark.django_db +def test_animal_queryset_get_animals_needing_medical_attention(animals): + qs = Animal.objects.get_animals_needing_medical_attention() + assert qs.count() > 0 + assert all(animal.status == "QUARANTINE" for animal in qs) + + +@pytest.mark.django_db +def test_animal_str_method(animal): + assert str(animal) == animal.name + + +@pytest.mark.django_db +def test_animal_get_absolute_url(animal): + assert animal.get_absolute_url() == f"/animals/{animal.pk}/" + + +@pytest.mark.django_db +def test_animal_get_animal_tag(animal): + assert animal.animal_tag == f"A-{animal.pk:05d}" + + +@pytest.mark.django_db +def test_animal_is_available(animal_is_available): + assert animal_is_available.is_available is True + + +@pytest.mark.django_db +def test_animal_number_of_medical_records(medical_record): + animal = medical_record.animal + number_of_records = 1 + assert animal.number_of_medical_records == number_of_records + + +@pytest.mark.django_db +def test_animal_latest_medical_record(medical_record): + animal = medical_record.animal + latest_medical_record = MedicalRecord.objects.filter(animal=animal).latest( + "created", + ) + assert animal.latest_medical_record == latest_medical_record + + +# Species model tests +@pytest.mark.django_db +def test_species_str_method(species): + assert str(species) == species.name + + +@pytest.mark.django_db +def test_species_get_absolute_url(species): + assert species.get_absolute_url() == f"/animals/species/{species.pk}/detail/" + + +# MedicalRecord model tests +@pytest.mark.django_db +def test_medical_record_str_method(medical_record): + assert str(medical_record) == medical_record.notes diff --git a/dragonroost/conftest.py b/dragonroost/conftest.py index 3942c73..c4d3b3a 100644 --- a/dragonroost/conftest.py +++ b/dragonroost/conftest.py @@ -4,6 +4,7 @@ from dragonroost.animals.models import MedicalRecord from dragonroost.animals.models import Species from dragonroost.animals.tests.factories import AnimalFactory +from dragonroost.animals.tests.factories import MedicalRecordFactory from dragonroost.animals.tests.factories import SpeciesFactory from dragonroost.users.models import User from dragonroost.users.tests.factories import UserFactory @@ -21,14 +22,24 @@ def user(db) -> User: @pytest.fixture def species(db) -> Species: - return SpeciesFactory.create_batch(5) + return SpeciesFactory.create() @pytest.fixture -def animals(db, species) -> Animal: +def animal(db) -> Animal: + return AnimalFactory() + + +@pytest.fixture +def animals(db) -> Animal: return AnimalFactory.create_batch(5) @pytest.fixture -def medical_records(db, animals) -> MedicalRecord: - return MedicalRecord.objects.filter(animal__in=animals) +def animal_is_available(db) -> Animal: + return AnimalFactory.create(status="AVAILABLE") + + +@pytest.fixture +def medical_record(db) -> MedicalRecord: + return MedicalRecordFactory() diff --git a/dragonroost/people/tests/factories.py b/dragonroost/people/tests/factories.py index e69de29..3db9162 100644 --- a/dragonroost/people/tests/factories.py +++ b/dragonroost/people/tests/factories.py @@ -0,0 +1,13 @@ +import factory + +from dragonroost.people.models import Person + + +class PersonFactory(factory.django.DjangoModelFactory): + class Meta: + model = Person + + first_name = factory.Faker("first_name") + last_name = factory.Faker("last_name") + email = factory.Faker("email") + phone_number = "555-5555" diff --git a/dragonroost/templates/business/location_detail.html b/dragonroost/templates/business/location_detail.html index 671a309..298d82a 100644 --- a/dragonroost/templates/business/location_detail.html +++ b/dragonroost/templates/business/location_detail.html @@ -1,8 +1,20 @@ -{% extends "base.html" %} - -{% block content %} -

{{ location.name }} - Detail

-

{{ location.description }}

- Edit - Delete -{% endblock content %} +