aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/tests
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
parentc7261ae893583707d1720492f67b5a3f5ffcdf72 (diff)
Resource now has a feature slot field
Diffstat (limited to 'pyblackbird_cc/resources/tests')
-rw-r--r--pyblackbird_cc/resources/tests/conftest.py5
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py24
-rw-r--r--pyblackbird_cc/resources/tests/test_views.py2
3 files changed, 25 insertions, 6 deletions
diff --git a/pyblackbird_cc/resources/tests/conftest.py b/pyblackbird_cc/resources/tests/conftest.py
index 9b401ba..0d1ed87 100644
--- a/pyblackbird_cc/resources/tests/conftest.py
+++ b/pyblackbird_cc/resources/tests/conftest.py
@@ -6,8 +6,3 @@ from pyblackbird_cc.resources.factories import ResourceModelFactory
@pytest.fixture()
def resources():
return ResourceModelFactory.create_batch(5)
-
-
-@pytest.fixture()
-def resource():
- return ResourceModelFactory()
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")
diff --git a/pyblackbird_cc/resources/tests/test_views.py b/pyblackbird_cc/resources/tests/test_views.py
index b961d3a..27a6a85 100644
--- a/pyblackbird_cc/resources/tests/test_views.py
+++ b/pyblackbird_cc/resources/tests/test_views.py
@@ -15,7 +15,7 @@ from ..views import create_resource
@pytest.mark.django_db()
-def test_create_featured_resource_view(resource, client):
+def test_create_featured_resource_view(client):
url = reverse("resources:create_featured")
response = client.get(url)
assert response.status_code == 302