aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-05-20 20:17:25 +0100
committerMatthew Lemon <y@yulqen.org>2024-05-20 20:17:25 +0100
commitff1aa3aa113e507f870eba4c96099946f154fb22 (patch)
treedb14562172d6936bdcc993b6af45ccbd2f2d8d89 /pyblackbird_cc
parentd048429fefaa92c7600b46fec9d38e1e9e862457 (diff)
wip:
- Passing test for raw ORM handling to find snapshot files from an object - Quietens down pytest output
Diffstat (limited to 'pyblackbird_cc')
-rw-r--r--pyblackbird_cc/resources/models.py9
-rw-r--r--pyblackbird_cc/resources/tests/conftest.py3
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py16
3 files changed, 26 insertions, 2 deletions
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 120ecdf..2b73c89 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -79,6 +79,15 @@ class Resource(models.Model):
def __str__(self):
return self.name
+ def get_pdf_file_names(self):
+ return [p.file_name for p in self.pdf_resources.all()]
+
+ def get_pdf_snapshot_file_names(self):
+ rs = self.pdf_resources.all()
+ sh = [sh for sh in rs.values_list("pdf_page_snapshots__file_name", flat=True)]
+ out = [s for s in sh if s]
+ return out
+
class ResourceType(models.Model):
name = models.CharField(max_length=255, null=False)
diff --git a/pyblackbird_cc/resources/tests/conftest.py b/pyblackbird_cc/resources/tests/conftest.py
index a5c1e41..0d1ed87 100644
--- a/pyblackbird_cc/resources/tests/conftest.py
+++ b/pyblackbird_cc/resources/tests/conftest.py
@@ -1,9 +1,8 @@
import pytest
-from pyblackbird_cc.resources.factories import ResourceModelFactory, PDFPageSnapshotModelFactory
+from pyblackbird_cc.resources.factories import ResourceModelFactory
@pytest.fixture()
def resources():
- snapshots = PDFPageSnapshotModelFactory.create_batch(3)
return ResourceModelFactory.create_batch(5)
diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py
index 5adcd14..56416f4 100644
--- a/pyblackbird_cc/resources/tests/test_models.py
+++ b/pyblackbird_cc/resources/tests/test_models.py
@@ -4,6 +4,7 @@ from unittest.mock import patch
import pytest
from django.test import TestCase
+from pyblackbird_cc.resources.factories import PDFPageSnapshotModelFactory
from pyblackbird_cc.resources.models import PDFPageSnapshot
from pyblackbird_cc.resources.models import PDFResource
from pyblackbird_cc.resources.models import Resource
@@ -12,10 +13,25 @@ from pyblackbird_cc.resources.models import ResourceType
from pyblackbird_cc.resources.views import ResourceInfo
from pyblackbird_cc.resources.views import _extract_metadata_from_resource
+# TODO - convert this test into the test of a function
+# that takes a Resource object and returns all the PDF snapshots
+# file names
+
@pytest.mark.django_db()
def test_resource_model(resources):
+ # Create a resource
+ r1 = resources[0]
+ # Get the first pdf resource on the resource
+ pdf_on_rw = r1.pdf_resources.first()
+ # Create a single pdf_page_shapshot and associate it with the pdf resource on the resource
+ pdf_page_snapshot = PDFPageSnapshotModelFactory(pdf_file=pdf_on_rw)
assert Resource.objects.filter(name="Default Resource 1").exists()
+ assert "test_0.pdf" in r1.get_pdf_file_names()
+ assert "test_1.pdf" in r1.get_pdf_file_names()
+ assert "test_2.pdf" in r1.get_pdf_file_names()
+ assert "test_3.pdf" not in r1.get_pdf_file_names()
+ assert "pdf_page_snapshot_0.jpg" in r1.get_pdf_snapshot_file_names()
class ResourceModelTest(TestCase):