aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/tests/test_models.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-05-22 20:48:05 +0100
committerMatthew Lemon <y@yulqen.org>2024-05-22 20:48:05 +0100
commit6985c83f55f4b60f531c77d333aeb34b0105c956 (patch)
treef85d972c2a0a3e8e65a308d327e712fe4885d2e8 /pyblackbird_cc/resources/tests/test_models.py
parentc7261ae893583707d1720492f67b5a3f5ffcdf72 (diff)
Resource now has a feature slot field
Diffstat (limited to 'pyblackbird_cc/resources/tests/test_models.py')
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py
index 56416f4..34f2905 100644
--- a/pyblackbird_cc/resources/tests/test_models.py
+++ b/pyblackbird_cc/resources/tests/test_models.py
@@ -3,6 +3,7 @@ from unittest.mock import patch
import pytest
from django.test import TestCase
+from django.db import IntegrityError
from pyblackbird_cc.resources.factories import PDFPageSnapshotModelFactory
from pyblackbird_cc.resources.models import PDFPageSnapshot
@@ -12,6 +13,7 @@ from pyblackbird_cc.resources.models import ResourceCategory
from pyblackbird_cc.resources.models import ResourceType
from pyblackbird_cc.resources.views import ResourceInfo
from pyblackbird_cc.resources.views import _extract_metadata_from_resource
+from pyblackbird_cc.resources.factories import ResourceModelFactory
# TODO - convert this test into the test of a function
# that takes a Resource object and returns all the PDF snapshots
@@ -34,6 +36,28 @@ def test_resource_model(resources):
assert "pdf_page_snapshot_0.jpg" in r1.get_pdf_snapshot_file_names()
+@pytest.mark.django_db()
+def test_can_add_feature_slots_to_resource():
+ r = ResourceModelFactory()
+ r.feature_slot = 1
+ r.save()
+ assert r.feature_slot == 1
+
+
+@pytest.mark.django_db()
+def test_resource_slot_int_must_be_unique():
+ """
+ Test that a resource feature slot must be unique.
+ """
+ r1 = ResourceModelFactory()
+ r2 = ResourceModelFactory()
+ r1.feature_slot = 1
+ r1.save()
+ r2.feature_slot = 1
+ with pytest.raises(IntegrityError):
+ r2.save()
+
+
class ResourceModelTest(TestCase):
def test_string_representation(self):
resource = Resource(name="Test Resource")