How to use assert_fail method in tox

Best Python code snippet using tox_python

test_ngshare.py

Source:test_ngshare.py Github

copy

Full Screen

...36 if not resp['success']:37 print(repr(resp), file=sys.stderr)38 raise Exception('Not success')39 return resp40def assert_fail(url, data=None, params=None, method=GET, msg=None):41 'Assert requesting a page is failing (with matching message)'42 global user43 if user is not None:44 if method == GET:45 params = params if params is not None else {}46 params['user'] = user47 else:48 data = data if data is not None else {}49 data['user'] = user50 resp = request_page(url, data, params, method)51 if resp['success']:52 print(repr(resp), file=sys.stderr)53 raise Exception('Success')54 if msg is not None:55 assert resp['message'] == msg56 return resp57def test_init():58 'Clear database'59 global user60 user = 'none'61 assert assert_success('/api/initialize-Data6ase')['message'] == 'done'62def test_list_courses():63 'Test GET /api/courses'64 url = '/api/courses'65 global user66 user = 'kevin'67 assert assert_success(url)['courses'] == ['course1']68 user = 'abigail'69 assert assert_success(url)['courses'] == ['course2']70 user = 'lawrence'71 assert assert_success(url)['courses'] == ['course1']72 user = 'eric'73 assert assert_success(url)['courses'] == ['course2']74def test_add_courses():75 'Test GET /api/course/<course_id>'76 url = '/api/course/'77 global user78 user = 'eric'79 assert_success(url + 'course3', method=POST)80 assert_fail(url + 'course3', method=POST, msg='Course already exists')81 assert assert_success('/api/courses')['courses'] == ['course2', 'course3']82def test_list_assignments():83 'Test GET /api/assignments/<course_id>'84 url = '/api/assignments/'85 global user86 user = 'kevin'87 assert_fail(url + 'course2',88 msg='Permission denied (not related to course)')89 user = 'abigail'90 assert assert_success(url + 'course2')['assignments'] == \91 ['assignment2a', 'assignment2b']92 user = 'lawrence'93 assert_fail(url + 'course2',94 msg='Permission denied (not related to course)')95 user = 'eric'96 assert assert_success(url + 'course2')['assignments'] == \97 ['assignment2a', 'assignment2b']98 assert_fail(url + 'jkl', msg='Course not found')99def test_download_assignment():100 'Test GET /api/assignment/<course_id>/<assignment_id>'101 url = '/api/assignment/'102 global user103 user = 'kevin'104 files = assert_success(url + 'course1/challenge')['files']105 assert files[0]['path'] == 'file2'106 assert base64.b64decode(files[0]['content'].encode()) == b'22222'107 assert files[0]['checksum'] == hashlib.md5(b'22222').hexdigest()108 assert_fail(url + 'jkl/challenger', msg='Course not found')109 assert_fail(url + 'course1/challenger', msg='Assignment not found')110 # Check list_only111 files = assert_success(url + 'course1/challenge?list_only=true')['files']112 assert set(files[0]) == {'path', 'checksum'}113 assert files[0]['path'] == 'file2'114 assert files[0]['checksum'] == hashlib.md5(b'22222').hexdigest()115 user = 'eric'116 assert_fail(url + 'course1/challenge',117 msg='Permission denied (not related to course)')118def test_release_assignment():119 'Test POST /api/assignment/<course_id>/<assignment_id>'120 url = '/api/assignment/'121 global user122 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsCg=='},123 {'path': 'b', 'content': 'amtsCg=='}])}124 user = 'kevin'125 assert_fail(url + 'jkl/challenger', method=POST,126 data=data, msg='Course not found')127 assert_fail(url + 'course1/challenger', method=POST,128 msg='Please supply files')129 assert_success(url + 'course1/challenger', method=POST,130 data=data)131 assert_fail(url + 'course1/challenger', method=POST,132 data=data, msg='Assignment already exists')133 data['files'] = json.dumps([{'path': 'a', 'content': 'amtsCg'}])134 assert_fail(url + 'course1/challenges', method=POST,135 data=data, msg='Content cannot be base64 decoded')136 for pathname in ['/a', '/', '', '../etc', 'a/./a.py', 'a/.']:137 data['files'] = json.dumps([{'path': pathname, 'content': ''}])138 assert_fail(url + 'course1/challenges', method=POST,139 data=data, msg='Illegal path')140 user = 'abigail'141 assert_fail(url + 'course1/challenger', method=POST,142 data=data, msg='Permission denied (not course instructor)')143 user = 'lawrence'144 assert_fail(url + 'course1/challenger', method=POST,145 data=data, msg='Permission denied (not course instructor)')146 user = 'eric'147 assert_fail(url + 'course1/challenger', method=POST,148 data=data, msg='Permission denied (not course instructor)')149def test_delete_assignment():150 'Test DELETE /api/assignment/<course_id>/<assignment_id>'151 url = '/api/assignment/'152 global user153 user = 'lawrence'154 assert_fail(url + 'course1/challenger', method=DELETE,155 msg='Permission denied (not course instructor)')156 user = 'kevin'157 assert_fail(url + 'jkl/challenger', method=DELETE, msg='Course not found')158 assert_fail(url + 'course1/challengers', method=DELETE,159 msg='Assignment not found')160 assert_success(url + 'course1/challenger')161 assert_success(url + 'course1/challenger', method=DELETE)162 assert_fail(url + 'course1/challenger', msg='Assignment not found')163def test_list_submissions():164 'Test GET /api/submissions/<course_id>/<assignment_id>'165 url = '/api/submissions/'166 global user167 user = 'kevin'168 assert_fail(url + 'jkl/challenge', msg='Course not found')169 assert_fail(url + 'course1/challenges',170 msg='Assignment not found')171 result = assert_success(url + 'course1/challenge')172 assert len(result['submissions']) == 2173 assert set(result['submissions'][0]) == {'student_id', 'timestamp'}174 assert result['submissions'][0]['student_id'] == 'lawrence'175 assert result['submissions'][1]['student_id'] == 'lawrence'176 user = 'abigail'177 result = assert_success(url + 'course2/assignment2a')178 assert len(result['submissions']) == 0179 user = 'eric'180 assert_fail(url + 'course1/challenges',181 msg='Permission denied (not course instructor)')182 assert_fail(url + 'course2/assignment2a',183 msg='Permission denied (not course instructor)')184def test_list_student_submission():185 'Test GET /api/submissions/<course_id>/<assignment_id>/<student_id>'186 url = '/api/submissions/'187 global user188 user = 'kevin'189 assert_fail(url + 'jkl/challenge/st', msg='Course not found')190 assert_fail(url + 'course1/challenges/st', msg='Assignment not found')191 assert_fail(url + 'course1/challenge/st', msg='Student not found')192 result = assert_success(url + 'course1/challenge/lawrence')193 assert len(result['submissions']) == 2194 assert set(result['submissions'][0]) == {'student_id', 'timestamp'}195 user = 'eric'196 result = assert_success(url + 'course2/assignment2a/eric')197 assert len(result['submissions']) == 0198 user = 'kevin'199 assert_fail(url + 'course2/assignment2a/eric',200 msg='Permission denied (not course instructor)')201 user = 'abigail'202 assert_fail(url + 'course1/challenge/lawrence',203 msg='Permission denied (not course instructor)')204 user = 'lawrence'205 assert_success(url + 'course1/challenge/lawrence')206 user = 'eric'207 assert_fail(url + 'course1/challenge/lawrence',208 msg='Permission denied (not course instructor)')209def test_submit_assignment():210 'Test POST /api/submission/<course_id>/<assignment_id>'211 url = '/api/submission/'212 global user213 user = 'kevin'214 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsCg=='},215 {'path': 'b', 'content': 'amtsCg=='}])}216 assert_fail(url + 'jkl/challenge', method=POST,217 msg='Course not found')218 assert_fail(url + 'course1/challenges', method=POST,219 msg='Assignment not found')220 user = 'lawrence'221 assert_fail(url + 'course1/challenge', method=POST,222 msg='Please supply files')223 resp1 = assert_success(url + 'course1/challenge', method=POST, data=data)224 ts1 = MyHelpers().strptime(resp1['timestamp'])225 data['files'] = json.dumps([{'path': 'a', 'content': 'amtsCg=='}])226 resp2 = assert_success(url + 'course1/challenge', method=POST, data=data)227 ts2 = MyHelpers().strptime(resp2['timestamp'])228 assert ts1 < ts2229 assert ts2 < ts1 + datetime.timedelta(seconds=1)230 data['files'] = json.dumps([{'path': 'a', 'content': 'amtsCg'}])231 assert_fail(url + 'course1/challenge', method=POST,232 data=data, msg='Content cannot be base64 decoded')233 user = 'kevin'234 result = assert_success('/api/submissions/course1/challenge')235 assert len(result['submissions']) == 4 # 2 from init, 2 from this236 user = 'eric'237 assert_fail(url + 'course1/challenge', method=POST,238 msg='Permission denied (not related to course)')239def test_download_submission():240 'Test GET /api/submission/<course_id>/<assignment_id>/<student_id>'241 url = '/api/submission/'242 global user243 user = 'kevin'244 assert_fail(url + 'jkl/challenge/st', msg='Course not found')245 assert_fail(url + 'course1/challenges/st', msg='Assignment not found')246 assert_fail(url + 'course1/challenge/st', msg='Student not found')247 # Test get latest248 result = assert_success(url + 'course1/challenge/lawrence')249 files = result['files']250 assert len(files) == 1251 file_obj = next(filter(lambda x: x['path'] == 'a', files))252 assert base64.b64decode(file_obj['content'].encode()) == b'jkl\n'253 assert file_obj['checksum'] == hashlib.md5(b'jkl\n').hexdigest()254 user = 'abigail'255 assert_fail(url + 'course2/assignment2a/eric', msg='Submission not found')256 # Test get latest with list_only257 user = 'kevin'258 result = assert_success(url + 'course1/challenge/lawrence',259 params={'list_only': 'true'})260 files = result['files']261 assert len(files) == 1262 assert set(files[0]) == {'path', 'checksum'}263 assert files[0]['path'] == 'a'264 assert files[0]['checksum'] == hashlib.md5(b'jkl\n').hexdigest()265 # Test timestamp266 result = assert_success('/api/submissions/course1/challenge/lawrence')267 timestamp = sorted(map(lambda x: x['timestamp'], result['submissions']))[0]268 result = assert_success(url + 'course1/challenge/lawrence',269 {'timestamp': timestamp})270 files = result['files']271 assert len(files) == 1272 file_obj = next(filter(lambda x: x['path'] == 'file3', files))273 assert base64.b64decode(file_obj['content'].encode()) == b'33333'274 assert file_obj['checksum'] == hashlib.md5(b'33333').hexdigest()275 # Test timestamp with list_only276 result = assert_success('/api/submissions/course1/challenge/lawrence')277 timestamp = sorted(map(lambda x: x['timestamp'], result['submissions']))[0]278 result = assert_success(url + 'course1/challenge/lawrence',279 {'timestamp': timestamp, 'list_only': 'true'})280 files = result['files']281 assert len(files) == 1282 file_obj = next(filter(lambda x: x['path'] == 'file3', files))283 assert 'content' not in file_obj284 assert file_obj['checksum'] == hashlib.md5(b'33333').hexdigest()285 # Test timestamp not found286 timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f %Z')287 assert_fail(url + 'course1/challenge/lawrence', {'timestamp': timestamp},288 msg='Submission not found')289 # Test permission290 user = 'eric'291 assert_fail(url + 'course2/assignment2a/eric',292 msg='Permission denied (not course instructor)')293def test_upload_feedback():294 'Test POST /api/feedback/<course_id>/<assignment_id>/<student_id>'295 url = '/api/feedback/'296 global user297 user = 'kevin'298 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsCg=='},299 {'path': 'b', 'content': 'amtsCg=='}]),300 'timestamp': '2020-01-01 00:00:00.000000 '}301 assert_fail(url + 'jkl/challenge/st', method=POST, data=data,302 msg='Course not found')303 assert_fail(url + 'course1/challenges/st', method=POST, data=data,304 msg='Assignment not found')305 assert_fail(url + 'course1/challenge/st', method=POST, data=data,306 msg='Student not found')307 assert_success(url + 'course1/challenge/lawrence', method=POST, data=data)308 data['files'] = json.dumps([{'path': 'c', 'content': 'amtsCf=='}])309 assert_success(url + 'course1/challenge/lawrence', method=POST, data=data)310 assert_fail(url + 'course1/challenge/lawrence', method=POST, data={},311 msg='Please supply timestamp')312 assert_fail(url + 'course1/challenge/lawrence', method=POST,313 data={'timestamp': 'a'}, msg='Time format incorrect')314 user = 'abigail'315 assert_fail(url + 'course2/assignment2a/eric', method=POST, data=data,316 msg='Submission not found')317 assert_fail(url + 'course2/assignment2a/eric', method=POST,318 data={'timestamp': data['timestamp']},319 msg='Submission not found')320 user = 'eric'321 assert_fail(url + 'course2/assignment2a/eric', method=POST, data=data,322 msg='Permission denied (not course instructor)')323def test_download_feedback():324 'Test GET /api/feedback/<course_id>/<assignment_id>/<student_id>'325 url = '/api/feedback/'326 global user327 user = 'kevin'328 assert_fail(url + 'jkl/challenge/st', msg='Course not found')329 assert_fail(url + 'course1/challenges/st', msg='Assignment not found')330 assert_fail(url + 'course1/challenge/st', msg='Student not found')331 meta = assert_success('/api/submission/course1/challenge/lawrence')332 timestamp = meta['timestamp']333 assert_fail(url + 'course1/challenge/lawrence', params={},334 msg='Please supply timestamp')335 assert_fail(url + 'course1/challenge/lawrence', params={'timestamp': 'a'},336 msg='Time format incorrect')337 user = 'eric'338 assert_fail(url + 'course2/assignment2a/eric',339 params={'timestamp': timestamp}, msg='Submission not found')340 user = 'kevin'341 feedback = assert_success(url + 'course1/challenge/lawrence',342 params={'timestamp': timestamp})343 assert feedback['files'] == []344 # Submit again ('amtsDg==' is 'jkl\x0e')345 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsDg=='}]),346 'timestamp': timestamp}347 assert_success(url + 'course1/challenge/lawrence', method=POST, data=data)348 # Fetch again349 feedback = assert_success(url + 'course1/challenge/lawrence',350 params={'timestamp': timestamp})351 assert len(feedback['files']) == 1352 assert feedback['files'][0]['path'] == 'a'353 file_obj = feedback['files'][0]354 assert base64.b64decode(file_obj['content'].encode()) == b'jkl\x0e'355 assert file_obj['checksum'] == hashlib.md5(b'jkl\x0e').hexdigest()356 # Again, submit again ('nmtsDg==' is 'nkl\x0e')357 data = {'files': json.dumps([{'path': 'a', 'content': 'bmtsDg=='}]),358 'timestamp': timestamp}359 assert_success(url + 'course1/challenge/lawrence', method=POST, data=data)360 # Again, fetch again361 feedback = assert_success(url + 'course1/challenge/lawrence',362 params={'timestamp': timestamp})363 assert len(feedback['files']) == 1364 file_obj = feedback['files'][0]365 assert file_obj['path'] == 'a'366 assert base64.b64decode(file_obj['content'].encode()) == b'nkl\x0e'367 assert file_obj['checksum'] == hashlib.md5(b'nkl\x0e').hexdigest()368 # Check list_only369 feedback = assert_success(url + 'course1/challenge/lawrence',370 params={'timestamp': timestamp,371 'list_only': 'true'})372 assert len(feedback['files']) == 1373 assert set(feedback['files'][0]) == {'path', 'checksum'}374 assert file_obj['checksum'] == hashlib.md5(b'nkl\x0e').hexdigest()375 assert feedback['files'][0]['path'] == 'a'376 # Permission check377 user = 'kevin'378 assert_fail(url + 'course1/challenge/lawrence',379 msg='Please supply timestamp')380 user = 'abigail'381 assert_fail(url + 'course1/challenge/lawrence',382 msg='Permission denied (not course instructor)')383 user = 'lawrence'384 assert_fail(url + 'course1/challenge/lawrence',385 msg='Please supply timestamp')386 user = 'eric'387 assert_fail(url + 'course1/challenge/lawrence',...

