This repository was archived by the owner on Mar 25, 2025. It is now read-only.
forked from openedx/openedx-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
54 lines (38 loc) · 1.66 KB
/
tests.py
File metadata and controls
54 lines (38 loc) · 1.66 KB
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
"""
This module contains the test cases for caliper_tracking application
"""
import json
import os
from datetime import datetime
from django.test import TestCase
import logging
from openedx.features.caliper_tracking.base_transformer import CaliperBaseTransformer
from openedx.features.caliper_tracking.caliper_config import EVENT_MAPPING
TEST_DIR_PATH = 'openedx/features/caliper_tracking/tests/'
class CaliperTransformationTestCase(TestCase):
"""Data driven test case that tests all transformers for expected output
The test case compares the files in the current/ directory
and compares them with their corresponding files in the expected/ directory
"""
maxDiff = None
def test_caliper_transformers(self):
test_files = [file for file in os.listdir(
'{}current/'.format(TEST_DIR_PATH)) if file.endswith(".json")]
for file in test_files:
input_file = '{}current/{}'.format(
TEST_DIR_PATH,
file
)
output_file = '{}expected/{}'.format(
TEST_DIR_PATH,
file
)
with open(input_file) as current, open(output_file) as expected:
event = json.loads(current.read())
expected_event = json.loads(expected.read())
expected_event.pop('id')
caliper_event = CaliperBaseTransformer(event).transform_event()
related_function = EVENT_MAPPING[event.get('event_type')]
caliper_event = related_function(event, caliper_event)
caliper_event.pop('id')
self.assertDictEqual(caliper_event, expected_event)