feat: added tests
CI / test (push) Failing after 20s
CI / build (push) Has been skipped

This commit is contained in:
2026-07-16 15:08:04 +02:00
parent 46816c7820
commit b28293d5b2
142 changed files with 627 additions and 32118 deletions
+65
View File
@@ -0,0 +1,65 @@
import io
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from PIL import Image
from crochet.models import Pattern, PatternImage, StitchType
def make_test_image_file(name='test.png'):
buffer = io.BytesIO()
Image.new('RGB', (1, 1), color='red').save(buffer, format='PNG')
return SimpleUploadedFile(name, buffer.getvalue(), content_type='image/png')
class PatternModelTests(TestCase):
def test_defaults(self):
pattern = Pattern.objects.create()
self.assertEqual(pattern.sections, [])
self.assertEqual(pattern.page_settings, {})
def test_str_falls_back_to_uuid_without_title(self):
pattern = Pattern.objects.create()
self.assertEqual(str(pattern), str(pattern.uuid))
def test_str_uses_title_when_present(self):
pattern = Pattern.objects.create(page_settings={'title': 'Ampharos'})
self.assertEqual(str(pattern), 'Ampharos')
def test_uuid_is_unique_per_pattern(self):
first = Pattern.objects.create()
second = Pattern.objects.create()
self.assertNotEqual(first.uuid, second.uuid)
class PatternImageModelTests(TestCase):
def test_deleted_with_pattern(self):
pattern = Pattern.objects.create()
PatternImage.objects.create(pattern=pattern, image=make_test_image_file())
self.assertEqual(PatternImage.objects.count(), 1)
pattern.delete()
self.assertEqual(PatternImage.objects.count(), 0)
class StitchTypeModelTests(TestCase):
def test_str_uses_spanish_translation(self):
stitch_type = StitchType.objects.create(translations={'es': 'Punto bajo', 'en': 'SC'})
self.assertEqual(str(stitch_type), 'Punto bajo')
def test_str_falls_back_without_spanish_translation(self):
stitch_type = StitchType.objects.create(translations={})
self.assertEqual(str(stitch_type), f'StitchType #{stitch_type.pk}')
def test_ordered_by_order_then_id(self):
# El catálogo ya trae tipos de punto sembrados por las migraciones de
# datos (0004/0005), así que se filtra a los creados aquí en vez de
# comparar contra StitchType.objects.all() entero.
third = StitchType.objects.create(translations={'es': 'C'}, order=1)
first = StitchType.objects.create(translations={'es': 'A'}, order=0)
second = StitchType.objects.create(translations={'es': 'B'}, order=1)
created_ids = [first.id, third.id, second.id]
self.assertEqual(list(StitchType.objects.filter(id__in=created_ids)), [first, third, second])