Skip to content

Commit 8f6a40b

Browse files
authored
Move JSON importer EXAMPLE_DATA to separate file (#2634)
This file can now be used as an argument to `./manage.py import_cms_data`.
1 parent 18f9d09 commit 8f6a40b

File tree

3 files changed

+167
-84
lines changed

3 files changed

+167
-84
lines changed

evap/cms/fixtures/__init__.py

Whitespace-only changes.
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"students": [
3+
{
4+
"gguid": "0x1",
5+
"email": "1@example.com",
6+
"name": "1",
7+
"christianname": "w_1",
8+
"callingname": "1"
9+
},
10+
{
11+
"gguid": "0x2",
12+
"email": "2@example.com",
13+
"name": "2",
14+
"christianname": "w_2",
15+
"callingname": "2"
16+
}
17+
],
18+
"lecturers": [
19+
{
20+
"gguid": "0x3",
21+
"email": "3@example.com",
22+
"name": "3",
23+
"christianname": "3",
24+
"titlefront": "Prof. Dr."
25+
},
26+
{
27+
"gguid": "0x4",
28+
"email": "4@example.com",
29+
"name": "4",
30+
"christianname": "4",
31+
"titlefront": "Dr."
32+
},
33+
{
34+
"gguid": "0x5",
35+
"email": "5@example.com",
36+
"name": "5",
37+
"christianname": "5",
38+
"titlefront": ""
39+
},
40+
{
41+
"gguid": "0x6",
42+
"email": "6@example.com",
43+
"name": "6",
44+
"christianname": "6",
45+
"titlefront": ""
46+
}
47+
],
48+
"events": [
49+
{
50+
"gguid": "0x5",
51+
"title": "Prozessorientierte Informationssysteme",
52+
"title_en": "Process-oriented information systems",
53+
"type": "Vorlesung",
54+
"isexam": false,
55+
"courses": [],
56+
"appointments": [
57+
{
58+
"begin": "30.04.2024 10:15:00",
59+
"end": "30.04.2024 11:45:00"
60+
},
61+
{
62+
"begin": "15.07.2024 10:15:00",
63+
"end": "15.07.2024 11:45:00"
64+
}
65+
],
66+
"relatedevents": [
67+
{
68+
"gguid": "0x6"
69+
}
70+
],
71+
"lecturers": [
72+
{
73+
"gguid": "0x3"
74+
}
75+
],
76+
"students": [
77+
{
78+
"gguid": "0x1"
79+
},
80+
{
81+
"gguid": "0x2"
82+
}
83+
],
84+
"language": "Deutsch"
85+
},
86+
{
87+
"gguid": "0x6",
88+
"title": "Prozessorientierte Informationssysteme",
89+
"title_en": "Process-oriented information systems",
90+
"type": "Klausur",
91+
"isexam": true,
92+
"courses": [
93+
{
94+
"cprid": "BA-Inf",
95+
"scale": "GRADE_PARTICIPATION"
96+
},
97+
{
98+
"cprid": "MA-Inf",
99+
"scale": "GRADE_PARTICIPATION"
100+
}
101+
],
102+
"appointments": [
103+
{
104+
"begin": "29.07.2024 10:15:00",
105+
"end": "29.07.2024 11:45:00"
106+
}
107+
],
108+
"relatedevents": [
109+
{
110+
"gguid": "0x5"
111+
}
112+
],
113+
"lecturers": [
114+
{
115+
"gguid": "0x3"
116+
},
117+
{
118+
"gguid": "0x4"
119+
},
120+
{
121+
"gguid": "0x5"
122+
}
123+
],
124+
"students": [
125+
{
126+
"gguid": "0x1"
127+
},
128+
{
129+
"gguid": "0x2"
130+
}
131+
],
132+
"language": "Deutsch"
133+
},
134+
{
135+
"gguid": "0x7",
136+
"title": "Bachelorprojekt: Prozessorientierte Informationssysteme",
137+
"title_en": "Bachelor's Project: Process-oriented information systems",
138+
"type": "Bachelorprojekt",
139+
"isexam": true,
140+
"courses": [
141+
{
142+
"cprid": "BA-Inf",
143+
"scale": "GRADE_PARTICIPATION"
144+
}
145+
],
146+
"lecturers": [
147+
{
148+
"gguid": "0x3"
149+
}
150+
],
151+
"students": [
152+
{
153+
"gguid": "0x1"
154+
},
155+
{
156+
"gguid": "0x2"
157+
}
158+
],
159+
"language": "Englisch"
160+
}
161+
]
162+
}

evap/cms/tests/test_json_importer.py

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import json
22
from copy import deepcopy
33
from datetime import date, datetime, timedelta
4+
from pathlib import Path
45

