aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyblackbird_cc/__init__.py3
-rw-r--r--pyblackbird_cc/resources/factories.py31
-rw-r--r--pyblackbird_cc/resources/models.py20
-rw-r--r--pyblackbird_cc/resources/templatetags/markdown_extras.py1
-rw-r--r--pyblackbird_cc/resources/tests/conftest.py8
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py10
-rw-r--r--pyproject.toml2
7 files changed, 70 insertions, 5 deletions
diff --git a/pyblackbird_cc/__init__.py b/pyblackbird_cc/__init__.py
index 3da9e5f..a368c98 100644
--- a/pyblackbird_cc/__init__.py
+++ b/pyblackbird_cc/__init__.py
@@ -1,5 +1,4 @@
__version__ = "0.1.0"
__version_info__ = tuple(
- int(num) if num.isdigit() else num
- for num in __version__.replace("-", ".", 1).split(".")
+ int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")
)
diff --git a/pyblackbird_cc/resources/factories.py b/pyblackbird_cc/resources/factories.py
new file mode 100644
index 0000000..b78822d
--- /dev/null
+++ b/pyblackbird_cc/resources/factories.py
@@ -0,0 +1,31 @@
+import factory
+
+
+class ResourceTypeModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = "resources.ResourceType"
+ django_get_or_create = ("name",)
+
+ name = factory.Sequence(lambda n: f"Default Resource Type {n}")
+
+
+class ResourceCategoryModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = "resources.ResourceCategory"
+ django_get_or_create = ("name",)
+
+ name = factory.Sequence(lambda n: f"Default Resource Category {n}")
+
+
+class ResourceModelFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = "resources.Resource"
+
+ name = factory.Sequence(lambda n: f"Default Resource {n}")
+ thumbnail_filenames = factory.Sequence(lambda n: [f"thumbnail_{n}.jpg"])
+ resource_type = factory.SubFactory(ResourceTypeModelFactory)
+ main_resource_category = factory.SubFactory(ResourceCategoryModelFactory)
+ additional_resource_category = factory.SubFactory(ResourceCategoryModelFactory)
+ description = factory.Sequence(lambda n: f"Default description {n}")
+ age_range = factory.Iterator(["5-7", "7-10", "10+"])
+ curriculum = factory.Iterator(["English", "Scottish"])
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 5a03454..120ecdf 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -114,6 +114,9 @@ class PDFResource(models.Model):
class Meta:
unique_together = ("resource", "file_name")
+ def __str__(self):
+ return self.resource.name
+
def snapshot_file_names(self):
return [f.file_name for f in self.pdf_page_snapshots.all()]
@@ -127,3 +130,20 @@ class PDFPageSnapshot(models.Model):
null=False,
related_name="pdf_page_snapshots",
)
+
+ def __str__(self):
+ return self.name
+
+
+# class FeatureResource(models.Model):
+# resource = models.ForeignKey(
+# "Resource",
+# on_delete=models.CASCADE,
+# null=False,
+# related_name="feature_resources",
+# )
+# slot = models.IntegerField(null=False, choices=[(1, 1), (2, 2), (3, 3)])
+# description = models.CharField(max_length=255, null=False)
+#
+# def __str__(self):
+# return f"{self.resource.name} as a feature in slot {self.slot}"
diff --git a/pyblackbird_cc/resources/templatetags/markdown_extras.py b/pyblackbird_cc/resources/templatetags/markdown_extras.py
index ce98298..400948a 100644
--- a/pyblackbird_cc/resources/templatetags/markdown_extras.py
+++ b/pyblackbird_cc/resources/templatetags/markdown_extras.py
@@ -4,6 +4,7 @@ from django.template.defaultfilters import stringfilter
register = template.Library()
+
@register.filter(is_safe=True)
@stringfilter
def markdown(value):
diff --git a/pyblackbird_cc/resources/tests/conftest.py b/pyblackbird_cc/resources/tests/conftest.py
new file mode 100644
index 0000000..0d1ed87
--- /dev/null
+++ b/pyblackbird_cc/resources/tests/conftest.py
@@ -0,0 +1,8 @@
+import pytest
+
+from pyblackbird_cc.resources.factories import ResourceModelFactory
+
+
+@pytest.fixture()
+def resources():
+ return ResourceModelFactory.create_batch(5)
diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py
index e1fe290..c54120c 100644
--- a/pyblackbird_cc/resources/tests/test_models.py
+++ b/pyblackbird_cc/resources/tests/test_models.py
@@ -1,6 +1,7 @@
import unittest
from unittest.mock import patch
+import pytest
from django.test import TestCase
from pyblackbird_cc.resources.models import PDFPageSnapshot
@@ -12,10 +13,15 @@ from pyblackbird_cc.resources.views import ResourceInfo
from pyblackbird_cc.resources.views import _extract_metadata_from_resource
+@pytest.mark.django_db
+def test_resource_model(resources):
+ assert Resource.objects.filter(name="Default Resource 1").exists()
+
+
class ResourceModelTest(TestCase):
def test_string_representation(self):
resource = Resource(name="Test Resource")
- assert str(resource) == "Test Resource"
+ assert str(resource) == "Test Resource"
@unittest.skip("Skipping this test for now as it is broken")
@@ -39,7 +45,7 @@ class TestExtractMetadata(TestCase):
result = _extract_metadata_from_resource(mock_resource)
self.assertIsInstance(result, ResourceInfo)
assert result.name == "Test Resource"
- assert result.pdf_filenames == "test.pdf"
+ assert result.pdf_filenames == "test.pdf"
assert result.thumbnail_filenames in ["thumb.jpg", "thumb2.jpg"]
assert result.created == "2022-01-01"
assert result.updated == "2022-01-02"
diff --git a/pyproject.toml b/pyproject.toml
index 55b6a45..fad8512 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,7 @@
# ==== pytest ====
[tool.pytest.ini_options]
minversion = "6.0"
-addopts = "--ds=config.settings.test --reuse-db --import-mode=importlib"
+addopts = "-rP --ds=config.settings.test --reuse-db --import-mode=importlib"
python_files = [
"tests.py",
"test_*.py",