diff options
Diffstat (limited to 'pyblackbird_cc/resources/tests/test_models.py')
-rw-r--r-- | pyblackbird_cc/resources/tests/test_models.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py new file mode 100644 index 0000000..c7ed4d2 --- /dev/null +++ b/pyblackbird_cc/resources/tests/test_models.py @@ -0,0 +1,75 @@ +import unittest +from unittest.mock import patch + +from django.test import TestCase + +from ..models import PDFPageSnapshot +from ..models import PDFResource +from ..models import Resource +from ..models import ResourceCategory +from ..models import ResourceType +from ..views import ResourceInfo +from ..views import _extract_metadata_from_resource + + +class ResourceModelTest(TestCase): + def test_string_representation(self): + resource = Resource(name="Test Resource") + self.assertEqual(str(resource), "Test Resource") + + +@unittest.skip("Skipping this test for now as it is broken") +class TestExtractMetadata(TestCase): + @patch("resources.views.get_presigned_obj_url") + def test_extract_metadata_from_resource(self, mock_get_url): + # Create mock instances of ResourceType and ResourceCategory + mock_resource_type = ResourceType.objects.create(name="Test Type") + mock_main_category = ResourceCategory.objects.create(name="Test Main Category") + + mock_resource = Resource( + name="Test Resource", + thumbnail_filenames=["thumb.jpg", "thumb2.jpg"], + created_at="2022-01-01", + updated_at="2022-01-02", + resource_type=mock_resource_type, + main_resource_category=mock_main_category, + age_range="5-7", + ) + mock_get_url.return_value = "https://example.com/url" + result = _extract_metadata_from_resource(mock_resource) + self.assertIsInstance(result, ResourceInfo) + self.assertEqual(result.name, "Test Resource") + self.assertEqual(result.pdf_filenames, "test.pdf") + self.assertEqual(result.thumbnail_filenames, ["thumb.jpg", "thumb2.jpg"]) + self.assertEqual(result.created, "2022-01-01") + self.assertEqual(result.updated, "2022-01-02") + + +@unittest.skip("These tests will not run because they rely upon the view to get file size, etc.") +class TestPDFResourceModel(TestCase): + def setUp(self): + self.resource_type = ResourceType.objects.create(name="Test Resource Type") + self.resource_category = ResourceCategory.objects.create(name="Test Resource Category") + self.resource = Resource.objects.create( + name="Test Resource", + resource_type=self.resource_type, + main_resource_category=self.resource_category, + age_range="5-7", + curriculum="English", + description="Test Description", + ) + self.pdf_resource = PDFResource.objects.create( + resource=self.resource, + file_name="resources/tests/testdata/test_small_file.pdf", + ) + self.pdf_page_snapshot = PDFPageSnapshot.objects.create( + name="Test Thumbnail Image", + file_name="test_resource_1.jpg", + pdf_file=self.pdf_resource, + ) + + def test_pdf_resource_string_representation(self): + self.assertEqual(str(self.resource), "Test Resource") + + def test_get_pdf_snapshot_filenames(self): + self.assertEqual(self.pdf_resource.snapshot_file_names(), ["test_resource_1.jpg"]) |