aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources
diff options
context:
space:
mode:
Diffstat (limited to 'pyblackbird_cc/resources')
-rw-r--r--pyblackbird_cc/resources/migrations/0004_resource_feature_slot_1_resource_feature_slot_2_and_more.py28
-rw-r--r--pyblackbird_cc/resources/migrations/0005_rename_feature_slot_1_resource_feature_slot_and_more.py26
-rw-r--r--pyblackbird_cc/resources/models.py1
-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
6 files changed, 80 insertions, 6 deletions
diff --git a/pyblackbird_cc/resources/migrations/0004_resource_feature_slot_1_resource_feature_slot_2_and_more.py b/pyblackbird_cc/resources/migrations/0004_resource_feature_slot_1_resource_feature_slot_2_and_more.py
new file mode 100644
index 0000000..d595b62
--- /dev/null
+++ b/pyblackbird_cc/resources/migrations/0004_resource_feature_slot_1_resource_feature_slot_2_and_more.py
@@ -0,0 +1,28 @@
+# Generated by Django 5.0.4 on 2024-05-22 19:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('resources', '0003_alter_resource_description'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='resource',
+ name='feature_slot_1',
+ field=models.IntegerField(choices=[(1, 1), (2, 2), (3, 3)], null=True, unique=True),
+ ),
+ migrations.AddField(
+ model_name='resource',
+ name='feature_slot_2',
+ field=models.IntegerField(choices=[(1, 1), (2, 2), (3, 3)], null=True, unique=True),
+ ),
+ migrations.AddField(
+ model_name='resource',
+ name='feature_slot_3',
+ field=models.IntegerField(choices=[(1, 1), (2, 2), (3, 3)], null=True, unique=True),
+ ),
+ ]
diff --git a/pyblackbird_cc/resources/migrations/0005_rename_feature_slot_1_resource_feature_slot_and_more.py b/pyblackbird_cc/resources/migrations/0005_rename_feature_slot_1_resource_feature_slot_and_more.py
new file mode 100644
index 0000000..2937c50
--- /dev/null
+++ b/pyblackbird_cc/resources/migrations/0005_rename_feature_slot_1_resource_feature_slot_and_more.py
@@ -0,0 +1,26 @@
+# Generated by Django 5.0.4 on 2024-05-22 19:26
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('resources', '0004_resource_feature_slot_1_resource_feature_slot_2_and_more'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='resource',
+ old_name='feature_slot_1',
+ new_name='feature_slot',
+ ),
+ migrations.RemoveField(
+ model_name='resource',
+ name='feature_slot_2',
+ ),
+ migrations.RemoveField(
+ model_name='resource',
+ name='feature_slot_3',
+ ),
+ ]
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 2b73c89..27d74e7 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -73,6 +73,7 @@ class Resource(models.Model):
("Scottish", "Scottish"),
],
)
+ feature_slot = models.IntegerField(choices=((1, 1), (2, 2), (3, 3)), unique=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
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