38
38
_DIGEST_1 = bytes_digest (_CONTENT_1 )
39
39
_DIGEST_2 = bytes_digest (_CONTENT_2 )
40
40
_DIGEST_3 = bytes_digest (_CONTENT_3 )
41
- _FILENAME_1 = "file.c "
41
+ _FILENAME_1 = "file.cpp "
42
42
_FILENAME_2 = "file"
43
43
_FILENAME_3 = "file.py"
44
- _LANGUAGE_1 = "C11 / gcc"
44
+ _LANGUAGE_1 = "C++20 / g++"
45
+ _LANGUAGE_1_ALT = "C++17 / g++"
45
46
46
47
47
48
class TestAddSubmissionMixin (DatabaseMixin , FileSystemMixin ):
@@ -106,65 +107,72 @@ def setUp(self):
106
107
def test_success (self ):
107
108
self .assertTrue (add_submission (
108
109
self .contest .id , self .user .username , self .task .name , _TS ,
109
- {"source.%l" : self .get_path (_FILENAME_1 )}))
110
+ {"source.%l" : self .get_path (_FILENAME_1 )}, None ))
110
111
self .assertSubmissionInDb (_TS , self .task , _LANGUAGE_1 ,
111
112
{"source.%l" : _DIGEST_1 })
112
113
114
+ def test_success_override_language (self ):
115
+ self .assertTrue (add_submission (
116
+ self .contest .id , self .user .username , self .task .name , _TS ,
117
+ {"source.%l" : self .get_path (_FILENAME_1 )}, _LANGUAGE_1_ALT ))
118
+ self .assertSubmissionInDb (_TS , self .task , _LANGUAGE_1_ALT ,
119
+ {"source.%l" : _DIGEST_1 })
120
+
113
121
def test_fail_no_task (self ):
114
122
# We pass a non-existing task name.
115
123
self .assertFalse (add_submission (
116
124
self .contest .id , self .user .username , self .task .name + "_wrong" ,
117
- _TS , {}))
125
+ _TS , {}, None ))
118
126
self .assertSubmissionNotInDb (_TS )
119
127
120
128
def test_fail_no_user (self ):
121
129
# We pass a non-existing username.
122
130
self .assertFalse (add_submission (
123
131
self .contest .id , self .user .username + "_wrong" , self .task .name ,
124
- _TS , {}))
132
+ _TS , {}, None ))
125
133
self .assertSubmissionNotInDb (_TS )
126
134
127
135
def test_fail_no_contest (self ):
128
136
# We pass a non-existing contest id.
129
137
self .assertFalse (add_submission (
130
138
self .contest .id + 100 , self .user .username , self .task .name , _TS ,
131
- {}))
139
+ {}, None ))
132
140
self .assertSubmissionNotInDb (_TS )
133
141
134
142
def test_fail_task_not_in_contest (self ):
135
143
# We pass a contest that does not contain the task.
136
144
self .assertFalse (add_submission (
137
145
self .other_contest .id , self .user .username , self .task .name , _TS ,
138
- {}))
146
+ {}, None ))
139
147
self .assertSubmissionNotInDb (_TS )
140
148
141
149
def test_fail_no_language_inferrable_missing_source (self ):
142
150
# Task requires a language, but we don't provide any file that
143
151
# indicate it.
144
152
self .assertFalse (add_submission (
145
- self .contest .id , self .user .username , self .task .name , _TS , {}))
153
+ self .contest .id , self .user .username , self .task .name , _TS , {}, None ))
146
154
self .assertSubmissionNotInDb (_TS )
147
155
148
156
def test_fail_no_language_inferrable_missing_extension (self ):
149
157
# Task requires a language, but the file we provide does not have
150
158
# an extension defining the language.
151
159
self .assertFalse (add_submission (
152
160
self .contest .id , self .user .username , self .task .name , _TS ,
153
- {"source.%l" : self .get_path (_FILENAME_2 )}))
161
+ {"source.%l" : self .get_path (_FILENAME_2 )}, None ))
154
162
self .assertSubmissionNotInDb (_TS )
155
163
156
164
def test_fail_file_not_found (self ):
157
165
# We provide a path, but the file does not exist.
158
166
self .assertFalse (add_submission (
159
167
self .contest .id , self .user .username , self .task .name , _TS ,
160
- {"source.%l" : self .get_path ("source_not_existing.c" )}))
168
+ {"source.%l" : self .get_path ("source_not_existing.c" )}, None ))
161
169
self .assertSubmissionNotInDb (_TS )
162
170
163
171
def test_fail_file_not_in_submission_format (self ):
164
172
# We provide a file, but for the wrong filename.
165
173
self .assertFalse (add_submission (
166
174
self .contest .id , self .user .username , self .task .name , _TS ,
167
- {"wrong_source.%l" : self .get_path (_FILENAME_1 )}))
175
+ {"wrong_source.%l" : self .get_path (_FILENAME_1 )}, None ))
168
176
self .assertSubmissionNotInDb (_TS )
169
177
170
178
@@ -186,7 +194,7 @@ def test_success_many(self):
186
194
self .contest .id , self .user .username , self .task .name , _TS , {
187
195
"source1.%l" : self .get_path (_FILENAME_1 ),
188
196
"source2.%l" : self .get_path (_FILENAME_1 ),
189
- }))
197
+ }, None ))
190
198
self .assertSubmissionInDb (_TS , self .task , _LANGUAGE_1 , {
191
199
"source1.%l" : _DIGEST_1 ,
192
200
"source2.%l" : _DIGEST_1 ,
@@ -197,7 +205,7 @@ def test_success_missing_file(self):
197
205
# the language.
198
206
self .assertTrue (add_submission (
199
207
self .contest .id , self .user .username , self .task .name , _TS ,
200
- {"source1.%l" : self .get_path (_FILENAME_1 )}))
208
+ {"source1.%l" : self .get_path (_FILENAME_1 )}, None ))
201
209
self .assertSubmissionInDb (_TS , self .task , _LANGUAGE_1 ,
202
210
{"source1.%l" : _DIGEST_1 })
203
211
@@ -206,7 +214,7 @@ def test_fail_language_only_in_one(self):
206
214
self .contest .id , self .user .username , self .task .name , _TS , {
207
215
"source1.%l" : self .get_path (_FILENAME_1 ),
208
216
"source2.%l" : self .get_path (_FILENAME_2 ),
209
- }))
217
+ }, None ))
210
218
self .assertSubmissionNotInDb (_TS )
211
219
212
220
def test_fail_inconsistent_language (self ):
@@ -215,7 +223,7 @@ def test_fail_inconsistent_language(self):
215
223
self .contest .id , self .user .username , self .task .name , _TS , {
216
224
"source1.%l" : self .get_path (_FILENAME_1 ),
217
225
"source2.%l" : self .get_path (_FILENAME_3 ),
218
- }))
226
+ }, None ))
219
227
self .assertSubmissionNotInDb (_TS )
220
228
221
229
@@ -237,7 +245,7 @@ def test_success_many(self):
237
245
self .contest .id , self .user .username , self .task .name , _TS , {
238
246
"source1.%l" : self .get_path (_FILENAME_1 ),
239
247
"source2" : self .get_path (_FILENAME_2 ),
240
- }))
248
+ }, None ))
241
249
self .assertSubmissionInDb (_TS , self .task , _LANGUAGE_1 , {
242
250
"source1.%l" : _DIGEST_1 ,
243
251
"source2" : _DIGEST_2 ,
@@ -248,7 +256,7 @@ def test_success_missing_source_without_language(self):
248
256
# the language.
249
257
self .assertTrue (add_submission (
250
258
self .contest .id , self .user .username , self .task .name , _TS ,
251
- {"source1.%l" : self .get_path (_FILENAME_1 )}))
259
+ {"source1.%l" : self .get_path (_FILENAME_1 )}, None ))
252
260
self .assertSubmissionInDb (_TS , self .task , _LANGUAGE_1 ,
253
261
{"source1.%l" : _DIGEST_1 })
254
262
@@ -257,7 +265,7 @@ def test_fail_missing_source_with_language(self):
257
265
# the language.
258
266
self .assertFalse (add_submission (
259
267
self .contest .id , self .user .username , self .task .name , _TS ,
260
- {"source2" : self .get_path (_FILENAME_2 )}))
268
+ {"source2" : self .get_path (_FILENAME_2 )}, None ))
261
269
self .assertSubmissionNotInDb (_TS )
262
270
263
271
@@ -276,13 +284,13 @@ def setUp(self):
276
284
def test_success_no_language (self ):
277
285
self .assertTrue (add_submission (
278
286
self .contest .id , self .user .username , self .task .name , _TS ,
279
- {"source" : self .get_path (_FILENAME_2 )}))
287
+ {"source" : self .get_path (_FILENAME_2 )}, None ))
280
288
self .assertSubmissionInDb (_TS , self .task , None , {"source" : _DIGEST_2 })
281
289
282
290
def test_success_no_source (self ):
283
291
# Here we don't provide any file, but language is not required.
284
292
self .assertTrue (add_submission (
285
- self .contest .id , self .user .username , self .task .name , _TS , {}))
293
+ self .contest .id , self .user .username , self .task .name , _TS , {}, None ))
286
294
self .assertSubmissionInDb (_TS , self .task , None , {})
287
295
288
296
0 commit comments