bloombase/plants/tests/test_models.py
Stephan Kerkman b88ba03884 feat: location FK, multi-photo gallery, hide pruning history
- Location model: plants now FK to Location instead of free-text CharField
- Data migration 0004 converts existing location strings to Location objects
- PlantForm uses ModelChoiceField dropdown + inline "add new location" text field
- PlantPhoto model: multiple photos per plant with is_thumbnail flag
- Plant.thumbnail_url property: picks marked thumbnail, falls back to first photo then legacy photo field
- Photo gallery partial: upload, set thumbnail (★), delete (✕) with HTMX swaps on #photo-gallery
- plant_detail: uses thumbnail_url for hero image, pruning history section removed
- plant_list search updated: location__name__icontains instead of location__icontains
- Three new URL routes: upload_photo, set_thumbnail, delete_photo
- All 53 tests updated and passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-28 18:27:45 +02:00

55 lines
1.5 KiB
Python

import pytest
from plants.models import Species, Plant, PruningLog, Location
from datetime import date
def make_location(name):
loc, _ = Location.objects.get_or_create(name=name)
return loc
@pytest.mark.django_db
def test_species_str():
s = Species.objects.create(common_name='Rose')
assert str(s) == 'Rose'
@pytest.mark.django_db
def test_plant_str():
p = Plant.objects.create(name='Kitchen Fern', location=make_location('Kitchen'))
assert str(p) == 'Kitchen Fern'
@pytest.mark.django_db
def test_plant_species_nullable():
p = Plant.objects.create(name='Unknown plant')
assert p.species is None
@pytest.mark.django_db
def test_pruning_log_str():
p = Plant.objects.create(name='Rose', location=make_location('Garden'))
log = PruningLog.objects.create(plant=p, pruned_on=date(2026, 5, 1))
assert 'Rose' in str(log)
assert '2026-05-01' in str(log)
@pytest.mark.django_db
def test_plant_pruning_months_default():
p = Plant.objects.create(name='Fern', location=make_location('Office'))
assert p.pruning_months == []
@pytest.mark.django_db
def test_species_pruning_months_default():
s = Species.objects.create(common_name='Oak')
assert s.pruning_months == []
@pytest.mark.django_db
def test_delete_species_nulls_plant_species():
s = Species.objects.create(common_name='Rose')
p = Plant.objects.create(name='Garden rose', location=make_location('Garden'), species=s)
s.delete()
p.refresh_from_db()
assert p.species is None