25
25
COURSE_ID = "Test_Course"
26
26
27
27
STUDENT_ID = u"Student"
28
- OLD_STUDENT_ID = "Old_Student"
28
+
29
+ PRE_FILE_SIZE_STUDENT_ID = "Pre_FileSize_Student"
30
+
31
+ PRE_FILE_NAME_STUDENT_ID = "Pre_FileName_Student"
29
32
30
33
STUDENT_USERNAME = "Student Username"
31
34
54
57
item_type = "openassessment"
55
58
)
56
59
57
- OLD_STUDENT_ITEM = dict (
58
- student_id = OLD_STUDENT_ID ,
60
+ PRE_FILE_SIZE_STUDENT_ITEM = dict (
61
+ student_id = PRE_FILE_SIZE_STUDENT_ID ,
62
+ course_id = COURSE_ID ,
63
+ item_id = ITEM_ID ,
64
+ item_type = "openassessment"
65
+ )
66
+
67
+ PRE_FILE_NAME_STUDENT_ITEM = dict (
68
+ student_id = PRE_FILE_NAME_STUDENT_ID ,
59
69
course_id = COURSE_ID ,
60
70
item_id = ITEM_ID ,
61
71
item_type = "openassessment"
@@ -809,7 +819,8 @@ def setUp(self):
809
819
self .maxDiff = None # pylint: disable=invalid-name
810
820
811
821
self .submission = self ._create_submission (STUDENT_ITEM )
812
- self .old_style_submission = self ._create_submission (OLD_STUDENT_ITEM )
822
+ self .pre_file_size_submission = self ._create_submission (PRE_FILE_SIZE_STUDENT_ITEM )
823
+ self .pre_file_name_submission = self ._create_submission (PRE_FILE_NAME_STUDENT_ITEM )
813
824
self .scorer_submission = self ._create_submission (SCORER_ITEM )
814
825
815
826
self .file_name_1 = 'file_name_1.jpg'
@@ -820,12 +831,14 @@ def setUp(self):
820
831
self .file_key_1 = '{}/{}/{}' .format (STUDENT_ID , COURSE_ID , ITEM_ID )
821
832
self .file_key_2 = '{}/{}/{}/1' .format (STUDENT_ID , COURSE_ID , ITEM_ID )
822
833
self .file_key_3 = '{}/{}/{}/2' .format (STUDENT_ID , COURSE_ID , ITEM_ID )
823
- self .file_key_4 = '{}/{}/{}' .format (OLD_STUDENT_ID , COURSE_ID , ITEM_ID )
834
+ self .file_key_4 = '{}/{}/{}' .format (PRE_FILE_SIZE_STUDENT_ID , COURSE_ID , ITEM_ID )
835
+ self .file_key_5 = '{}/{}/{}' .format (PRE_FILE_NAME_STUDENT_ID , COURSE_ID , ITEM_ID )
824
836
825
837
self .file_description_1 = 'Some Description 1'
826
838
self .file_description_2 = 'Some Description 2'
827
839
self .file_description_3 = 'Some Description 3'
828
840
self .file_description_4 = 'Some Description 4'
841
+ self .file_description_5 = 'Some Description 5'
829
842
830
843
self .file_size_1 = 2 ** 20
831
844
self .file_size_2 = 2 ** 21
@@ -849,39 +862,74 @@ def setUp(self):
849
862
850
863
# Older responses (approx. pre-2020) won't have files_sizes
851
864
# and will have the key 'files_name' rather than 'files_names'
852
- self .old_style_answer = {
865
+ self .pre_file_size_answer = {
853
866
'parts' : [{'text' : self .answer_text }],
854
867
'file_keys' : [self .file_key_4 ],
855
868
'files_descriptions' : [self .file_description_4 ],
856
869
'files_name' : [self .file_name_4 ]
857
870
}
858
871
872
+ # And answers a bit older than that (approx. pre-Nov. 2019) won't
873
+ # have any file name data
874
+ self .pre_file_name_answer = {
875
+ 'parts' : [{'text' : self .answer_text }],
876
+ 'file_keys' : [self .file_key_5 ],
877
+ 'files_descriptions' : [self .file_description_5 ],
878
+ }
879
+
859
880
self .submission_files_data = [
860
881
{
861
882
'course_id' : COURSE_ID ,
862
883
'block_id' : ITEM_ID ,
863
- 'student_id' : OLD_STUDENT_ID ,
884
+ 'student_id' : PRE_FILE_NAME_STUDENT_ID ,
885
+ 'key' : self .file_key_5 ,
886
+ 'name' : 'File_1' ,
887
+ 'type' : OraDownloadData .ATTACHMENT ,
888
+ 'description' : self .file_description_5 ,
889
+ 'size' : 0 ,
890
+ 'file_path' : '{}/{}/{}/attachments/{}' .format (
891
+ COURSE_ID , ITEM_ID , PRE_FILE_NAME_STUDENT_ID , "File_1"
892
+ ),
893
+ },
894
+ {
895
+ 'course_id' : COURSE_ID ,
896
+ 'block_id' : ITEM_ID ,
897
+ 'student_id' : PRE_FILE_NAME_STUDENT_ID ,
898
+ 'key' : '' ,
899
+ 'name' : 'part_0.txt' ,
900
+ 'type' : OraDownloadData .TEXT ,
901
+ 'description' : 'Submission text.' ,
902
+ 'content' : self .answer_text ,
903
+ 'size' : len (self .answer_text ),
904
+ 'file_path' : '{}/{}/{}/{}' .format (
905
+ COURSE_ID , ITEM_ID , PRE_FILE_NAME_STUDENT_ID , 'part_0.txt'
906
+ ),
907
+ },
908
+ {
909
+ 'course_id' : COURSE_ID ,
910
+ 'block_id' : ITEM_ID ,
911
+ 'student_id' : PRE_FILE_SIZE_STUDENT_ID ,
864
912
'key' : self .file_key_4 ,
865
913
'name' : self .file_name_4 ,
866
914
'type' : OraDownloadData .ATTACHMENT ,
867
915
'description' : self .file_description_4 ,
868
916
'size' : 0 ,
869
917
'file_path' : '{}/{}/{}/attachments/{}' .format (
870
- COURSE_ID , ITEM_ID , OLD_STUDENT_ID , self .file_name_4
918
+ COURSE_ID , ITEM_ID , PRE_FILE_SIZE_STUDENT_ID , self .file_name_4
871
919
),
872
920
},
873
921
{
874
922
'course_id' : COURSE_ID ,
875
923
'block_id' : ITEM_ID ,
876
- 'student_id' : OLD_STUDENT_ID ,
924
+ 'student_id' : PRE_FILE_SIZE_STUDENT_ID ,
877
925
'key' : '' ,
878
926
'name' : 'part_0.txt' ,
879
927
'type' : OraDownloadData .TEXT ,
880
928
'description' : 'Submission text.' ,
881
929
'content' : self .answer_text ,
882
930
'size' : len (self .answer_text ),
883
931
'file_path' : '{}/{}/{}/{}' .format (
884
- COURSE_ID , ITEM_ID , OLD_STUDENT_ID , 'part_0.txt'
932
+ COURSE_ID , ITEM_ID , PRE_FILE_SIZE_STUDENT_ID , 'part_0.txt'
885
933
),
886
934
},
887
935
{
@@ -954,11 +1002,16 @@ def test_collect_ora2_submission_files(self):
954
1002
submission .answer = self .answer
955
1003
submission .save ()
956
1004
957
- # Answers once had a different format
958
- old_uuid = self .old_style_submission ['uuid' ]
959
- old_style_submission = sub_api ._get_submission_model (old_uuid ) # pylint: disable=protected-access
960
- old_style_submission .answer = self .old_style_answer
961
- old_style_submission .save ()
1005
+ # older submission formats
1006
+ pre_filesize_uuid = self .pre_file_size_submission ['uuid' ]
1007
+ pre_file_size_submission = sub_api ._get_submission_model (pre_filesize_uuid ) # pylint: disable=protected-access
1008
+ pre_file_size_submission .answer = self .pre_file_size_answer
1009
+ pre_file_size_submission .save ()
1010
+
1011
+ pre_filename_uuid = self .pre_file_name_submission ['uuid' ]
1012
+ pre_file_name_submission = sub_api ._get_submission_model (pre_filename_uuid ) # pylint: disable=protected-access
1013
+ pre_file_name_submission .answer = self .pre_file_name_answer
1014
+ pre_file_name_submission .save ()
962
1015
963
1016
# answer for scorer submission is just a string, and `collect_ora2_submission_files`
964
1017
# raises exception because of it, so we change it to empty dict
@@ -982,6 +1035,7 @@ def test_create_zip_with_attachments(self):
982
1035
OraDownloadData .create_zip_with_attachments (file , COURSE_ID , self .submission_files_data )
983
1036
984
1037
download_mock .assert_has_calls ([
1038
+ call (self .file_key_5 ),
985
1039
call (self .file_key_4 ),
986
1040
call (self .file_key_1 ),
987
1041
call (self .file_key_2 ),
@@ -990,10 +1044,10 @@ def test_create_zip_with_attachments(self):
990
1044
991
1045
zip_file = zipfile .ZipFile (file )
992
1046
993
- # archive should contain four attachments, two parts text file and one csv
994
- self .assertEqual (len (zip_file .infolist ()), 7 )
1047
+ # archive should contain five attachments, three parts text file and one csv
1048
+ self .assertEqual (len (zip_file .infolist ()), 9 )
995
1049
996
- # check for old_user 's file and text
1050
+ # check for pre_file_name_user 's file and text
997
1051
self .assertEqual (
998
1052
zip_file .read (self .submission_files_data [0 ]['file_path' ]),
999
1053
file_content
@@ -1002,22 +1056,31 @@ def test_create_zip_with_attachments(self):
1002
1056
zip_file .read (self .submission_files_data [1 ]['file_path' ]),
1003
1057
self .answer_text .encode ('utf-8' )
1004
1058
)
1005
- # check that main user 's attachments have been written to the archive
1059
+ # check for pre_file_size_user 's file and text
1006
1060
self .assertEqual (
1007
1061
zip_file .read (self .submission_files_data [2 ]['file_path' ]),
1008
1062
file_content
1009
1063
)
1010
1064
self .assertEqual (
1011
1065
zip_file .read (self .submission_files_data [3 ]['file_path' ]),
1012
- file_content
1066
+ self . answer_text . encode ( 'utf-8' )
1013
1067
)
1068
+ # check that main user's attachments have been written to the archive
1014
1069
self .assertEqual (
1015
1070
zip_file .read (self .submission_files_data [4 ]['file_path' ]),
1016
1071
file_content
1017
1072
)
1018
- # main user's text response
1019
1073
self .assertEqual (
1020
1074
zip_file .read (self .submission_files_data [5 ]['file_path' ]),
1075
+ file_content
1076
+ )
1077
+ self .assertEqual (
1078
+ zip_file .read (self .submission_files_data [6 ]['file_path' ]),
1079
+ file_content
1080
+ )
1081
+ # main user's text response
1082
+ self .assertEqual (
1083
+ zip_file .read (self .submission_files_data [7 ]['file_path' ]),
1021
1084
self .answer_text .encode ('utf-8' )
1022
1085
)
1023
1086
0 commit comments