Description:
add submission test
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r761:4315e4a33c9c - - 6 files changed: 101 inserted, 233 deleted

@@ -0,0 +1,44
1 + require "application_system_test_case"
2 +
3 + class SubmissionsTest < ApplicationSystemTestCase
4 + # test "visiting the index" do
5 + # visit users_url
6 + #
7 + # assert_selector "h1", text: "User"
8 + # end
9 +
10 + test "add new submission" do
11 + #admin can add new submission regardless of availability of the problem
12 + login('admin','admin')
13 + visit direct_edit_problem_submissions_path(problems(:prob_sub))
14 + assert_text 'Live submit'
15 + find('.ace_text-input',visible: false).set "test code (will cause compilation error)"
16 + click_on 'Submit'
17 + page.accept_confirm
18 + assert_text 'less than a minute ago'
19 + visit logout_main_path
20 +
21 + #normal user can submit available problem
22 + login('john','hello')
23 + visit direct_edit_problem_submissions_path(problems(:prob_add))
24 + assert_text 'Live submit'
25 + find('.ace_text-input',visible: false).set "test code (will cause compilation error)"
26 + click_on 'Submit'
27 + page.accept_confirm
28 + assert_text 'less than a minute ago'
29 + visit logout_main_path
30 +
31 + #but not unavailable problem
32 + login('john','hello')
33 + visit direct_edit_problem_submissions_path(problems(:prob_sub))
34 + assert_text 'You are not authorized'
35 + end
36 +
37 +
38 + def login(username,password)
39 + visit root_path
40 + fill_in "Login", with: username
41 + fill_in "Password", with: password
42 + click_on "Login"
43 + end
44 + end
@@ -74,24 +74,27
74 bootstrap3-datetimepicker-rails (4.17.47)
74 bootstrap3-datetimepicker-rails (4.17.47)
75 momentjs-rails (>= 2.8.1)
75 momentjs-rails (>= 2.8.1)
76 builder (3.2.3)
76 builder (3.2.3)
77 byebug (11.0.1)
77 byebug (11.0.1)
78 capybara (3.25.0)
78 capybara (3.25.0)
79 addressable
79 addressable
80 mini_mime (>= 0.1.3)
80 mini_mime (>= 0.1.3)
81 nokogiri (~> 1.8)
81 nokogiri (~> 1.8)
82 rack (>= 1.6.0)
82 rack (>= 1.6.0)
83 rack-test (>= 0.6.3)
83 rack-test (>= 0.6.3)
84 regexp_parser (~> 1.5)
84 regexp_parser (~> 1.5)
85 xpath (~> 3.2)
85 xpath (~> 3.2)
86 + capybara-console (0.0.4)
87 + capybara
88 + rails (>= 3.0)
86 childprocess (1.0.1)
89 childprocess (1.0.1)
87 rake (< 13.0)
90 rake (< 13.0)
88 coffee-rails (4.2.2)
91 coffee-rails (4.2.2)
89 coffee-script (>= 2.2.0)
92 coffee-script (>= 2.2.0)
90 railties (>= 4.0.0)
93 railties (>= 4.0.0)
91 coffee-script (2.4.1)
94 coffee-script (2.4.1)
92 coffee-script-source
95 coffee-script-source
93 execjs
96 execjs
94 coffee-script-source (1.12.2)
97 coffee-script-source (1.12.2)
95 concurrent-ruby (1.1.5)
98 concurrent-ruby (1.1.5)
96 crass (1.0.4)
99 crass (1.0.4)
97 dynamic_form (1.1.4)
100 dynamic_form (1.1.4)
@@ -287,24 +290,25
287 ace-rails-ap
290 ace-rails-ap
288 activerecord-session_store
291 activerecord-session_store
289 autoprefixer-rails
292 autoprefixer-rails
290 best_in_place (~> 3.0.1)
293 best_in_place (~> 3.0.1)
291 bootsnap (>= 1.1.0)
294 bootsnap (>= 1.1.0)
292 bootstrap-datepicker-rails
295 bootstrap-datepicker-rails
293 bootstrap-sass (~> 3.4.1)
296 bootstrap-sass (~> 3.4.1)
294 bootstrap-switch-rails
297 bootstrap-switch-rails
295 bootstrap-toggle-rails
298 bootstrap-toggle-rails
296 bootstrap3-datetimepicker-rails
299 bootstrap3-datetimepicker-rails
297 byebug
300 byebug
298 capybara (>= 2.15)
301 capybara (>= 2.15)
302 + capybara-console
299 coffee-rails
303 coffee-rails
300 dynamic_form
304 dynamic_form
301 fuzzy-string-match
305 fuzzy-string-match
302 haml
306 haml
303 haml-rails
307 haml-rails
304 in_place_editing
308 in_place_editing
305 jbuilder (~> 2.5)
309 jbuilder (~> 2.5)
306 jquery-countdown-rails
310 jquery-countdown-rails
307 jquery-datatables-rails
311 jquery-datatables-rails
308 jquery-rails
312 jquery-rails
309 jquery-tablesorter
313 jquery-tablesorter
310 jquery-timepicker-addon-rails
314 jquery-timepicker-addon-rails
@@ -37,28 +37,24
37 = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit',
37 = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit',
38 data: {confirm: "Submitting this source code for task #{@problem.long_name}?"}
38 data: {confirm: "Submitting this source code for task #{@problem.long_name}?"}
39 - # latest submission status
39 - # latest submission status
40 .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"}
40 .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"}
41 .panel-heading
41 .panel-heading
42 Latest Submission Status
42 Latest Submission Status
43 = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission
43 = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission
44 .panel-body
44 .panel-body
45 %div#latest_status
45 %div#latest_status
46 - if @submission
46 - if @submission
47 = render :partial => 'submission_short',
47 = render :partial => 'submission_short',
48 :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id }
48 :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id }
49 - .row
50 - .col-md-12
51 - %h2 Console
52 - %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20}
53
49
54 - if @submission
50 - if @submission
55 .modal.fade#compiler{tabindex: -1,role: 'dialog'}
51 .modal.fade#compiler{tabindex: -1,role: 'dialog'}
56 .modal-dialog.modal-lg{role:'document'}
52 .modal-dialog.modal-lg{role:'document'}
57 .modal-content
53 .modal-content
58 .modal-header
54 .modal-header
59 %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}}
55 %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}}
60 %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} &times;
56 %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} &times;
61 %h4 Compiler message
57 %h4 Compiler message
62 .modal-body
58 .modal-body
63 %pre#compiler_msg= @submission.compiler_message
59 %pre#compiler_msg= @submission.compiler_message
64 .modal-footer
60 .modal-footer
@@ -80,231 +76,12
80 e.gotoLine(1);
76 e.gotoLine(1);
81 };
77 };
82 reader.readAsText(file)
78 reader.readAsText(file)
83 });
79 });
84
80
85 //brython();
81 //brython();
86 });
82 });
87
83
88
84
89
85
90
86
91
87
92 - %script#__main__{type:'text/python3'}
93 - :plain
94 - import sys
95 - import traceback
96 -
97 - from browser import document as doc
98 - from browser import window, alert, console
99 -
100 - _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
101 - for supporting Python development. See www.python.org for more information."""
102 -
103 - _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
104 - All Rights Reserved.
105 -
106 - Copyright (c) 2001-2013 Python Software Foundation.
107 - All Rights Reserved.
108 -
109 - Copyright (c) 2000 BeOpen.com.
110 - All Rights Reserved.
111 -
112 - Copyright (c) 1995-2001 Corporation for National Research Initiatives.
113 - All Rights Reserved.
114 -
115 - Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
116 - All Rights Reserved."""
117 -
118 - _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
119 - All rights reserved.
120 -
121 - Redistribution and use in source and binary forms, with or without
122 - modification, are permitted provided that the following conditions are met:
123 -
124 - Redistributions of source code must retain the above copyright notice, this
125 - list of conditions and the following disclaimer. Redistributions in binary
126 - form must reproduce the above copyright notice, this list of conditions and
127 - the following disclaimer in the documentation and/or other materials provided
128 - with the distribution.
129 - Neither the name of the <ORGANIZATION> nor the names of its contributors may
130 - be used to endorse or promote products derived from this software without
131 - specific prior written permission.
132 -
133 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
134 - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
135 - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
136 - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
137 - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
138 - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
139 - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
140 - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
141 - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
142 - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
143 - POSSIBILITY OF SUCH DAMAGE.
144 - """
145 -
146 - def credits():
147 - print(_credits)
148 - credits.__repr__ = lambda:_credits
149 -
150 - def copyright():
151 - print(_copyright)
152 - copyright.__repr__ = lambda:_copyright
153 -
154 - def license():
155 - print(_license)
156 - license.__repr__ = lambda:_license
157 -
158 - def write(data):
159 - doc['console'].value += str(data)
160 -
161 -
162 - sys.stdout.write = sys.stderr.write = write
163 - history = []
164 - current = 0
165 - _status = "main" # or "block" if typing inside a block
166 -
167 - # execution namespace
168 - editor_ns = {'credits':credits,
169 - 'copyright':copyright,
170 - 'license':license,
171 - '__name__':'__main__'}
172 -
173 - def cursorToEnd(*args):
174 - pos = len(doc['console'].value)
175 - doc['console'].setSelectionRange(pos, pos)
176 - doc['console'].scrollTop = doc['console'].scrollHeight
177 -
178 - def get_col(area):
179 - # returns the column num of cursor
180 - sel = doc['console'].selectionStart
181 - lines = doc['console'].value.split('\n')
182 - for line in lines[:-1]:
183 - sel -= len(line) + 1
184 - return sel
185 -
186 -
187 - def myKeyPress(event):
188 - global _status, current
189 - if event.keyCode == 9: # tab key
190 - event.preventDefault()
191 - doc['console'].value += " "
192 - elif event.keyCode == 13: # return
193 - src = doc['console'].value
194 - if _status == "main":
195 - currentLine = src[src.rfind('>>>') + 4:]
196 - elif _status == "3string":
197 - currentLine = src[src.rfind('>>>') + 4:]
198 - currentLine = currentLine.replace('\n... ', '\n')
199 - else:
200 - currentLine = src[src.rfind('...') + 4:]
201 - if _status == 'main' and not currentLine.strip():
202 - doc['console'].value += '\n>>> '
203 - event.preventDefault()
204 - return
205 - doc['console'].value += '\n'
206 - history.append(currentLine)
207 - current = len(history)
208 - if _status == "main" or _status == "3string":
209 - try:
210 - _ = editor_ns['_'] = eval(currentLine, editor_ns)
211 - if _ is not None:
212 - write(repr(_)+'\n')
213 - doc['console'].value += '>>> '
214 - _status = "main"
215 - except IndentationError:
216 - doc['console'].value += '... '
217 - _status = "block"
218 - except SyntaxError as msg:
219 - if str(msg) == 'invalid syntax : triple string end not found' or \
220 - str(msg).startswith('Unbalanced bracket'):
221 - doc['console'].value += '... '
222 - _status = "3string"
223 - elif str(msg) == 'eval() argument must be an expression':
224 - try:
225 - exec(currentLine, editor_ns)
226 - except:
227 - traceback.print_exc()
228 - doc['console'].value += '>>> '
229 - _status = "main"
230 - elif str(msg) == 'decorator expects function':
231 - doc['console'].value += '... '
232 - _status = "block"
233 - else:
234 - traceback.print_exc()
235 - doc['console'].value += '>>> '
236 - _status = "main"
237 - except:
238 - traceback.print_exc()
239 - doc['console'].value += '>>> '
240 - _status = "main"
241 - elif currentLine == "": # end of block
242 - block = src[src.rfind('>>>') + 4:].splitlines()
243 - block = [block[0]] + [b[4:] for b in block[1:]]
244 - block_src = '\n'.join(block)
245 - # status must be set before executing code in globals()
246 - _status = "main"
247 - try:
248 - _ = exec(block_src, editor_ns)
249 - if _ is not None:
250 - print(repr(_))
251 - except:
252 - traceback.print_exc()
253 - doc['console'].value += '>>> '
254 - else:
255 - doc['console'].value += '... '
256 -
257 - cursorToEnd()
258 - event.preventDefault()
259 -
260 - def myKeyDown(event):
261 - global _status, current
262 - if event.keyCode == 37: # left arrow
263 - sel = get_col(doc['console'])
264 - if sel < 5:
265 - event.preventDefault()
266 - event.stopPropagation()
267 - elif event.keyCode == 36: # line start
268 - pos = doc['console'].selectionStart
269 - col = get_col(doc['console'])
270 - doc['console'].setSelectionRange(pos - col + 4, pos - col + 4)
271 - event.preventDefault()
272 - elif event.keyCode == 38: # up
273 - if current > 0:
274 - pos = doc['console'].selectionStart
275 - col = get_col(doc['console'])
276 - # remove current line
277 - doc['console'].value = doc['console'].value[:pos - col + 4]
278 - current -= 1
279 - doc['console'].value += history[current]
280 - event.preventDefault()
281 - elif event.keyCode == 40: # down
282 - if current < len(history) - 1:
283 - pos = doc['console'].selectionStart
284 - col = get_col(doc['console'])
285 - # remove current line
286 - doc['console'].value = doc['console'].value[:pos - col + 4]
287 - current += 1
288 - doc['console'].value += history[current]
289 - event.preventDefault()
290 - elif event.keyCode == 8: # backspace
291 - src = doc['console'].value
292 - lstart = src.rfind('\n')
293 - if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6):
294 - event.preventDefault()
295 - event.stopPropagation()
296 -
297 -
298 - doc['console'].bind('keypress', myKeyPress)
299 - doc['console'].bind('keydown', myKeyDown)
300 - doc['console'].bind('click', cursorToEnd)
301 - v = sys.implementation.version
302 - doc['console'].value = "Brython %s.%s.%s on %s %s\n>>> " % (
303 - v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion)
304 - #doc['console'].value += 'Type "copyright", "credits" or "license" for more information.'
305 - doc['console'].focus()
306 - cursorToEnd()
307 -
308 -
309 -
310 -
@@ -1,36 +1,36
1 - Language_1:
1 + Language_c:
2 name: c
2 name: c
3 pretty_name: C
3 pretty_name: C
4 ext: c
4 ext: c
5 common_ext: c
5 common_ext: c
6
6
7 - Language_2:
7 + Language_cpp:
8 name: cpp
8 name: cpp
9 pretty_name: C++
9 pretty_name: C++
10 ext: cpp
10 ext: cpp
11 common_ext: cpp,cc
11 common_ext: cpp,cc
12
12
13 - Language_3:
13 + Language_pas:
14 name: pas
14 name: pas
15 pretty_name: Pascal
15 pretty_name: Pascal
16 ext: pas
16 ext: pas
17 common_ext: pas
17 common_ext: pas
18
18
19 - Language_4:
19 + Language_ruby:
20 name: ruby
20 name: ruby
21 pretty_name: Ruby
21 pretty_name: Ruby
22 ext: rb
22 ext: rb
23 common_ext: rb
23 common_ext: rb
24
24
25 - Language_5:
25 + Language_python:
26 name: python
26 name: python
27 pretty_name: Python
27 pretty_name: Python
28 ext: py
28 ext: py
29 common_ext: py
29 common_ext: py
30
30
31 - Language_6:
31 + Language_java:
32 name: java
32 name: java
33 pretty_name: Java
33 pretty_name: Java
34 ext: java
34 ext: java
35 common_ext: java
35 common_ext: java
36
36
@@ -1,20 +1,20
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 - one:
2 + prob_add:
3 id: 1
3 id: 1
4 name: add
4 name: add
5 full_name: add_full_name
5 full_name: add_full_name
6 available: true
6 available: true
7
7
8 - two:
8 + prob_sub:
9 id: 2
9 id: 2
10 name: subtract
10 name: subtract
11 full_name: subtract_full_name
11 full_name: subtract_full_name
12 available: false
12 available: false
13
13
14 easy:
14 easy:
15 name: easy_problem
15 name: easy_problem
16 full_name: Easy Problem
16 full_name: Easy Problem
17 available: true
17 available: true
18 contests: contest_a, contest_b
18 contests: contest_a, contest_b
19
19
20 hard:
20 hard:
@@ -1,5 +1,48
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 - one:
2 + add1_by_admin:
3 id: 1
3 id: 1
4 - two:
4 + user: admin
5 + problem: prob_add
6 + language: Language_c
7 + source:
8 + \#include <stdio>
9 + \#include <stdlib>
10 + int main() {
11 + cout << 1 << endl;
12 + }
13 +
14 + sub1_by_admin:
5 id: 2
15 id: 2
16 + user: admin
17 + problem: prob_sub
18 + language: Language_c
19 + source:
20 + \#include <stdio>
21 + \#include <stdlib>
22 + int main() {
23 + cout << 2 << endl;
24 + }
25 +
26 + add1_by_john:
27 + id: 3
28 + user: john
29 + problem: prob_add
30 + language: Language_c
31 + source:
32 + \#include <stdio>
33 + \#include <stdlib>
34 + int main() {
35 + cout << 33 << endl;
36 + }
37 +
38 + sub1_by_james:
39 + id: 4
40 + user: james
41 + problem: prob_sub
42 + language: Language_c
43 + source:
44 + \#include <stdio>
45 + \#include <stdlib>
46 + int main() {
47 + cout << 44 << endl;
48 + }
You need to be logged in to leave comments. Login now