Full Screen

Full Screen

test_nbgrader.py

Source:test_nbgrader.py Github

copy

Full Screen

...20 if resp['success'] != True :21 print(repr(resp), file=sys.stderr)22 raise Exception('Not success')23 return resp24def assert_fail(url, data={}, params={}, method=GET, msg=None) :25 global user26 if user is not None :27 params = params.copy()28 params['user'] = user29 resp = request_page(url, data, params, method)30 if resp['success'] != False :31 print(repr(resp), file=sys.stderr)32 raise Exception('Success')33 if msg is not None :34 assert resp['message'] == msg35 return resp36# Run init.py before running the test37def test_init() :38 import os, time39 from settings import DB_NAME40 assert DB_NAME.startswith('sqlite:///')41 os.unlink(DB_NAME[len('sqlite:///'):])42 os.system('touch vserver.py')43 time.sleep(2)44def test_list_courses() :45 url = '/api/courses'46 global user47 user = None48 assert_fail(url, msg='Login required (Please supply user)')49 user = 'Nobody'50 assert_fail(url, msg='Login required (User not found)')51 user = 'Kevin'52 assert assert_success(url)['courses'] == ['course1']53 user = 'Abigail'54 assert assert_success(url)['courses'] == ['course2']55 user = 'Lawrence'56 assert assert_success(url)['courses'] == ['course1']57 user = 'Eric'58 assert assert_success(url)['courses'] == ['course2']59def test_add_courses() :60 url = '/api/course/'61 global user62 user = None63 assert_fail(url + 'course3', method=POST,64 msg='Login required (Please supply user)')65 user = 'Erics'66 assert_fail(url + 'course3', method=POST,67 msg='Login required (User not found)')68 user = 'Eric'69 assert_success(url + 'course3', method=POST)70 assert_fail(url + 'course3', method=POST, msg='Course already exists')71 assert assert_success('/api/courses')['courses'] == ['course2', 'course3']72def test_list_assignments() :73 url = '/api/assignments/'74 global user75 user = 'Kevin'76 assert_fail(url + 'course2',77 msg='Permission denied (not related to course)')78 user = 'Abigail'79 assert assert_success(url + 'course2')['assignments'] == \80 ['assignment2a', 'assignment2b']81 user = 'Lawrence'82 assert_fail(url + 'course2',83 msg='Permission denied (not related to course)')84 user = 'Eric'85 assert assert_success(url + 'course2')['assignments'] == \86 ['assignment2a', 'assignment2b']87 assert_fail(url + 'jkl', msg='Course not found')88def test_download_assignment() :89 url = '/api/assignment/'90 global user91 user = 'Kevin'92 files = assert_success(url + 'course1/challenge')['files']93 assert files[0]['path'] == 'file2'94 assert base64.b64decode(files[0]['content'].encode()) == b'22222'95 assert_fail(url + 'jkl/challenger', msg='Course not found')96 assert_fail(url + 'course1/challenger', msg='Assignment not found')97 # Check list_only98 files = assert_success(url + 'course1/challenge?list_only=true')['files']99 assert list(files[0]) == ['path']100 assert files[0]['path'] == 'file2'101 user = 'Eric'102 assert_fail(url + 'course1/challenge',103 msg='Permission denied (not related to course)')104def test_release_assignment() :105 url = '/api/assignment/'106 global user107 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsCg=='},108 {'path': 'b', 'content': 'amtsCg=='}])}109 user = 'Kevin'110 assert_fail(url + 'jkl/challenger', method=POST, 111 data=data, msg='Course not found')112 assert_fail(url + 'course1/challenger', method=POST,113 msg='Please supply files')114 assert_success(url + 'course1/challenger', method=POST, 115 data=data)116 assert_fail(url + 'course1/challenger', method=POST, 117 data=data, msg='Assignment already exists')118 data['files'] = json.dumps([{'path': 'a', 'content': 'amtsCg'}])119 assert_fail(url + 'course1/challenges', method=POST, 120 data=data, msg='Content cannot be base64 decoded')121 for pathname in ['/a', '/', '', '../etc', 'a/./a.py', 'a/.'] :122 data['files'] = json.dumps([{'path': pathname, 'content': ''}])123 assert_fail(url + 'course1/challenges', method=POST, 124 data=data, msg='Illegal path')125 user = 'Abigail'126 assert_fail(url + 'course1/challenger', method=POST, 127 data=data, msg='Permission denied (not course instructor)')128 user = 'Lawrence'129 assert_fail(url + 'course1/challenger', method=POST, 130 data=data, msg='Permission denied (not course instructor)')131 user = 'Eric'132 assert_fail(url + 'course1/challenger', method=POST, 133 data=data, msg='Permission denied (not course instructor)')134def test_list_submissions() :135 url = '/api/submissions/'136 global user137 user = 'Kevin'138 assert_fail(url + 'jkl/challenge', msg='Course not found')139 assert_fail(url + 'course1/challenges',140 msg='Assignment not found')141 result = assert_success(url + 'course1/challenge')142 assert len(result['submissions']) == 2143 assert set(result['submissions'][0]) == {'student_id', 'timestamp'}144 assert result['submissions'][0]['student_id'] == 'Lawrence'145 assert result['submissions'][1]['student_id'] == 'Lawrence'146 user = 'Abigail'147 result = assert_success(url + 'course2/assignment2a')148 assert len(result['submissions']) == 0149 user = 'Eric'150 assert_fail(url + 'course1/challenges',151 msg='Permission denied (not course instructor)')152 assert_fail(url + 'course2/assignment2a',153 msg='Permission denied (not course instructor)')154def test_list_student_submission() :155 url = '/api/submissions/'156 global user157 user = 'Kevin'158 assert_fail(url + 'jkl/challenge/st', msg='Course not found')159 assert_fail(url + 'course1/challenges/st', msg='Assignment not found')160 assert_fail(url + 'course1/challenge/st', msg='Student not found')161 result = assert_success(url + 'course1/challenge/Lawrence')162 assert len(result['submissions']) == 2163 assert set(result['submissions'][0]) == {'student_id', 'timestamp'}164 user = 'Eric'165 result = assert_success(url + 'course2/assignment2a/Eric')166 assert len(result['submissions']) == 0167 user = 'Kevin'168 assert_fail(url + 'course2/assignment2a/Eric',169 msg='Permission denied (not course instructor)')170 user = 'Abigail'171 assert_fail(url + 'course1/challenge/Lawrence',172 msg='Permission denied (not course instructor)')173 user = 'Lawrence'174 assert_success(url + 'course1/challenge/Lawrence')175 user = 'Eric'176 assert_fail(url + 'course1/challenge/Lawrence',177 msg='Permission denied (not course instructor)')178def test_submit_assignment() :179 url = '/api/submission/'180 global user181 user = 'Kevin'182 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsCg=='},183 {'path': 'b', 'content': 'amtsCg=='}])}184 assert_fail(url + 'jkl/challenge', method=POST,185 msg='Course not found')186 assert_fail(url + 'course1/challenges', method=POST,187 msg='Assignment not found')188 user = 'Lawrence'189 assert_fail(url + 'course1/challenge', method=POST,190 msg='Please supply files')191 assert_success(url + 'course1/challenge', method=POST, data=data)192 data['files'] = json.dumps([{'path': 'a', 'content': 'amtsCg=='}])193 assert_success(url + 'course1/challenge',194 method=POST, data=data)195 data['files'] = json.dumps([{'path': 'a', 'content': 'amtsCg'}])196 assert_fail(url + 'course1/challenge', method=POST,197 data=data, msg='Content cannot be base64 decoded')198 user = 'Kevin'199 result = assert_success('/api/submissions/course1/challenge')200 assert len(result['submissions']) == 4 # 2 from init, 2 from this201 user = 'Eric'202 assert_fail(url + 'course1/challenge', method=POST,203 msg='Permission denied (not related to course)')204def test_download_submission() :205 url = '/api/submission/'206 global user207 user = 'Kevin'208 assert_fail(url + 'jkl/challenge/st', msg='Course not found')209 assert_fail(url + 'course1/challenges/st', msg='Assignment not found')210 assert_fail(url + 'course1/challenge/st', msg='Student not found')211 result = assert_success(url + 'course1/challenge/Lawrence')212 assert len(result['files']) == 1213 assert next(filter(lambda x: x['path'] == 'a', result['files'])) \214 ['content'].replace('\n', '') == 'amtsCg=='215 user = 'Abigail'216 assert_fail(url + 'course2/assignment2a/Eric', msg='Submission not found')217 # Check list_only218 user = 'Kevin'219 result = assert_success(220 url + 'course1/challenge/Lawrence?list_only=true')221 assert len(result['files']) == 1222 assert list(result['files'][0]) == ['path']223 assert result['files'][0]['path'] == 'a'224 user = 'Eric'225 assert_fail(url + 'course2/assignment2a/Eric',226 msg='Permission denied (not course instructor)')227def test_upload_feedback() :228 url = '/api/feedback/'229 global user230 user = 'Kevin'231 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsCg=='},232 {'path': 'b', 'content': 'amtsCg=='}]),233 'timestamp': '2020-01-01 00:00:00.000000 '}234 assert_fail(url + 'jkl/challenge/st', method=POST, data=data,235 msg='Course not found')236 assert_fail(url + 'course1/challenges/st', method=POST, data=data,237 msg='Assignment not found')238 assert_fail(url + 'course1/challenge/st', method=POST, data=data,239 msg='Student not found')240 assert_success(url + 'course1/challenge/Lawrence',241 method=POST, data=data)242 data['files'] = json.dumps([{'path': 'c', 'content': 'amtsCf=='}])243 assert_success(url + 'course1/challenge/Lawrence',244 method=POST, data=data)245 assert_fail(url + 'course1/challenge/Lawrence', method=POST, data={},246 msg='Please supply timestamp')247 assert_fail(url + 'course1/challenge/Lawrence', method=POST,248 data={'timestamp': 'a'}, msg='Time format incorrect')249 user = 'Abigail'250 assert_fail(url + 'course2/assignment2a/Eric', method=POST, data=data,251 msg='Submission not found')252 assert_fail(url + 'course2/assignment2a/Eric', method=POST,253 data={'timestamp': data['timestamp']},254 msg='Submission not found')255 user = 'Eric'256 assert_fail(url + 'course2/assignment2a/Eric', method=POST, data=data,257 msg='Permission denied (not course instructor)')258def test_download_feedback() :259 url = '/api/feedback/'260 global user261 user = 'Kevin'262 assert_fail(url + 'jkl/challenge/st', msg='Course not found')263 assert_fail(url + 'course1/challenges/st', msg='Assignment not found')264 assert_fail(url + 'course1/challenge/st', msg='Student not found')265 meta = assert_success('/api/submission/course1/challenge/Lawrence')266 timestamp = meta['timestamp']267 assert_fail(url + 'course1/challenge/Lawrence', params={},268 msg='Please supply timestamp')269 assert_fail(url + 'course1/challenge/Lawrence', params={'timestamp': 'a'},270 msg='Time format incorrect')271 user = 'Eric'272 assert_fail(url + 'course2/assignment2a/Eric',273 params={'timestamp': timestamp}, msg='Submission not found')274 user = 'Kevin'275 feedback = assert_success(url + 'course1/challenge/Lawrence', 276 params={'timestamp': timestamp})277 assert feedback['files'] == []278 # Submit again279 data = {'files': json.dumps([{'path': 'a', 'content': 'amtsDg=='}]),280 'timestamp': timestamp}281 assert_success(url + 'course1/challenge/Lawrence', method=POST, data=data)282 # Fetch again283 feedback = assert_success(url + 'course1/challenge/Lawrence', 284 params={'timestamp': timestamp})285 assert len(feedback['files']) == 1286 assert feedback['files'][0]['path'] == 'a'287 assert feedback['files'][0]['content'].replace('\n', '') == 'amtsDg=='288 # Again, submit again289 data = {'files': json.dumps([{'path': 'a', 'content': 'bmtsDg=='}]),290 'timestamp': timestamp}291 assert_success(url + 'course1/challenge/Lawrence', method=POST, data=data)292 # Again, fetch again293 feedback = assert_success(url + 'course1/challenge/Lawrence',294 params={'timestamp': timestamp})295 assert len(feedback['files']) == 1296 assert feedback['files'][0]['path'] == 'a'297 assert feedback['files'][0]['content'].replace('\n', '') == 'bmtsDg=='298 # Check list_only299 feedback = assert_success(url + 'course1/challenge/Lawrence',300 params={'timestamp': timestamp,301 'list_only': 'true'})302 assert len(feedback['files']) == 1303 assert list(feedback['files'][0]) == ['path']304 assert feedback['files'][0]['path'] == 'a'305 # Permission check306 user = 'Kevin'307 assert_fail(url + 'course1/challenge/Lawrence',308 msg='Please supply timestamp')309 user = 'Abigail'310 assert_fail(url + 'course1/challenge/Lawrence',311 msg='Permission denied (not course instructor)')312 user = 'Lawrence'313 assert_fail(url + 'course1/challenge/Lawrence',314 msg='Please supply timestamp')315 user = 'Eric'316 assert_fail(url + 'course1/challenge/Lawrence',...

