Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BareResourceGenerator in test suite. #1423

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csunplugged/resources/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Disable unused import warnings for this file
# flake8: noqa: F401

from tests.resources.BareResourceGenerator import BareResourceGenerator
from .ArrowsResourceGenerator import ArrowsResourceGenerator
from .BarcodeChecksumPosterResourceGenerator import BarcodeChecksumPosterResourceGenerator
from .BinaryCardsResourceGenerator import BinaryCardsResourceGenerator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource-untranslated:
generator-module: GridResourceGenerator
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator
thumbnail-static-path: img/resources/bare/thumbnail.png
copies: false
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource-untranslated:
generator-module: GridResourceGenerator
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator
thumbnail-static-path: img/resources/bare/thumbnail.png
copies: Maybe
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource-untranslated:
generator-module: GridResourceGenerator
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator
thumbnail-static-path: img/resources/bare/thumbnail.png
copies: false
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource-untranslated:
generator-module: GridResourceGenerator
generator-module: BareResourceGenerator
thumbnail-static-path: missing-image.png
copies: false
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resource-untranslated:
generator-module: GridResourceGenerator
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator
thumbnail-static-path: img/resources/bare/thumbnail.png
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resource-untranslated:
generator-module: GridResourceGenerator
generator-module: BaseResourceGenerator
copies: false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource-untranslated:
generator-module: GridResourceGenerator
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator
thumbnail-static-path: img/resources/bare/thumbnail.png
copies: false
resource2-untranslated:
generator-module: JobBadgesResourceGenerator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource-translated:
generator-module: GridResourceGenerator
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator
thumbnail-static-path: img/resources/bare/thumbnail.png
copies: false
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource-untranslated:
generator-module: GridResourceGenerator.py
thumbnail-static-path: img/resources/grid/thumbnail.png
generator-module: BareResourceGenerator.py
thumbnail-static-path: img/resources/bare/thumbnail.png
copies: false
4 changes: 2 additions & 2 deletions csunplugged/tests/resources/loaders/test_resource_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_basic_resource_loader_config(self):
self.assertEqual("Resource 1", resource.name)
self.assertIn("Description of resource 1", resource.content)
self.assertEqual("resource-untranslated", resource.slug)
self.assertEqual("GridResourceGenerator", resource.generator_module)
self.assertEqual("BareResourceGenerator", resource.generator_module)
self.assertEqual(False, resource.copies)

def test_resource_loader_config_missing_translation_fallback(self):
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_resource_loader_trimmed_module_value(self):
resource_loader.load()
self.assertEquals(
Resource.objects.get(slug="resource-untranslated").generator_module,
"GridResourceGenerator",
"BareResourceGenerator",
)

def test_resource_loader_missing_copies_value(self):
Expand Down
28 changes: 14 additions & 14 deletions csunplugged/tests/resources/models/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ def __init__(self, *args, **kwargs):

def test_resource_str(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
self.assertEqual(resource.__str__(), "Grid")
self.assertEqual(resource.__str__(), "Bare")

def test_resource_model_name(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
self.assertEqual(resource.MODEL_NAME, "Printable")

def test_resource_model_get_absolute_url(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
self.assertEqual(
resource.get_absolute_url(),
"/en/resources/grid/"
"/en/resources/bare/"
)
8 changes: 4 additions & 4 deletions csunplugged/tests/resources/utils/test_get_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_get_thumbnail_static_path_for_resource_local_development(self):
"resource",
"Resource",
"Description of resource",
"GridResourceGenerator",
"BareResourceGenerator",
)
self.assertEqual(
get_thumbnail_static_path_for_resource(resource),
Expand All @@ -117,7 +117,7 @@ def test_get_thumbnail_static_path_for_resource_production_en(self):
"resource",
"Resource",
"Description of resource",
"GridResourceGenerator",
"BareResourceGenerator",
)
self.assertEqual(
get_thumbnail_static_path_for_resource(resource),
Expand All @@ -132,7 +132,7 @@ def test_get_thumbnail_static_path_for_resource_production_de(self):
"resource",
"Resource",
"Description of resource",
"GridResourceGenerator",
"BareResourceGenerator",
)
self.assertEqual(
get_thumbnail_static_path_for_resource(resource),
Expand All @@ -148,7 +148,7 @@ def test_get_thumbnail_static_path_for_resource_production_in_context(self):
"resource",
"Resource",
"Description of resource",
"GridResourceGenerator",
"BareResourceGenerator",
)
self.assertEqual(
get_thumbnail_static_path_for_resource(resource),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def __init__(self, *args, **kwargs):

def test_resources_cache_valid_resource(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
query = QueryDict("paper_size=a4")
generator = get_resource_generator(resource.generator_module, query)
response = resource_pdf_cache(resource, generator)
self.assertEqual(response.status_code, HTTPStatus.FOUND)
self.assertEqual(
response.url,
"/static/resources/en/grid/Grid%20(a4).pdf"
"/staticfiles/resources/bare/en/Bare%20(a4).pdf"
)
44 changes: 22 additions & 22 deletions csunplugged/tests/resources/views/test_generate_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def __init__(self, *args, **kwargs):

def test_generate_view_valid_slug(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
kwargs = {
"resource_slug": resource.slug,
Expand All @@ -31,16 +31,16 @@ def test_generate_view_valid_slug(self):
self.assertEqual(HTTPStatus.OK, response.status_code)
self.assertEqual(
response.get("Content-Disposition"),
'attachment; filename*=UTF-8\'\'Grid%20%28a4%29.pdf; filename="Grid%20%28a4%29.pdf"'
'attachment; filename*=UTF-8\'\'Bare%20%28a4%29.pdf; filename="Bare%20%28a4%29.pdf"'
)

@override_settings(DEPLOYED=True)
def test_generate_view_valid_slug_production_cache(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
kwargs = {
"resource_slug": resource.slug,
Expand All @@ -52,15 +52,15 @@ def test_generate_view_valid_slug_production_cache(self):
self.assertEqual(HTTPStatus.FOUND, response.status_code)
self.assertEqual(
response.url,
"/static/resources/en/grid/Grid%20(a4).pdf"
"/staticfiles/resources/bare/en/Bare%20(a4).pdf"
)

def test_generate_view_valid_slug_missing_parameter(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
kwargs = {
"resource_slug": resource.slug,
Expand All @@ -71,10 +71,10 @@ def test_generate_view_valid_slug_missing_parameter(self):

def test_generate_view_valid_slug_invalid_parameter(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
kwargs = {
"resource_slug": resource.slug,
Expand All @@ -87,10 +87,10 @@ def test_generate_view_valid_slug_invalid_parameter(self):

def test_generate_view_valid_slug_multiple_parameter(self):
resource = self.test_data.create_resource(
"grid",
"Grid",
"resources/grid.html",
"GridResourceGenerator",
"bare",
"Bare",
"resources/bare.html",
"BareResourceGenerator",
)
kwargs = {
"resource_slug": resource.slug,
Expand Down
2 changes: 1 addition & 1 deletion csunplugged/tests/resources/views/test_index_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_resources_index_with_one_resource(self):
"resource",
"Resource",
"Description",
"GridResourceGenerator",
"BareResourceGenerator",
)
url = reverse("resources:index")
response = self.client.get(url)
Expand Down
Loading