Skip to content

Commit 0c4e2ec

Browse files
author
rtschu
committed
integrate into master changes
1 parent 3a77069 commit 0c4e2ec

File tree

6 files changed

+1954
-1012
lines changed

6 files changed

+1954
-1012
lines changed

block_evasys_sync.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function get_content() {
152152
$end = $record->get('enddate');
153153
$recordhasstandardtime = $record->get('usestandardtime');
154154
} else {
155-
if (!$ismodeautomated && $categoryhasstandardtime) {
155+
if ($categoryhasstandardtime) {
156156
$start = $categoryhasstandardtime['start'];
157157
$end = $categoryhasstandardtime['end'];
158158
$recordhasstandardtime = true;
@@ -232,7 +232,7 @@ public function get_content() {
232232
// Append this course.
233233
$courses[] = $course;
234234
}
235-
$standardttimemode = (!$ismodeautomated && $hasstandardtime && !$record);
235+
$standardttimemode = ($recordhasstandardtime && !$wasstarted);
236236
// Create the data object for the mustache table.
237237
$data = array(
238238
'href' => $href,
@@ -243,7 +243,7 @@ public function get_content() {
243243
* In case of the automated workflow, we require surveys
244244
* in order to be able to automatically trigger the evaluation. */
245245
'showcontrols' => ($hassurveys || !$ismodeautomated) && count($evasyscourses) > 0 && !$invalidcourses,
246-
'usestandardtimelayout' => (!$ismodeautomated && $hasstandardtime && !$wasstarted),
246+
'usestandardtimelayout' => $standardttimemode,
247247
// Choose mode.
248248
'direct' => $ismodeautomated,
249249
'startdisabled' => $startdisabled || $standardttimemode,

generator.py

+64-9
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,44 @@
1515
"idnumber": ["none", "invalid", "one"],
1616
"mapped": ["none", "invalid", "one", "multi"],
1717
"internalstate": ["notopened", "opened", "closed", "manual", "none"],
18-
"actualstate": ["open", "closed", "mixed"]
18+
"actualstate": ["open", "closed", "mixed"],
19+
"recordstandardtime": ["recordstandardtimemode", "recordnonstandardtimemode", "norecordstandardtimemode"]
1920
}
2021

22+
ILLEGALSTATES = [
23+
{"recordstandardtime": "recordstandardtimemode", "internalstate": "none"},
24+
{"recordstandardtime": "recordnonstandardtimemode", "internalstate": "none"},
25+
{"recordstandardtime": "norecordstandardtimemode", "internalstate": "notopened"},
26+
{"recordstandardtime": "norecordstandardtimemode", "internalstate": "opened"},
27+
{"recordstandardtime": "norecordstandardtimemode", "internalstate": "closed"},
28+
{"recordstandardtime": "norecordstandardtimemode", "internalstate": "manual"},
29+
]
30+
31+
32+
def illegal_state(scenario):
33+
for fullillegalstate in ILLEGALSTATES:
34+
illegal = True
35+
for illegalstate in fullillegalstate.keys():
36+
if scenario[list(OPTIONS.keys()).index(illegalstate)] != fullillegalstate[illegalstate]:
37+
illegal = False
38+
break
39+
if illegal:
40+
return True
41+
if scenario[5] == "none" and scenario[7] != "norecordstandardtimemode":
42+
print(scenario)
43+
return False
44+
2145

22-
def get_checks(mode, standardtime, students_state, idnumber_state, mapped_state, internal_state, actual_state):
46+
def get_checks(mode, standardtime, students_state, idnumber_state, mapped_state, internal_state, actual_state, recordstandardtimemode):
2347
"""
2448
This Function will take the scenario parameters and construct the resulting checks.
2549
:return: The combined checks for the parameters.
2650
"""
27-
checks = ""
2851
# If there are no mapped courses the Block not offer the option to "Show surveys"
2952
if (idnumber_state == "none") and (mapped_state == "none"):
3053
return "Then I should see \"Change mapping\"\n And I should not see \"Name:\"\n "
3154

55+
checks = ""
3256
# In all other cases (even if there are only invalid entries) we need to click the button to start code execution
3357
checks += "And I load the evasys block\n"
3458

@@ -62,7 +86,7 @@ def get_checks(mode, standardtime, students_state, idnumber_state, mapped_state,
6286
checks += "And I should see \"There are some closed surveys, but all surveys should be open.\"" + "\n"
6387

6488
# if the standardtimemodecheckbox should be present from the start we also want to check that
65-
checks += checks_standardtimemode(standardtime, mode, internal_state, actual_state) + "\n"
89+
checks += checks_standardtimemode(standardtime, mode, internal_state, recordstandardtimemode) + "\n"
6690
# if there are no students that are eligible to evaluate we want to output a warning
6791
checks += student_checks[students_state]
6892
checks = checks.replace("\n", "\n ")
@@ -136,13 +160,15 @@ def get_combi_sentence(set, dictionary, param_name):
136160

137161

138162
def get_combi_description(mode, standardtime, students_state, idnumber_state, mapped_state, internal_state,
139-
actual_state):
163+
actual_state, recordstandardtimemode):
140164
"""
141165
This will construct the description for a scenario that covers multiple states.
142166
:return: String the description of the scenario.
143167
"""
144168
if "none" in mapped_state and "none" in idnumber_state:
145169
return "If there are no related evasys-courses I should not see any.\n "
170+
if not recordstandardtimemode == "norecordstandardtimemode":
171+
standardtime = {1} if recordstandardtimemode == "recordstandardtimemode" else {0}
146172
description = ""
147173
description += get_combi_sentence(standardtime, standardtimemode_descriptions, "standardtime")
148174
description += get_combi_sentence(students_state, students_descriptions, "number of students")
@@ -153,7 +179,7 @@ def get_combi_description(mode, standardtime, students_state, idnumber_state, ma
153179
return description
154180

155181

156-
def get_scenario(mode, standardtime, students_state, idnumber_state, mapped_state, internal_state, actual_state):
182+
def get_scenario(mode, standardtime, students_state, idnumber_state, mapped_state, internal_state, actual_state, recordstandardtimemode):
157183
"""
158184
This constructs the actual scenario by building all courses, states etc.
159185
:return: string the combined enviroment specifiing string for a scenario
@@ -164,6 +190,7 @@ def get_scenario(mode, standardtime, students_state, idnumber_state, mapped_stat
164190
behat_scenario += step_idnumberstate(idnumber_state, actual_state)
165191
behat_scenario += step_mappedstate(mapped_state, actual_state)
166192
behat_scenario += step_internal_state[internal_state].replace("{{course}}", str(coursename)) + "\n"
193+
behat_scenario += step_record_standardtimemode[recordstandardtimemode].replace("{{course}}", str(coursename)) + "\n"
167194
behat_scenario += "And I turn editing mode on\n"
168195
behat_scenario += "And I add the \"EvaSys Sync\" block\n"
169196
behat_scenario += "And I turn editing mode off\n"
@@ -246,6 +273,7 @@ def condense_keep_options(fullarray):
246273
if changed:
247274
break
248275
fullarray = new_array
276+
249277
return fullarray
250278

251279

@@ -278,17 +306,20 @@ def main():
278306
# get the checks for all options to be able to condense options with the same expected outcome
279307
uncondensed_dict = {}
280308
for scenario in cartesianoptions:
281-
check = get_checks(scenario[0], scenario[1], scenario[2], scenario[3], scenario[4], scenario[5], scenario[6])
309+
check = get_checks(scenario[0], scenario[1], scenario[2], scenario[3], scenario[4], scenario[5], scenario[6], scenario[7])
282310
if not check in uncondensed_dict.keys():
283311
uncondensed_dict[check] = []
284312
uncondensed_dict[check].append(scenario)
285313

286314
# condense those scenarios
287315
condensed_dict = {}
288316
if CONDENSE_TESTS:
317+
i = 0
289318
for check in uncondensed_dict.keys():
290319
scenarios = uncondensed_dict[check]
291320
condensed_dict[check] = condense_keep_options(scenarios)
321+
i += 1
322+
print("Condensed " + str(i) + " of " + str(len(uncondensed_dict.keys())))
292323
else:
293324
for check in uncondensed_dict.keys():
294325
fullarray = uncondensed_dict[check]
@@ -310,18 +341,42 @@ def main():
310341
# do a deep-copy of the scenario because sets can only be accessed by pop which alters the set itself
311342
scenario_copy = copy.deepcopy(scenario)
312343
desc = get_combi_description(scenario[0], scenario[1], scenario[2], scenario[3], scenario[4], scenario[5],
313-
scenario[6])
344+
scenario[6], scenario[7])
314345
mode = scenario_copy[0].pop()
315346
standardtime = scenario_copy[1].pop()
316347
students_state = scenario_copy[2].pop()
317348
idnumber_state = scenario_copy[3].pop()
318349
mapped_state = scenario_copy[4].pop()
319350
internal_state = scenario_copy[5].pop()
320351
actual_state = scenario_copy[6].pop()
352+
recordstandardtime = scenario_copy[7].pop()
321353
if actual_state == "mixed" and len(scenario_copy[6]) > 0:
322354
actual_state = scenario_copy[6].pop()
355+
356+
corrected = True
357+
illegal = False
358+
illegals = []
359+
while corrected:
360+
corrected = False
361+
if illegal_state([mode, standardtime, students_state, idnumber_state, mapped_state, internal_state,
362+
actual_state, recordstandardtime]):
363+
corrected = True
364+
illegals.append([mode, standardtime, students_state, idnumber_state, mapped_state, internal_state,
365+
actual_state, recordstandardtime])
366+
if len(scenario_copy[5]) >= 1:
367+
internal_state = scenario_copy[5].pop()
368+
elif len(scenario_copy[7]) >= 1:
369+
recordstandardtime = scenario_copy[7].pop()
370+
else:
371+
if len(illegals) > 1:
372+
print("Illegal multiscenario")
373+
print(illegals)
374+
illegal = True
375+
corrected = False
376+
if illegal:
377+
continue
323378
scen_text = get_scenario(mode, standardtime, students_state, idnumber_state, mapped_state, internal_state,
324-
actual_state)
379+
actual_state, recordstandardtime)
325380
if not scen_text:
326381
print("Warning impossible scenario!!!")
327382
continue

tests/behat/behat_block_evasys_sync.php

+21
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,27 @@ public function the_internal_state_of_course_is($shortname, $mode) {
331331
$record->save();
332332
}
333333

334+
/**
335+
* @Given the recordstandardtimemode for course :shortname is set to :value
336+
*/
337+
public function the_recorstandardtime_for_course_is_set($shortname, $mode) {
338+
global $DB;
339+
$id = $this->get_courseid_by_shortname($shortname);
340+
$record = \block_evasys_sync\course_evaluation_allocation::get_record_by_course($id, false);
341+
if (!$record) {
342+
$record = new \block_evasys_sync\course_evaluation_allocation(0);
343+
$record->set('course', $id);
344+
}
345+
$record->set('usestandardtime', $mode == "true");
346+
$record->save();
347+
}
348+
349+
/**
350+
* @Given the recordstandardtimemode for course :shortname is not set
351+
*/
352+
public function the_recordstandardtimemode_for_course_is_not_set($shortname) {
353+
return;
354+
}
334355

335356
/**
336357
* @Given no courses are mapped to course :shortname

0 commit comments

Comments
 (0)