56
from django.conf import settings
67
from django.core import mail
78
from django.test import TestCase, override_settings
89
from model_bakery import baker
910
from pydantic import ValidationError
1011

12+
import evap.cms.fixtures
1113
from evap.cms.json_importer import ImportDict, JSONImporter, NameChange, WarningMessage, _clean_whitespaces
1214
from evap.evaluation.models import (
1315
Contribution,
@@ -22,89 +24,9 @@
2224
)
2325
from evap.evaluation.models_logging import LogEntry
2426

25-
EXAMPLE_DATA: ImportDict = {
26-
"students": [
27-
{"gguid": "0x1", "email": "1@example.com", "name": "1", "christianname": "w_1", "callingname": "1"},
28-
{"gguid": "0x2", "email": "2@example.com", "name": "2", "christianname": "w_2", "callingname": "2"},
29-
],
30-
"lecturers": [
31-
{
32-
"gguid": "0x3",
33-
"email": "3@example.com",
34-
"name": "3",
35-
"christianname": "3",
36-
"titlefront": "Prof. Dr.",
37-
},
38-
{
39-
"gguid": "0x4",
40-
"email": "4@example.com",
41-
"name": "4",
42-
"christianname": "4",
43-
"titlefront": "Dr.",
44-
},
45-
{
46-
"gguid": "0x5",
47-
"email": "5@example.com",
48-
"name": "5",
49-
"christianname": "5",
50-
"titlefront": "",
51-
},
52-
{
53-
"gguid": "0x6",
54-
"email": "6@example.com",
55-
"name": "6",
56-
"christianname": "6",
57-
"titlefront": "",
58-
},
59-
],
60-
"events": [
61-
{
62-
"gguid": "0x5",
63-
"title": "Prozessorientierte Informationssysteme",
64-
"title_en": "Process-oriented information systems",
65-
"type": "Vorlesung",
66-
"isexam": False,
67-
"courses": [],
68-
"appointments": [
69-
{"begin": "30.04.2024 10:15:00", "end": "30.04.2024 11:45:00"},
70-
{"begin": "15.07.2024 10:15:00", "end": "15.07.2024 11:45:00"},
71-
],
72-
"relatedevents": [{"gguid": "0x6"}],
73-
"lecturers": [{"gguid": "0x3"}],
74-
"students": [{"gguid": "0x1"}, {"gguid": "0x2"}],
75-
"language": "Deutsch",
76-
},
77-
{
78-
"gguid": "0x6",
79-
"title": "Prozessorientierte Informationssysteme",
80-
"title_en": "Process-oriented information systems",
81-
"type": "Klausur",
82-
"isexam": True,
83-
"courses": [
84-
{"cprid": "BA-Inf", "scale": "GRADE_PARTICIPATION"},
85-
{"cprid": "MA-Inf", "scale": "GRADE_PARTICIPATION"},
86-
],
87-
"appointments": [{"begin": "29.07.2024 10:15:00", "end": "29.07.2024 11:45:00"}],
88-
"relatedevents": [{"gguid": "0x5"}],
89-
"lecturers": [{"gguid": "0x3"}, {"gguid": "0x4"}, {"gguid": "0x5"}],
90-
"students": [{"gguid": "0x1"}, {"gguid": "0x2"}],
91-
"language": "Deutsch",
92-
},
93-
{
94-
"gguid": "0x7",
95-
"title": "Bachelorprojekt: Prozessorientierte Informationssysteme",
96-
"title_en": "Bachelor's Project: Process-oriented information systems",
97-
"type": "Bachelorprojekt",
98-
"isexam": True,
99-
"courses": [
100-
{"cprid": "BA-Inf", "scale": "GRADE_PARTICIPATION"},
101-
],
102-
"lecturers": [{"gguid": "0x3"}],
103-
"students": [{"gguid": "0x1"}, {"gguid": "0x2"}],
104-
"language": "Englisch",
105-
},
106-
],
107-
}
27+
EXAMPLE_DATA = json.loads(
28+
Path(evap.cms.fixtures.__file__).with_name("import_example_data.json").read_text(encoding="utf-8")
29+
)
10830
EXAMPLE_DATA_WITHOUT_RELATED_EVALUATION = {
10931
"students": EXAMPLE_DATA["students"],
11032
"lecturers": EXAMPLE_DATA["lecturers"],
@@ -281,7 +203,6 @@
281203
},
282204
],
283205
}
284-
EXAMPLE_JSON = json.dumps(EXAMPLE_DATA)
285206

286207

287208
class TestImportUserProfiles(TestCase):

0 commit comments

Comments
 (0)