Description:
add submission test
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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 |
@@ -80,12 +80,15 | |||
|
80 | 80 | mini_mime (>= 0.1.3) |
|
81 | 81 | nokogiri (~> 1.8) |
|
82 | 82 | rack (>= 1.6.0) |
|
83 | 83 | rack-test (>= 0.6.3) |
|
84 | 84 | regexp_parser (~> 1.5) |
|
85 | 85 | xpath (~> 3.2) |
|
86 | + capybara-console (0.0.4) | |
|
87 | + capybara | |
|
88 | + rails (>= 3.0) | |
|
86 | 89 | childprocess (1.0.1) |
|
87 | 90 | rake (< 13.0) |
|
88 | 91 | coffee-rails (4.2.2) |
|
89 | 92 | coffee-script (>= 2.2.0) |
|
90 | 93 | railties (>= 4.0.0) |
|
91 | 94 | coffee-script (2.4.1) |
@@ -293,12 +296,13 | |||
|
293 | 296 | bootstrap-sass (~> 3.4.1) |
|
294 | 297 | bootstrap-switch-rails |
|
295 | 298 | bootstrap-toggle-rails |
|
296 | 299 | bootstrap3-datetimepicker-rails |
|
297 | 300 | byebug |
|
298 | 301 | capybara (>= 2.15) |
|
302 | + capybara-console | |
|
299 | 303 | coffee-rails |
|
300 | 304 | dynamic_form |
|
301 | 305 | fuzzy-string-match |
|
302 | 306 | haml |
|
303 | 307 | haml-rails |
|
304 | 308 | in_place_editing |
@@ -43,16 +43,12 | |||
|
43 | 43 | = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission |
|
44 | 44 | .panel-body |
|
45 | 45 | %div#latest_status |
|
46 | 46 | - if @submission |
|
47 | 47 | = render :partial => 'submission_short', |
|
48 | 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 | 50 | - if @submission |
|
55 | 51 | .modal.fade#compiler{tabindex: -1,role: 'dialog'} |
|
56 | 52 | .modal-dialog.modal-lg{role:'document'} |
|
57 | 53 | .modal-content |
|
58 | 54 | .modal-header |
@@ -86,225 +82,6 | |||
|
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 | + Language_c: | |
|
2 | 2 | name: c |
|
3 | 3 | pretty_name: C |
|
4 | 4 | ext: c |
|
5 | 5 | common_ext: c |
|
6 | 6 | |
|
7 |
- Language_ |
|
|
7 | + Language_cpp: | |
|
8 | 8 | name: cpp |
|
9 | 9 | pretty_name: C++ |
|
10 | 10 | ext: cpp |
|
11 | 11 | common_ext: cpp,cc |
|
12 | 12 | |
|
13 |
- Language_ |
|
|
13 | + Language_pas: | |
|
14 | 14 | name: pas |
|
15 | 15 | pretty_name: Pascal |
|
16 | 16 | ext: pas |
|
17 | 17 | common_ext: pas |
|
18 | 18 | |
|
19 |
- Language_ |
|
|
19 | + Language_ruby: | |
|
20 | 20 | name: ruby |
|
21 | 21 | pretty_name: Ruby |
|
22 | 22 | ext: rb |
|
23 | 23 | common_ext: rb |
|
24 | 24 | |
|
25 |
- Language_ |
|
|
25 | + Language_python: | |
|
26 | 26 | name: python |
|
27 | 27 | pretty_name: Python |
|
28 | 28 | ext: py |
|
29 | 29 | common_ext: py |
|
30 | 30 | |
|
31 |
- Language_ |
|
|
31 | + Language_java: | |
|
32 | 32 | name: java |
|
33 | 33 | pretty_name: Java |
|
34 | 34 | ext: java |
|
35 | 35 | common_ext: java |
|
36 | 36 |
@@ -1,14 +1,14 | |||
|
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
|
2 | - one: | |
|
2 | + prob_add: | |
|
3 | 3 | id: 1 |
|
4 | 4 | name: add |
|
5 | 5 | full_name: add_full_name |
|
6 | 6 | available: true |
|
7 | 7 | |
|
8 | - two: | |
|
8 | + prob_sub: | |
|
9 | 9 | id: 2 |
|
10 | 10 | name: subtract |
|
11 | 11 | full_name: subtract_full_name |
|
12 | 12 | available: false |
|
13 | 13 | |
|
14 | 14 | easy: |
@@ -1,5 +1,48 | |||
|
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
|
2 | - one: | |
|
2 | + add1_by_admin: | |
|
3 | 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 | 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