@@ -1969,6 +1969,76 @@ def test_evaluation_copy(self):
1969
1969
self .assertEqual (copied_evaluation .contributions .count (), 4 )
1970
1970
1971
1971
1972
+ @override_settings (EXAM_QUESTIONNAIRE_IDS = [111 ])
1973
+ class TestEvaluationExamCreation (WebTestStaffMode ):
1974
+ csrf_checks = False
1975
+ url = reverse ("staff:create_exam_evaluation" )
1976
+
1977
+ @classmethod
1978
+ def setUpTestData (cls ):
1979
+ # We need to set the managers language to avoid a database update, when no language is set
1980
+ cls .manager = make_manager (language = "en" )
1981
+ cls .course = baker .make (Course )
1982
+ vote_start_datetime = datetime .datetime .now () - datetime .timedelta (days = 50 )
1983
+ cls .evaluation = baker .make (Evaluation , course = cls .course , vote_start_datetime = vote_start_datetime )
1984
+ cls .evaluation .participants .set (baker .make (UserProfile , _quantity = 3 ))
1985
+ cls .contributions = baker .make (
1986
+ Contribution , evaluation = cls .evaluation , _fill_optional = ["contributor" ], _quantity = 3 , _bulk_create = True
1987
+ )
1988
+ cls .exam_date = datetime .date .today () + datetime .timedelta (days = 10 )
1989
+ cls .params = {"evaluation_id" : cls .evaluation .pk , "exam_date" : cls .exam_date }
1990
+ cls .exam_questionnaire = baker .make (Questionnaire , pk = 111 )
1991
+
1992
+ def test_create_exam_evaluation (self ):
1993
+ self .app .post (self .url , user = self .manager , status = 200 , params = self .params )
1994
+ self .assertEqual (Evaluation .objects .count (), 2 )
1995
+ exam_evaluation = Evaluation .objects .exclude (pk = self .evaluation .pk ).get ()
1996
+ self .assertEqual (exam_evaluation .contributions .count (), self .evaluation .contributions .count ())
1997
+ self .assertEqual (
1998
+ exam_evaluation .vote_start_datetime ,
1999
+ datetime .datetime .combine (self .exam_date + datetime .timedelta (days = 1 ), datetime .time (8 , 0 )),
2000
+ )
2001
+ self .assertEqual (exam_evaluation .vote_end_date , self .exam_date + datetime .timedelta (days = 3 ))
2002
+ self .assertEqual (exam_evaluation .name_de , "Klausur" )
2003
+ self .assertEqual (exam_evaluation .name_en , "Exam" )
2004
+ self .assertEqual (exam_evaluation .course , self .evaluation .course )
2005
+ self .assertQuerySetEqual (exam_evaluation .participants .all (), self .evaluation .participants .all ())
2006
+ self .assertEqual (exam_evaluation .weight , 1 )
2007
+
2008
+ evaluation = Evaluation .objects .get (pk = self .evaluation .pk )
2009
+ self .assertEqual (evaluation .weight , 9 )
2010
+ self .assertEqual (evaluation .vote_end_date , self .exam_date - datetime .timedelta (days = 1 ))
2011
+
2012
+ def test_exam_evaluation_for_single_result (self ):
2013
+ self .evaluation .is_single_result = True
2014
+ self .evaluation .save ()
2015
+ with assert_no_database_modifications ():
2016
+ self .app .post (self .url , user = self .manager , status = 400 , params = self .params )
2017
+
2018
+ def test_exam_evaluation_for_already_existing_exam_evaluation (self ):
2019
+ baker .make (Evaluation , course = self .course , name_en = "Exam" , name_de = "Klausur" )
2020
+ self .assertTrue (self .evaluation .has_exam_evaluation )
2021
+ with assert_no_database_modifications ():
2022
+ self .app .post (self .url , user = self .manager , status = 400 , params = self .params )
2023
+
2024
+ def test_exam_evaluation_with_wrong_date (self ):
2025
+ self .evaluation .vote_start_datetime = datetime .datetime .now () + datetime .timedelta (days = 100 )
2026
+ self .evaluation .vote_end_date = datetime .date .today () + datetime .timedelta (days = 150 )
2027
+ self .evaluation .save ()
2028
+ with assert_no_database_modifications ():
2029
+ self .app .post (self .url , user = self .manager , status = 400 , params = self .params )
2030
+
2031
+ def test_exam_evaluation_with_missing_date (self ):
2032
+ self .params .pop ("exam_date" )
2033
+ with assert_no_database_modifications ():
2034
+ self .app .post (self .url , user = self .manager , status = 400 , params = self .params )
2035
+
2036
+ def test_exam_evaluation_with_wrongly_formatted_date (self ):
2037
+ self .params ["exam_date" ] = ""
2038
+ with assert_no_database_modifications ():
2039
+ self .app .post (self .url , user = self .manager , status = 400 , params = self .params )
2040
+
2041
+
1972
2042
class TestCourseCopyView (WebTestStaffMode ):
1973
2043
@classmethod
1974
2044
def setUpTestData (cls ):
0 commit comments