aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--pyproject.toml2
4 files changed, 27 insertions, 3 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):
diff --git a/pyproject.toml b/pyproject.toml
index fad8512..a633c49 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,7 @@
# ==== pytest ====
[tool.pytest.ini_options]
minversion = "6.0"
-addopts = "-rP --ds=config.settings.test --reuse-db --import-mode=importlib"
+addopts = "--disable-pytest-warnings -q -rP --ds=config.settings.test --reuse-db --import-mode=importlib"
python_files = [
"tests.py",
"test_*.py",