Skip to content

Commit

Permalink
Merge pull request #38 from ssciolla/issue-37-use-utf8mb4
Browse files Browse the repository at this point in the history
Modify database, settings.py to use utf8mb4 (#37)
  • Loading branch information
ssciolla authored Aug 10, 2020
2 parents 9411f27 + 0d0999d commit 575f87b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
mysql:
image: mysql:5.7
restart: on-failure
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
environment:
- MYSQL_ROOT_PASSWORD=pe_root_pw
- MYSQL_HOST=placement_exams_mysql
Expand Down
9 changes: 7 additions & 2 deletions pe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@

CONFIG_DIR: str = os.path.join(BASE_DIR, os.getenv('ENV_DIR', os.path.join('config', 'secrets')))

DATABASES: Dict[str, Dict[str, str]] = {
DATABASES: Dict[str, Dict[str, Any]] = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('DB_NAME', 'placement_exams_local'),
'USER': os.getenv('DB_USER', 'pe_user'),
'PASSWORD': os.getenv('DB_PASSWORD', 'pe_pw'),
'HOST': os.getenv('DB_HOST', 'placement_exams_mysql'),
'PORT': os.getenv('DB_PORT', '3306')
'PORT': os.getenv('DB_PORT', '3306'),
'OPTIONS': {'charset': 'utf8mb4'},
'TEST': {
'CHARSET': 'utf8mb4',
'COLLATION': 'utf8mb4_unicode_ci'
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/test_05.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"model": "pe.report",
"pk": 4,
"fields": {
"name": "Divination 🔮",
"contact": "[email protected]"
}
},
{
"model": "pe.exam",
"pk": 4,
"fields": {
"sa_code": "Δ",
"name": "Δ𓀤𝌕👁",
"report_id": 4,
"course_id": 1111111,
"assignment_id": 777777,
"default_time_filter": "2020-08-01T00:00:00Z"
}
}
]
9 changes: 9 additions & 0 deletions test/test_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ def test_fixtures_load_maintains_submission_link(self):
self.assertEqual(submission.exam.sa_code, 'PP')
self.assertEqual(submission.exam.name, 'Potions Placement Advanced')

def test_load_fixtures_with_supplementary_characters(self):
"""Loading exam and report fixtures with characters that need utf8mb4 encoding succeeds."""
call_command('loaddata', 'test_05.json')
div_report: Report = Report.objects.get(id=4)
self.assertEqual(div_report.name, 'Divination 🔮')
div_exam: Exam = div_report.exams.first()
self.assertEqual(div_exam.sa_code, 'Δ')
self.assertEqual(div_exam.name, 'Δ𓀤𝌕👁')


class StringMethodsTestCase(TestCase):
fixtures: List[str] = ['test_01.json', 'test_04.json']
Expand Down

0 comments on commit 575f87b

Please sign in to comment.