Full Screen

Full Screen

rfc3696.py

Source:rfc3696.py Github

copy

Full Screen

...38 def test_dns_name_matcher(self):39 40 name = _PreferredFullyQualifiedDnsName() & Eos()41 42 self.assert_fail('', name)43 self.assert_fail('a', name)44 self.assert_fail('12.34', name)45 self.assert_fail('a.b.', name)46 self.assert_fail(' a.b', name)47 self.assert_fail('a.b ', name)48 self.assert_fail('a._.', name)49 self.assert_fail('a.-b.c', name)50 self.assert_fail('a.b-.c', name)51 self.assert_fail('a.b.c.123', name)52 53 self.assert_literal('a.b.123.c', name)54 self.assert_literal('a.b-c.d', name)55 self.assert_literal('a.b--c.d', name)56 self.assert_literal('acooke.org', name)57 self.assert_literal('EXAMPLE.COM', name)58 self.assert_literal('example.a23', name)59 self.assert_literal('example.12c', name)60 61 62class IpV4AddressTest(BaseTest):63 64 def test_ipv4_address(self):65 66 address = _IpV4Address() & Eos()67 68 self.assert_literal('1.2.3.4', address)69 self.assert_literal('255.255.255.255', address)70 self.assert_literal('0.0.0.0', address)71 72 self.assert_fail('1.2.3', address)73 self.assert_fail('1.2.3.', address)74 self.assert_fail('1.256.3.4', address)75 self.assert_fail('1.a.3.4', address)76 self.assert_fail('1.-1.3.4', address)77 78 79class IpV6AddressTest(BaseTest):80 81 def test_ipv6_address(self):82 83 address = _Ipv6Address() & Eos()84 85 self.assert_literal('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', address)86 self.assert_literal('1080:0:0:0:8:800:200C:417A', address)87 self.assert_literal('FF01:0:0:0:0:0:0:101', address)88 self.assert_literal('0:0:0:0:0:0:0:1', address)89 self.assert_literal('0:0:0:0:0:0:0:0', address)90 self.assert_literal('1080::8:800:200C:417A', address)91 self.assert_literal('FF01::101', address)92 self.assert_literal('::1', address)93 self.assert_literal('::', address)94 self.assert_literal('0:0:0:0:0:0:13.1.68.3', address)95 self.assert_literal('0:0:0:0:0:FFFF:129.144.52.38', address)96 self.assert_literal('::13.1.68.3', address)97 self.assert_literal('::FFFF:129.144.52.38', address)98 99 self.assert_fail('1:2:3:4:5:6:7', address)100 self.assert_fail('1:2:3:4:5:6:7:8:9', address)101 self.assert_fail('::1:2:3:4:5:6:7:8', address)102 self.assert_fail(':1::2:3:4:5:6:7:8', address)103 self.assert_fail(':1:2:3:4:5:6:7:8::', address)104 self.assert_fail('1:2:3:4:5:1.2.3.4', address)105 self.assert_fail('1:2:3:4:5.6.7:1.2.3.4', address)106 self.assert_fail('::1:2:3:4:5:6:1.2.3.4', address)107 self.assert_fail('1::2:3:4:5:6:1.2.3.4', address)108 self.assert_fail('1:2:3:4:5:6::1.2.3.4', address)109class _EmailLocalPartTest(BaseTest):110 111 def test_email_local_part_matcher(self):112 113 local = _EmailLocalPart() & Eos()114 115 self.assert_fail('', local)116 self.assert_fail('""', local)117 self.assert_fail('"unmatched', local)118 self.assert_fail('unmatched"', local)119 self.assert_fail(' ', local)120 self.assert_fail('a b', local)121 122 self.assert_literal(r'andrew', local)123 self.assert_literal(r'Abc\@def', local)124 self.assert_literal(r'Fred\ Bloggs', local)125 self.assert_literal(r'Joe.\\Blow', local)126 self.assert_literal(r'"Abc@def"', local)127 self.assert_literal(r'"Fred Bloggs"', local)128 self.assert_literal(r'user+mailbox', local)129 self.assert_literal(r'customer/department=shipping', local)130 self.assert_literal(r'$A12345', local)131 self.assert_literal(r'!def!xyz%abc', local)132 self.assert_literal(r'_somename', local)133class _EmailTest(BaseTest):134 135 def test_email_matcher(self):136 137 email = _Email() & Eos()138 139 self.assert_literal(r'andrew@acooke.org', email)140 self.assert_literal(r'Abc\@def@example.com', email)141 self.assert_literal(r'Fred\ Bloggs@example.com', email)142 self.assert_literal(r'Joe.\\Blow@example.com', email)143 self.assert_literal(r'"Abc@def"@example.com', email)144 self.assert_literal(r'"Fred Bloggs"@example.com', email)145 self.assert_literal(r'user+mailbox@example.com', email)146 self.assert_literal(r'customer/department=shipping@example.com', email)147 self.assert_literal(r'$A12345@example.com', email)148 self.assert_literal(r'!def!xyz%abc@example.com', email)149 self.assert_literal(r'_somename@example.com', email)150 151 def test_email(self):152 153 email = Email()154 155 assert email(r'andrew@acooke.org',)156 assert email(r'Abc\@def@example.com',)157 assert email(r'Fred\ Bloggs@example.com',)158 assert email(r'Joe.\\Blow@example.com',)159 assert email(r'"Abc@def"@example.com',)160 assert email(r'"Fred Bloggs"@example.com',)161 assert email(r'user+mailbox@example.com',)162 assert email(r'customer/department=shipping@example.com',)163 assert email(r'$A12345@example.com',)164 assert email(r'!def!xyz%abc@example.com',)165 assert email(r'_somename@example.com',)166 167 addresses = ['', 'a', '12.34', 'a.b.', ' a.b', 'a.b ', 'a._.', 168 'a.-b.c', 'a.b-.c', 'a.b.c.123']169 names = ['', '""', '"unmatched', 'unmatched"', ' ', 'a b']170 for name in names:171 for address in addresses:172 bad = name + '@' + address173 assert not email(bad), bad174 175class HttpUrlTest(BaseTest):176 177 def test_http_matcher(self):178 #basicConfig(level=DEBUG)179 180 http = _HttpUrl() & Eos()181 http.config.compile_to_re()182 #print(http.get_parse().matcher.tree())183 184 self.assert_literal(r'http://www.acooke.org', http)185 self.assert_literal(r'http://www.acooke.org/', http)186 self.assert_literal(r'http://www.acooke.org:80', http)187 self.assert_literal(r'http://www.acooke.org:80/', http)188 self.assert_literal(r'http://www.acooke.org/andrew', http)189 self.assert_literal(r'http://www.acooke.org:80/andrew', http)190 self.assert_literal(r'http://www.acooke.org/andrew/', http)191 self.assert_literal(r'http://www.acooke.org:80/andrew/', http)192 self.assert_literal(r'http://www.acooke.org/?foo', http)193 self.assert_literal(r'http://www.acooke.org:80/?foo', http)194 self.assert_literal(r'http://www.acooke.org/#bar', http)195 self.assert_literal(r'http://www.acooke.org:80/#bar', http)196 self.assert_literal(r'http://www.acooke.org/andrew?foo', http)197 self.assert_literal(r'http://www.acooke.org:80/andrew?foo', http)198 self.assert_literal(r'http://www.acooke.org/andrew/?foo', http)199 self.assert_literal(r'http://www.acooke.org:80/andrew/?foo', http)200 self.assert_literal(r'http://www.acooke.org/andrew#bar', http)201 self.assert_literal(r'http://www.acooke.org:80/andrew#bar', http)202 self.assert_literal(r'http://www.acooke.org/andrew/#bar', http)203 self.assert_literal(r'http://www.acooke.org:80/andrew/#bar', http)204 self.assert_literal(r'http://www.acooke.org/andrew?foo#bar', http)205 self.assert_literal(r'http://www.acooke.org:80/andrew?foo#bar', http)206 self.assert_literal(r'http://www.acooke.org/andrew/?foo#bar', http)207 self.assert_literal(r'http://www.acooke.org:80/andrew/?foo#bar', http)208 209 self.assert_fail(r'http://www.acooke.org:80/andrew/?foo#bar ', http)210 self.assert_fail(r'http://www.acooke.org:80/andrew/?foo#bar baz', http)211 212 def test_http(self):213 214 httpUrl = HttpUrl()215 216 assert httpUrl(r'http://www.acooke.org')217 assert httpUrl(r'http://www.acooke.org/')218 assert httpUrl(r'http://www.acooke.org:80')219 assert httpUrl(r'http://www.acooke.org:80/')220 assert httpUrl(r'http://www.acooke.org/andrew')221 assert httpUrl(r'http://www.acooke.org:80/andrew')222 assert httpUrl(r'http://www.acooke.org/andrew/')223 assert httpUrl(r'http://www.acooke.org:80/andrew/')224 assert httpUrl(r'http://www.acooke.org/?foo')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful