-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecea225
commit d0f1f17
Showing
11 changed files
with
271 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Module for tests of the models in the at a distance application.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from tests.BaseTestWithDB import BaseTestWithDB | ||
from tests.at_a_distance.AtADistanceTestDataGenerator import AtADistanceTestDataGenerator | ||
|
||
|
||
class AtADistanceLessonModelTest(BaseTestWithDB): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.test_data = AtADistanceTestDataGenerator() | ||
|
||
def test_at_a_distance_lesson_model_get_absolute_url(self): | ||
lesson = self.test_data.create_lesson(1) | ||
self.assertEqual( | ||
lesson.get_absolute_url(), | ||
"/en/at-a-distance/lesson-1/" | ||
) | ||
|
||
def test_at_a_distance_lesson_model_get_slides_path(self): | ||
lesson = self.test_data.create_lesson(1) | ||
self.assertEqual( | ||
lesson.get_slides_path(), | ||
"at_a_distance/lesson-slides/lesson-1.html" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Module for tests of the views in the at a distance application.""" |
3 changes: 3 additions & 0 deletions
3
...gged/tests/at_a_distance/views/assets/templates/at_a_distance/lesson-slides/lesson-1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<section> | ||
<h1>Slide</h1> | ||
</section> |
9 changes: 9 additions & 0 deletions
9
...gged/tests/at_a_distance/views/assets/templates/at_a_distance/lesson-slides/lesson-2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> |
18 changes: 18 additions & 0 deletions
18
...gged/tests/at_a_distance/views/assets/templates/at_a_distance/lesson-slides/lesson-3.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> | ||
<section> | ||
<h1>Slide</h1> | ||
</section> |
31 changes: 31 additions & 0 deletions
31
csunplugged/tests/at_a_distance/views/test_lesson_file_generation_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.conf import settings | ||
from django.test import override_settings | ||
from django.urls import reverse | ||
from tests.BaseTestWithDB import BaseTestWithDB | ||
from tests.at_a_distance.AtADistanceTestDataGenerator import AtADistanceTestDataGenerator | ||
|
||
TEST_TEMPLATES = settings.TEMPLATES | ||
TEST_TEMPLATES[0]["DIRS"].append("tests/at_a_distance/views/assets/templates") | ||
|
||
|
||
@override_settings(TEMPLATES=TEST_TEMPLATES) | ||
class LessonFileGenerationViewTest(BaseTestWithDB): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.test_data = AtADistanceTestDataGenerator() | ||
self.language = "en" | ||
|
||
def test_lesson_file_generation_view_context(self): | ||
lesson = self.test_data.create_lesson(1) | ||
kwargs = { | ||
"lesson_slug": lesson.slug, | ||
} | ||
url = reverse("at_a_distance:lesson_file_generation", kwargs=kwargs) | ||
response = self.client.get(url) | ||
self.assertEqual( | ||
response.context["lesson"], | ||
lesson | ||
) | ||
self.assertEqual(response.context["fragments"], "false") | ||
self.assertEqual(response.context["slide_number"], "false") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from http import HTTPStatus | ||
from django.conf import settings | ||
from django.test import override_settings | ||
from django.urls import reverse | ||
from tests.BaseTestWithDB import BaseTestWithDB | ||
from tests.at_a_distance.AtADistanceTestDataGenerator import AtADistanceTestDataGenerator | ||
|
||
TEST_TEMPLATES = settings.TEMPLATES | ||
TEST_TEMPLATES[0]["DIRS"].append("tests/at_a_distance/views/assets/templates") | ||
|
||
|
||
@override_settings(TEMPLATES=TEST_TEMPLATES) | ||
class LessonViewTest(BaseTestWithDB): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.test_data = AtADistanceTestDataGenerator() | ||
self.language = "en" | ||
|
||
def test_lesson_view_with_valid_slug(self): | ||
lesson = self.test_data.create_lesson(1) | ||
kwargs = { | ||
"lesson_slug": lesson.slug | ||
} | ||
url = reverse("at_a_distance:lesson", kwargs=kwargs) | ||
response = self.client.get(url) | ||
self.assertEqual(HTTPStatus.OK, response.status_code) | ||
|
||
def test_lesson_view_with_invalid_slug(self): | ||
self.test_data.create_lesson(1) | ||
kwargs = { | ||
"lesson_slug": "wrong_slug", | ||
} | ||
url = reverse("at_a_distance:lesson", kwargs=kwargs) | ||
response = self.client.get(url) | ||
self.assertEqual(404, response.status_code) | ||
|
||
def test_lesson_view_context(self): | ||
lesson = self.test_data.create_lesson(1) | ||
kwargs = { | ||
"lesson_slug": lesson.slug, | ||
} | ||
url = reverse("at_a_distance:lesson", kwargs=kwargs) | ||
response = self.client.get(url) | ||
self.assertEqual( | ||
response.context["lesson"], | ||
lesson | ||
) | ||
self.assertEqual( | ||
response.context["slides_pdf"], | ||
"slides/en/lesson-1/lesson-1-slides.pdf" | ||
) | ||
self.assertEqual( | ||
response.context["notes_pdf"], | ||
"slides/en/lesson-1/lesson-1-speaker-notes.pdf" | ||
) |
124 changes: 124 additions & 0 deletions
124
csunplugged/tests/at_a_distance/views/test_slides_file_generation_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from django.conf import settings | ||
from django.test import override_settings | ||
from django.urls import reverse | ||
from tests.BaseTestWithDB import BaseTestWithDB | ||
from tests.at_a_distance.AtADistanceTestDataGenerator import AtADistanceTestDataGenerator | ||
|
||
TEST_TEMPLATES = settings.TEMPLATES | ||
TEST_TEMPLATES[0]["DIRS"].append("tests/at_a_distance/views/assets/templates") | ||
LANGUAGE1 = "lang1" | ||
LANGUAGE2 = "lang2" | ||
MULTIPLE_LANGUAGES = ((LANGUAGE1, LANGUAGE1), (LANGUAGE2, LANGUAGE2)) | ||
|
||
|
||
@override_settings(TEMPLATES=TEST_TEMPLATES) | ||
class LessonFileGenerationViewTest(BaseTestWithDB): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.test_data = AtADistanceTestDataGenerator() | ||
self.language = "en" | ||
|
||
def test_slides_file_generation_view_single_lesson(self): | ||
self.test_data.create_lesson(1) | ||
url = reverse("at_a_distance:slides_file_generation_json") | ||
response = self.client.get(url) | ||
self.assertJSONEqual( | ||
response.content.decode(), | ||
{ | ||
"resolution": "1920x1080", | ||
"slide_counts": { | ||
"lesson-1": 2, | ||
}, | ||
"languages": { | ||
"en": [ | ||
"lesson-1", | ||
] | ||
}, | ||
} | ||
) | ||
|
||
def test_slides_file_generation_view_multiple_lessons(self): | ||
self.test_data.create_lesson(1) | ||
self.test_data.create_lesson(2) | ||
self.test_data.create_lesson(3) | ||
url = reverse("at_a_distance:slides_file_generation_json") | ||
response = self.client.get(url) | ||
self.assertJSONEqual( | ||
response.content.decode(), | ||
{ | ||
"resolution": "1920x1080", | ||
"slide_counts": { | ||
"lesson-1": 2, | ||
"lesson-2": 4, | ||
"lesson-3": 7, | ||
}, | ||
"languages": { | ||
"en": [ | ||
"lesson-1", | ||
"lesson-2", | ||
"lesson-3", | ||
] | ||
}, | ||
} | ||
) | ||
|
||
@override_settings(DEFAULT_LANGUAGES=MULTIPLE_LANGUAGES) | ||
def test_slides_file_generation_view_single_lesson_multiple_languages(self): | ||
lesson = self.test_data.create_lesson(1) | ||
lesson.languages = [LANGUAGE1, LANGUAGE2] | ||
lesson.save() | ||
url = reverse("at_a_distance:slides_file_generation_json") + "?language=all" | ||
response = self.client.get(url) | ||
self.assertJSONEqual( | ||
response.content.decode(), | ||
{ | ||
"resolution": "1920x1080", | ||
"slide_counts": { | ||
"lesson-1": 2, | ||
}, | ||
"languages": { | ||
LANGUAGE1: [ | ||
"lesson-1", | ||
], | ||
LANGUAGE2: [ | ||
"lesson-1", | ||
] | ||
}, | ||
} | ||
) | ||
|
||
@override_settings(DEFAULT_LANGUAGES=MULTIPLE_LANGUAGES) | ||
def test_slides_file_generation_view_multiple_lessons_multiple_languages(self): | ||
lesson1 = self.test_data.create_lesson(1) | ||
lesson1.languages = [LANGUAGE1, LANGUAGE2] | ||
lesson1.save() | ||
lesson2 = self.test_data.create_lesson(2) | ||
lesson2.languages = [LANGUAGE1] | ||
lesson2.save() | ||
lesson3 = self.test_data.create_lesson(3) | ||
lesson3.languages = [LANGUAGE2] | ||
lesson3.save() | ||
url = reverse("at_a_distance:slides_file_generation_json") + "?language=all" | ||
response = self.client.get(url) | ||
self.assertJSONEqual( | ||
response.content.decode(), | ||
{ | ||
"resolution": "1920x1080", | ||
"slide_counts": { | ||
"lesson-1": 2, | ||
"lesson-2": 4, | ||
"lesson-3": 7, | ||
}, | ||
"languages": { | ||
LANGUAGE1: [ | ||
"lesson-1", | ||
"lesson-2", | ||
], | ||
LANGUAGE2: [ | ||
"lesson-1", | ||
"lesson-3", | ||
] | ||
}, | ||
} | ||
) |