-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_quizz.py
56 lines (45 loc) · 1.79 KB
/
test_quizz.py
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
# -*- coding: utf-8 -*-
import unittest
import glob
import json
class TestQuizz(unittest.TestCase):
MAX_QUESTIONS_QUIZZ = 15
def __init__(self, *args, **kwargs):
super(TestQuizz, self).__init__(*args, **kwargs)
self.slugs = []
def test_for_each_quizz(self):
files = glob.glob("static/*.json")
files = [f for f in files if 'liste-quizz' not in f]
for file in files:
content = json.load(open(file))
self.general_structure(content)
self.check_questions(content['questions'])
def general_structure(self, content):
self.assertEquals(
set(content.keys()),
set(['title', 'slug', 'questions'])
)
# Slug is unique accross quizzes
self.assertNotIn(content['slug'], self.slugs)
self.slugs.append(content['slug'])
def check_questions(self, questions):
self.assertLessEqual(len(questions), self.MAX_QUESTIONS_QUIZZ)
for question in questions:
self.assertIn(question['type'], ['mc', 'tf'])
# Image is not required for now
question.pop('image', None)
if question['type'] == 'tf':
self.assertEquals(
set(question.keys()),
set(['text', 'type', 'answer', 'explanations'])
)
self.assertIn(question['answer'], ['t', 'f'])
elif question['type'] == 'mc':
self.assertEquals(
set(question.keys()),
set(['text', 'type', 'answer', 'explanations', 'answers'])
)
self.assertIn(question['answer'], question['answers'])
self.assertEquals(type(question['answer']), str)
else:
raise NotImplementedError