From 2d7ca494bd1f1d6cbad997a5a19d31838f3f6b4c Mon Sep 17 00:00:00 2001 From: Stephan Kerkman Date: Mon, 1 Jun 2026 16:40:59 +0200 Subject: [PATCH] feat: add Location.cover_photo ImageField + migration + test --- plants/migrations/0011_location_cover_photo.py | 18 ++++++++++++++++++ plants/models.py | 1 + plants/tests/test_location_redesign.py | 16 ++++++++++++++++ pytest.ini | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 plants/migrations/0011_location_cover_photo.py create mode 100644 plants/tests/test_location_redesign.py diff --git a/plants/migrations/0011_location_cover_photo.py b/plants/migrations/0011_location_cover_photo.py new file mode 100644 index 0000000..756a9c7 --- /dev/null +++ b/plants/migrations/0011_location_cover_photo.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.1 on 2026-06-01 14:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('plants', '0010_add_frost_density_to_species'), + ] + + operations = [ + migrations.AddField( + model_name='location', + name='cover_photo', + field=models.ImageField(blank=True, null=True, upload_to='locations/'), + ), + ] diff --git a/plants/models.py b/plants/models.py index 0e1bfb0..9de63ad 100644 --- a/plants/models.py +++ b/plants/models.py @@ -3,6 +3,7 @@ from django.db import models class Location(models.Model): name = models.CharField(max_length=200, unique=True) + cover_photo = models.ImageField(upload_to='locations/', blank=True, null=True) class Meta: ordering = ['name'] diff --git a/plants/tests/test_location_redesign.py b/plants/tests/test_location_redesign.py new file mode 100644 index 0000000..4daa4c4 --- /dev/null +++ b/plants/tests/test_location_redesign.py @@ -0,0 +1,16 @@ +import pytest +from django.core.files.uploadedfile import SimpleUploadedFile +from plants.models import Location + + +@pytest.mark.django_db +def test_location_cover_photo_field_exists(): + """Location can be saved with and without a cover_photo.""" + loc = Location.objects.create(name='Test Garden') + assert loc.cover_photo.name == '' or loc.cover_photo.name is None + + fake_img = SimpleUploadedFile('cover.jpg', b'fake-image-data', content_type='image/jpeg') + loc.cover_photo = fake_img + loc.save() + loc.refresh_from_db() + assert loc.cover_photo.name.startswith('locations/') diff --git a/pytest.ini b/pytest.ini index 991009f..1141f67 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -DJANGO_SETTINGS_MODULE = plantdb.settings +DJANGO_SETTINGS_MODULE = bloombase.settings