-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
3 changed files
with
113 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.contrib.auth.models import Group | ||
from django.db.migrations.executor import MigrationExecutor | ||
from django.db import connection | ||
from django.test import TransactionTestCase | ||
|
||
from dips.models import StaticContent | ||
|
||
|
||
class TestMigrations(TransactionTestCase): | ||
"""Uses TransactionTestCase to perform rollbacks.""" | ||
|
||
def setUp(self): | ||
self.executor = MigrationExecutor(connection) | ||
|
||
def test_rollbacks(self): | ||
"""Checks that migration rollbacks run correctly. | ||
Perform all rollbacks in order in the same test to maintain DB status. | ||
""" | ||
# Initial counts | ||
self.assertEqual(Group.objects.count(), 3) | ||
self.assertEqual(StaticContent.objects.count(), 3) | ||
|
||
# StaticContent removal | ||
self.executor.migrate([("dips", "0009_staticcontent")]) | ||
self.assertEqual(StaticContent.objects.count(), 0) | ||
|
||
# Groups removal | ||
self.executor.migrate([("dips", "0001_initial")]) | ||
self.assertEqual(Group.objects.count(), 0) |
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
from django.test import TestCase | ||
from unittest.mock import patch | ||
|
||
from dips.models import User | ||
from dips.models import StaticContent, User | ||
|
||
|
||
class ViewsTests(TestCase): | ||
def setUp(self): | ||
self.user = User.objects.create_superuser("admin", "[email protected]", "admin") | ||
self.client.login(username="admin", password="admin") | ||
self.faq = StaticContent.objects.get(key="03_faq") | ||
|
||
@patch("elasticsearch_dsl.Search.execute") | ||
@patch("elasticsearch_dsl.Search.count", return_value=0) | ||
|
@@ -26,3 +27,76 @@ def test_search_wrong_dates(self, mock_msg_error, mock_es_count, mock_es_exec): | |
self.assertEqual(response.context["filters"], expected_filters) | ||
# But the errors should be added to the messages | ||
self.assertEqual(mock_msg_error.call_count, 2) | ||
|
||
def test_static_content_get_en(self): | ||
response = self.client.get("/static_content/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertEqual(len(response.context["formset"]), 3) | ||
self.assertContains(response, "## Digital Archives Access Interface") | ||
|
||
def test_static_content_get_fr(self): | ||
response = self.client.get("/static_content/", HTTP_ACCEPT_LANGUAGE="fr") | ||
self.assertEqual(len(response.context["formset"]), 3) | ||
self.assertContains( | ||
response, "## Interface d'accès aux archives numériques" | ||
) | ||
|
||
def test_static_content_post_en(self): | ||
data = { | ||
"form-TOTAL_FORMS": ["3"], | ||
"form-INITIAL_FORMS": ["3"], | ||
"form-MIN_NUM_FORMS": ["0"], | ||
"form-MAX_NUM_FORMS": ["1000"], | ||
"form-0-content": ["New English content"], | ||
"form-0-key": ["01_home"], | ||
"form-1-content": [""], | ||
"form-1-key": ["02_login"], | ||
"form-2-content": [""], | ||
"form-2-key": ["03_faq"], | ||
} | ||
self.client.post("/static_content/", data, HTTP_ACCEPT_LANGUAGE="en") | ||
static_content = StaticContent.objects.get(key="01_home") | ||
self.assertEqual(static_content.content_en, "New English content") | ||
|
||
def test_static_content_post_fr(self): | ||
data = { | ||
"form-TOTAL_FORMS": ["3"], | ||
"form-INITIAL_FORMS": ["3"], | ||
"form-MIN_NUM_FORMS": ["0"], | ||
"form-MAX_NUM_FORMS": ["1000"], | ||
"form-0-content": ["New French content"], | ||
"form-0-key": ["01_home"], | ||
"form-1-content": [""], | ||
"form-1-key": ["02_login"], | ||
"form-2-content": [""], | ||
"form-2-key": ["03_faq"], | ||
} | ||
self.client.post("/static_content/", data, HTTP_ACCEPT_LANGUAGE="fr") | ||
static_content = StaticContent.objects.get(key="01_home") | ||
self.assertEqual(static_content.content_fr, "New French content") | ||
|
||
def test_faq_markdown(self): | ||
self.faq.content_en = "## Header" | ||
self.faq.save() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertContains(response, "<h2>Header</h2>") | ||
|
||
def test_faq_html(self): | ||
self.faq.content_en = "<h2>Header</h2>" | ||
self.faq.save() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertContains(response, "<h2>Header</h2>") | ||
|
||
def test_faq_langs(self): | ||
self.faq.content_en = "English content" | ||
self.faq.save() | ||
# English | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertContains(response, "English content") | ||
# Fallback | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="fr") | ||
self.assertContains(response, "English content") | ||
# French | ||
self.faq.content_fr = "French content" | ||
self.faq.save() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="fr") | ||
self.assertContains(response, "French content") |