1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import unittest
from unittest.mock import patch
from django.test import TestCase
from pyblackbird_cc.resources.models import PDFPageSnapshot
from pyblackbird_cc.resources.models import PDFResource
from pyblackbird_cc.resources.models import Resource
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
class ResourceModelTest(TestCase):
def test_string_representation(self):
resource = Resource(name="Test Resource")
assert 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)
assert result.name == "Test Resource"
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"
@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"])
|