How to use ok_ method in Nose

Best Python code snippet using nose

test_basic.py

Source:test_basic.py Github

copy

Full Screen

...89 eq_(view.model, Model1)90 eq_(view.name, 'Model1')91 eq_(view.endpoint, 'model1')92 eq_(view._primary_key, 'id')93 ok_('test1' in view._sortable_columns)94 ok_('test2' in view._sortable_columns)95 ok_('test3' in view._sortable_columns)96 ok_('test4' in view._sortable_columns)97 ok_(view._create_form_class is not None)98 ok_(view._edit_form_class is not None)99 eq_(view._search_supported, False)100 eq_(view._filters, None)101 # Verify form102 eq_(view._create_form_class.test1.field_class, fields.StringField)103 eq_(view._create_form_class.test2.field_class, fields.StringField)104 eq_(view._create_form_class.test3.field_class, fields.TextAreaField)105 eq_(view._create_form_class.test4.field_class, fields.TextAreaField)106 # Make some test clients107 client = app.test_client()108 rv = client.get('/admin/model1/')109 eq_(rv.status_code, 200)110 rv = client.get('/admin/model1/new/')111 eq_(rv.status_code, 200)112 rv = client.post('/admin/model1/new/',113 data=dict(test1='test1large', test2='test2'))114 eq_(rv.status_code, 302)115 model = Model1.select().get()116 eq_(model.test1, 'test1large')117 eq_(model.test2, 'test2')118 ok_(model.test3 is None or model.test3 == '')119 ok_(model.test4 is None or model.test4 == '')120 rv = client.get('/admin/model1/')121 eq_(rv.status_code, 200)122 ok_('test1large' in rv.data)123 url = '/admin/model1/edit/?id=%s' % model.id124 rv = client.get(url)125 eq_(rv.status_code, 200)126 rv = client.post(url,127 data=dict(test1='test1small', test2='test2large'))128 eq_(rv.status_code, 302)129 model = Model1.select().get()130 eq_(model.test1, 'test1small')131 eq_(model.test2, 'test2large')132 ok_(model.test3 is None or model.test3 == '')133 ok_(model.test4 is None or model.test4 == '')134 url = '/admin/model1/delete/?id=%s' % model.id135 rv = client.post(url)136 eq_(rv.status_code, 302)137 eq_(Model1.select().count(), 0)138def test_column_editable_list():139 app, db, admin = setup()140 Model1, Model2 = create_models(db)141 # wtf-peewee doesn't automatically add length validators for max_length142 form_args = {'test1': {'validators': [validators.Length(max=20)]}}143 view = CustomModelView(Model1, column_editable_list=['test1'],144 form_args=form_args)145 admin.add_view(view)146 fill_db(Model1, Model2)147 client = app.test_client()148 # Test in-line edit field rendering149 rv = client.get('/admin/model1/')150 data = rv.data.decode('utf-8')151 ok_('data-role="x-editable"' in data)152 # Form - Test basic in-line edit functionality153 rv = client.post('/admin/model1/ajax/update/', data={154 'list_form_pk': '1',155 'test1': 'change-success-1',156 })157 data = rv.data.decode('utf-8')158 ok_('Record was successfully saved.' == data)159 # ensure the value has changed160 rv = client.get('/admin/model1/')161 data = rv.data.decode('utf-8')162 ok_('change-success-1' in data)163 # Test validation error164 rv = client.post('/admin/model1/ajax/update/', data={165 'list_form_pk': '1',166 'test1': ('longerthantwentycharacterslongerthantwentycharacterslonger'167 'thantwentycharacterslongerthantwentycharacters'),168 })169 data = rv.data.decode('utf-8')170 eq_(rv.status_code, 500)171 # Test invalid primary key172 rv = client.post('/admin/model1/ajax/update/', data={173 'list_form_pk': '1000',174 'test1': 'problematic-input',175 })176 data = rv.data.decode('utf-8')177 eq_(rv.status_code, 500)178 # Test editing column not in column_editable_list179 rv = client.post('/admin/model1/ajax/update/', data={180 'list_form_pk': '1',181 'test2': 'problematic-input',182 })183 data = rv.data.decode('utf-8')184 ok_('problematic-input' not in data)185 # Test in-line editing for relations186 view = CustomModelView(Model2, column_editable_list=['model1'])187 admin.add_view(view)188 rv = client.post('/admin/model2/ajax/update/', data={189 'list_form_pk': '1',190 'model1': '3',191 })192 data = rv.data.decode('utf-8')193 ok_('Record was successfully saved.' == data)194 # confirm the value has changed195 rv = client.get('/admin/model2/')196 data = rv.data.decode('utf-8')197 ok_('test1_val_3' in data)198def test_details_view():199 app, db, admin = setup()200 Model1, Model2 = create_models(db)201 view_no_details = CustomModelView(Model1)202 admin.add_view(view_no_details)203 # fields are scaffolded204 view_w_details = CustomModelView(Model2, can_view_details=True)205 admin.add_view(view_w_details)206 # show only specific fields in details w/ column_details_list207 char_field_view = CustomModelView(Model2, can_view_details=True,208 column_details_list=["char_field"],209 endpoint="cf_view")210 admin.add_view(char_field_view)211 fill_db(Model1, Model2)212 client = app.test_client()213 # ensure link to details is hidden when can_view_details is disabled214 rv = client.get('/admin/model1/')215 data = rv.data.decode('utf-8')216 ok_('/admin/model1/details/' not in data)217 # ensure link to details view appears218 rv = client.get('/admin/model2/')219 data = rv.data.decode('utf-8')220 ok_('/admin/model2/details/' in data)221 # test redirection when details are disabled222 rv = client.get('/admin/model1/details/?url=%2Fadmin%2Fmodel1%2F&id=3')223 eq_(rv.status_code, 302)224 # test if correct data appears in details view when enabled225 rv = client.get('/admin/model2/details/?url=%2Fadmin%2Fmodel2%2F&id=3')226 data = rv.data.decode('utf-8')227 ok_('Char Field' in data)228 ok_('char_field_val_3' in data)229 ok_('Int Field' in data)230 ok_('5000' in data)231 # test column_details_list232 rv = client.get('/admin/cf_view/details/?url=%2Fadmin%2Fcf_view%2F&id=3')233 data = rv.data.decode('utf-8')234 ok_('Char Field' in data)235 ok_('char_field_val_3' in data)236 ok_('Int Field' not in data)237 ok_('5000' not in data)238def test_column_filters():239 app, db, admin = setup()240 Model1, Model2 = create_models(db)241 fill_db(Model1, Model2)242 # Test string filter243 view = CustomModelView(Model1, column_filters=['test1'])244 admin.add_view(view)245 eq_(len(view._filters), 7)246 eq_(247 [(f['index'], f['operation']) for f in view._filter_groups[u'Test1']],248 [249 (0, 'contains'),250 (1, 'not contains'),251 (2, 'equals'),252 (3, 'not equal'),253 (4, 'empty'),254 (5, 'in list'),255 (6, 'not in list'),256 ]257 )258 # Make some test clients259 client = app.test_client()260 # string - equals261 rv = client.get('/admin/model1/?flt0_0=test1_val_1')262 eq_(rv.status_code, 200)263 data = rv.data.decode('utf-8')264 ok_('test2_val_1' in data)265 ok_('test1_val_2' not in data)266 # string - not equal267 rv = client.get('/admin/model1/?flt0_1=test1_val_1')268 eq_(rv.status_code, 200)269 data = rv.data.decode('utf-8')270 ok_('test2_val_1' not in data)271 ok_('test1_val_2' in data)272 # string - contains273 rv = client.get('/admin/model1/?flt0_2=test1_val_1')274 eq_(rv.status_code, 200)275 data = rv.data.decode('utf-8')276 ok_('test2_val_1' in data)277 ok_('test1_val_2' not in data)278 # string - not contains279 rv = client.get('/admin/model1/?flt0_3=test1_val_1')280 eq_(rv.status_code, 200)281 data = rv.data.decode('utf-8')282 ok_('test2_val_1' not in data)283 ok_('test1_val_2' in data)284 # string - empty285 rv = client.get('/admin/model1/?flt0_4=1')286 eq_(rv.status_code, 200)287 data = rv.data.decode('utf-8')288 ok_('empty_obj' in data)289 ok_('test1_val_1' not in data)290 ok_('test1_val_2' not in data)291 # string - not empty292 rv = client.get('/admin/model1/?flt0_4=0')293 eq_(rv.status_code, 200)294 data = rv.data.decode('utf-8')295 ok_('empty_obj' not in data)296 ok_('test1_val_1' in data)297 ok_('test1_val_2' in data)298 # string - in list299 rv = client.get('/admin/model1/?flt0_5=test1_val_1%2Ctest1_val_2')300 eq_(rv.status_code, 200)301 data = rv.data.decode('utf-8')302 ok_('test2_val_1' in data)303 ok_('test2_val_2' in data)304 ok_('test1_val_3' not in data)305 ok_('test1_val_4' not in data)306 # string - not in list307 rv = client.get('/admin/model1/?flt0_6=test1_val_1%2Ctest1_val_2')308 eq_(rv.status_code, 200)309 data = rv.data.decode('utf-8')310 ok_('test2_val_1' not in data)311 ok_('test2_val_2' not in data)312 ok_('test1_val_3' in data)313 ok_('test1_val_4' in data)314 # Test int filter315 view = CustomModelView(Model2, column_filters=['int_field'])316 admin.add_view(view)317 eq_(318 [(f['index'], f['operation']) for f in view._filter_groups[u'Int Field']],319 [320 (0, 'equals'),321 (1, 'not equal'),322 (2, 'greater than'),323 (3, 'smaller than'),324 (4, 'empty'),325 (5, 'in list'),326 (6, 'not in list'),327 ]328 )329 # integer - equals330 rv = client.get('/admin/model2/?flt0_0=5000')331 eq_(rv.status_code, 200)332 data = rv.data.decode('utf-8')333 ok_('char_field_val_3' in data)334 ok_('char_field_val_4' not in data)335 # integer - equals (huge number)336 rv = client.get('/admin/model2/?flt0_0=6169453081680413441')337 eq_(rv.status_code, 200)338 data = rv.data.decode('utf-8')339 ok_('char_field_val_5' in data)340 ok_('char_field_val_4' not in data)341 # integer - equals - test validation342 rv = client.get('/admin/model2/?flt0_0=badval')343 eq_(rv.status_code, 200)344 data = rv.data.decode('utf-8')345 ok_('Invalid Filter Value' in data)346 # integer - not equal347 rv = client.get('/admin/model2/?flt0_1=5000')348 eq_(rv.status_code, 200)349 data = rv.data.decode('utf-8')350 ok_('char_field_val_3' not in data)351 ok_('char_field_val_4' in data)352 # integer - greater353 rv = client.get('/admin/model2/?flt0_2=6000')354 eq_(rv.status_code, 200)355 data = rv.data.decode('utf-8')356 ok_('char_field_val_3' not in data)357 ok_('char_field_val_4' in data)358 # integer - smaller359 rv = client.get('/admin/model2/?flt0_3=6000')360 eq_(rv.status_code, 200)361 data = rv.data.decode('utf-8')362 ok_('char_field_val_3' in data)363 ok_('char_field_val_4' not in data)364 # integer - empty365 rv = client.get('/admin/model2/?flt0_4=1')366 eq_(rv.status_code, 200)367 data = rv.data.decode('utf-8')368 ok_('char_field_val_1' in data)369 ok_('char_field_val_2' in data)370 ok_('char_field_val_3' not in data)371 ok_('char_field_val_4' not in data)372 # integer - not empty373 rv = client.get('/admin/model2/?flt0_4=0')374 eq_(rv.status_code, 200)375 data = rv.data.decode('utf-8')376 ok_('char_field_val_1' not in data)377 ok_('char_field_val_2' not in data)378 ok_('char_field_val_3' in data)379 ok_('char_field_val_4' in data)380 # integer - in list381 rv = client.get('/admin/model2/?flt0_5=5000%2C9000')382 eq_(rv.status_code, 200)383 data = rv.data.decode('utf-8')384 ok_('char_field_val_1' not in data)385 ok_('char_field_val_2' not in data)386 ok_('char_field_val_3' in data)387 ok_('char_field_val_4' in data)388 # integer - in list (huge number)389 rv = client.get('/admin/model2/?flt0_5=6169453081680413441')390 eq_(rv.status_code, 200)391 data = rv.data.decode('utf-8')392 ok_('char_field_val_1' not in data)393 ok_('char_field_val_5' in data)394 # integer - in list - test validation395 rv = client.get('/admin/model2/?flt0_5=5000%2Cbadval')396 eq_(rv.status_code, 200)397 data = rv.data.decode('utf-8')398 ok_('Invalid Filter Value' in data)399 # integer - not in list400 rv = client.get('/admin/model2/?flt0_6=5000%2C9000')401 eq_(rv.status_code, 200)402 data = rv.data.decode('utf-8')403 ok_('char_field_val_1' in data)404 ok_('char_field_val_2' in data)405 ok_('char_field_val_3' not in data)406 ok_('char_field_val_4' not in data)407 # Test boolean filter408 view = CustomModelView(Model2, column_filters=['bool_field'],409 endpoint="_bools")410 admin.add_view(view)411 eq_(412 [(f['index'], f['operation']) for f in view._filter_groups[u'Bool Field']],413 [414 (0, 'equals'),415 (1, 'not equal'),416 ]417 )418 # boolean - equals - Yes419 rv = client.get('/admin/_bools/?flt0_0=1')420 eq_(rv.status_code, 200)421 data = rv.data.decode('utf-8')422 ok_('char_field_val_1' in data)423 ok_('char_field_val_2' not in data)424 ok_('char_field_val_3' not in data)425 # boolean - equals - No426 rv = client.get('/admin/_bools/?flt0_0=0')427 eq_(rv.status_code, 200)428 data = rv.data.decode('utf-8')429 ok_('char_field_val_1' not in data)430 ok_('char_field_val_2' in data)431 ok_('char_field_val_3' in data)432 # boolean - not equals - Yes433 rv = client.get('/admin/_bools/?flt0_1=1')434 eq_(rv.status_code, 200)435 data = rv.data.decode('utf-8')436 ok_('char_field_val_1' not in data)437 ok_('char_field_val_2' in data)438 ok_('char_field_val_3' in data)439 # boolean - not equals - No440 rv = client.get('/admin/_bools/?flt0_1=0')441 eq_(rv.status_code, 200)442 data = rv.data.decode('utf-8')443 ok_('char_field_val_1' in data)444 ok_('char_field_val_2' not in data)445 ok_('char_field_val_3' not in data)446 # Test float filter447 view = CustomModelView(Model2, column_filters=['float_field'],448 endpoint="_float")449 admin.add_view(view)450 eq_(451 [(f['index'], f['operation']) for f in view._filter_groups[u'Float Field']],452 [453 (0, 'equals'),454 (1, 'not equal'),455 (2, 'greater than'),456 (3, 'smaller than'),457 (4, 'empty'),458 (5, 'in list'),459 (6, 'not in list'),460 ]461 )462 # float - equals463 rv = client.get('/admin/_float/?flt0_0=25.9')464 eq_(rv.status_code, 200)465 data = rv.data.decode('utf-8')466 ok_('char_field_val_3' in data)467 ok_('char_field_val_4' not in data)468 # float - equals - test validation469 rv = client.get('/admin/_float/?flt0_0=badval')470 eq_(rv.status_code, 200)471 data = rv.data.decode('utf-8')472 ok_('Invalid Filter Value' in data)473 # float - not equal474 rv = client.get('/admin/_float/?flt0_1=25.9')475 eq_(rv.status_code, 200)476 data = rv.data.decode('utf-8')477 ok_('char_field_val_3' not in data)478 ok_('char_field_val_4' in data)479 # float - greater480 rv = client.get('/admin/_float/?flt0_2=60.5')481 eq_(rv.status_code, 200)482 data = rv.data.decode('utf-8')483 ok_('char_field_val_3' not in data)484 ok_('char_field_val_4' in data)485 # float - smaller486 rv = client.get('/admin/_float/?flt0_3=60.5')487 eq_(rv.status_code, 200)488 data = rv.data.decode('utf-8')489 ok_('char_field_val_3' in data)490 ok_('char_field_val_4' not in data)491 # float - empty492 rv = client.get('/admin/_float/?flt0_4=1')493 eq_(rv.status_code, 200)494 data = rv.data.decode('utf-8')495 ok_('char_field_val_1' in data)496 ok_('char_field_val_2' in data)497 ok_('char_field_val_3' not in data)498 ok_('char_field_val_4' not in data)499 # float - not empty500 rv = client.get('/admin/_float/?flt0_4=0')501 eq_(rv.status_code, 200)502 data = rv.data.decode('utf-8')503 ok_('char_field_val_1' not in data)504 ok_('char_field_val_2' not in data)505 ok_('char_field_val_3' in data)506 ok_('char_field_val_4' in data)507 # float - in list508 rv = client.get('/admin/_float/?flt0_5=25.9%2C75.5')509 eq_(rv.status_code, 200)510 data = rv.data.decode('utf-8')511 ok_('char_field_val_1' not in data)512 ok_('char_field_val_2' not in data)513 ok_('char_field_val_3' in data)514 ok_('char_field_val_4' in data)515 # float - in list - test validation516 rv = client.get('/admin/_float/?flt0_5=25.9%2Cbadval')517 eq_(rv.status_code, 200)518 data = rv.data.decode('utf-8')519 ok_('Invalid Filter Value' in data)520 # float - not in list521 rv = client.get('/admin/_float/?flt0_6=25.9%2C75.5')522 eq_(rv.status_code, 200)523 data = rv.data.decode('utf-8')524 ok_('char_field_val_1' in data)525 ok_('char_field_val_2' in data)526 ok_('char_field_val_3' not in data)527 ok_('char_field_val_4' not in data)528 # Test date, time, and datetime filters529 view = CustomModelView(Model1,530 column_filters=['date_field', 'datetime_field', 'timeonly_field'],531 endpoint="_datetime")532 admin.add_view(view)533 eq_(534 [(f['index'], f['operation']) for f in view._filter_groups[u'Date Field']],535 [536 (0, 'equals'),537 (1, 'not equal'),538 (2, 'greater than'),539 (3, 'smaller than'),540 (4, 'between'),541 (5, 'not between'),542 (6, 'empty'),543 ]544 )545 eq_(546 [(f['index'], f['operation']) for f in view._filter_groups[u'Datetime Field']],547 [548 (7, 'equals'),549 (8, 'not equal'),550 (9, 'greater than'),551 (10, 'smaller than'),552 (11, 'between'),553 (12, 'not between'),554 (13, 'empty'),555 ]556 )557 eq_(558 [(f['index'], f['operation']) for f in view._filter_groups[u'Timeonly Field']],559 [560 (14, 'equals'),561 (15, 'not equal'),562 (16, 'greater than'),563 (17, 'smaller than'),564 (18, 'between'),565 (19, 'not between'),566 (20, 'empty'),567 ]568 )569 # date - equals570 rv = client.get('/admin/_datetime/?flt0_0=2014-11-17')571 eq_(rv.status_code, 200)572 data = rv.data.decode('utf-8')573 ok_('date_obj1' in data)574 ok_('date_obj2' not in data)575 # date - not equal576 rv = client.get('/admin/_datetime/?flt0_1=2014-11-17')577 eq_(rv.status_code, 200)578 data = rv.data.decode('utf-8')579 ok_('date_obj1' not in data)580 ok_('date_obj2' in data)581 # date - greater582 rv = client.get('/admin/_datetime/?flt0_2=2014-11-16')583 eq_(rv.status_code, 200)584 data = rv.data.decode('utf-8')585 ok_('date_obj1' in data)586 ok_('date_obj2' not in data)587 # date - smaller588 rv = client.get('/admin/_datetime/?flt0_3=2014-11-16')589 eq_(rv.status_code, 200)590 data = rv.data.decode('utf-8')591 ok_('date_obj1' not in data)592 ok_('date_obj2' in data)593 # date - between594 rv = client.get('/admin/_datetime/?flt0_4=2014-11-13+to+2014-11-20')595 eq_(rv.status_code, 200)596 data = rv.data.decode('utf-8')597 ok_('date_obj1' in data)598 ok_('date_obj2' not in data)599 # date - not between600 rv = client.get('/admin/_datetime/?flt0_5=2014-11-13+to+2014-11-20')601 eq_(rv.status_code, 200)602 data = rv.data.decode('utf-8')603 ok_('date_obj1' not in data)604 ok_('date_obj2' in data)605 # date - empty606 rv = client.get('/admin/_datetime/?flt0_6=1')607 eq_(rv.status_code, 200)608 data = rv.data.decode('utf-8')609 ok_('test1_val_1' in data)610 ok_('date_obj1' not in data)611 ok_('date_obj2' not in data)612 # date - empty613 rv = client.get('/admin/_datetime/?flt0_6=0')614 eq_(rv.status_code, 200)615 data = rv.data.decode('utf-8')616 ok_('test1_val_1' not in data)617 ok_('date_obj1' in data)618 ok_('date_obj2' in data)619 # datetime - equals620 rv = client.get('/admin/_datetime/?flt0_7=2014-04-03+01%3A09%3A00')621 eq_(rv.status_code, 200)622 data = rv.data.decode('utf-8')623 ok_('datetime_obj1' in data)624 ok_('datetime_obj2' not in data)625 # datetime - not equal626 rv = client.get('/admin/_datetime/?flt0_8=2014-04-03+01%3A09%3A00')627 eq_(rv.status_code, 200)628 data = rv.data.decode('utf-8')629 ok_('datetime_obj1' not in data)630 ok_('datetime_obj2' in data)631 # datetime - greater632 rv = client.get('/admin/_datetime/?flt0_9=2014-04-03+01%3A08%3A00')633 eq_(rv.status_code, 200)634 data = rv.data.decode('utf-8')635 ok_('datetime_obj1' in data)636 ok_('datetime_obj2' not in data)637 # datetime - smaller638 rv = client.get('/admin/_datetime/?flt0_10=2014-04-03+01%3A08%3A00')639 eq_(rv.status_code, 200)640 data = rv.data.decode('utf-8')641 ok_('datetime_obj1' not in data)642 ok_('datetime_obj2' in data)643 # datetime - between644 rv = client.get('/admin/_datetime/?flt0_11=2014-04-02+00%3A00%3A00+to+2014-11-20+23%3A59%3A59')645 eq_(rv.status_code, 200)646 data = rv.data.decode('utf-8')647 ok_('datetime_obj1' in data)648 ok_('datetime_obj2' not in data)649 # datetime - not between650 rv = client.get('/admin/_datetime/?flt0_12=2014-04-02+00%3A00%3A00+to+2014-11-20+23%3A59%3A59')651 eq_(rv.status_code, 200)652 data = rv.data.decode('utf-8')653 ok_('datetime_obj1' not in data)654 ok_('datetime_obj2' in data)655 # datetime - empty656 rv = client.get('/admin/_datetime/?flt0_13=1')657 eq_(rv.status_code, 200)658 data = rv.data.decode('utf-8')659 ok_('test1_val_1' in data)660 ok_('datetime_obj1' not in data)661 ok_('datetime_obj2' not in data)662 # datetime - not empty663 rv = client.get('/admin/_datetime/?flt0_13=0')664 eq_(rv.status_code, 200)665 data = rv.data.decode('utf-8')666 ok_('test1_val_1' not in data)667 ok_('datetime_obj1' in data)668 ok_('datetime_obj2' in data)669 # time - equals670 rv = client.get('/admin/_datetime/?flt0_14=11%3A10%3A09')671 eq_(rv.status_code, 200)672 data = rv.data.decode('utf-8')673 ok_('timeonly_obj1' in data)674 ok_('timeonly_obj2' not in data)675 # time - not equal676 rv = client.get('/admin/_datetime/?flt0_15=11%3A10%3A09')677 eq_(rv.status_code, 200)678 data = rv.data.decode('utf-8')679 ok_('timeonly_obj1' not in data)680 ok_('timeonly_obj2' in data)681 # time - greater682 rv = client.get('/admin/_datetime/?flt0_16=11%3A09%3A09')683 eq_(rv.status_code, 200)684 data = rv.data.decode('utf-8')685 ok_('timeonly_obj1' in data)686 ok_('timeonly_obj2' not in data)687 # time - smaller688 rv = client.get('/admin/_datetime/?flt0_17=11%3A09%3A09')689 eq_(rv.status_code, 200)690 data = rv.data.decode('utf-8')691 ok_('timeonly_obj1' not in data)692 ok_('timeonly_obj2' in data)693 # time - between694 rv = client.get('/admin/_datetime/?flt0_18=10%3A40%3A00+to+11%3A50%3A59')695 eq_(rv.status_code, 200)696 data = rv.data.decode('utf-8')697 ok_('timeonly_obj1' in data)698 ok_('timeonly_obj2' not in data)699 # time - not between700 rv = client.get('/admin/_datetime/?flt0_19=10%3A40%3A00+to+11%3A50%3A59')701 eq_(rv.status_code, 200)702 data = rv.data.decode('utf-8')703 ok_('timeonly_obj1' not in data)704 ok_('timeonly_obj2' in data)705 # time - empty706 rv = client.get('/admin/_datetime/?flt0_20=1')707 eq_(rv.status_code, 200)708 data = rv.data.decode('utf-8')709 ok_('test1_val_1' in data)710 ok_('timeonly_obj1' not in data)711 ok_('timeonly_obj2' not in data)712 # time - not empty713 rv = client.get('/admin/_datetime/?flt0_20=0')714 eq_(rv.status_code, 200)715 data = rv.data.decode('utf-8')716 ok_('test1_val_1' not in data)717 ok_('timeonly_obj1' in data)718 ok_('timeonly_obj2' in data)719def test_default_sort():720 app, db, admin = setup()721 M1, _ = create_models(db)722 M1('c', 1).save()723 M1('b', 2).save()724 M1('a', 3).save()725 eq_(M1.select().count(), 3)726 view = CustomModelView(M1, column_default_sort='test1')727 admin.add_view(view)728 _, data = view.get_list(0, None, None, None, None)729 eq_(data[0].test1, 'a')730 eq_(data[1].test1, 'b')731 eq_(data[2].test1, 'c')732def test_extra_fields():733 app, db, admin = setup()734 Model1, _ = create_models(db)735 view = CustomModelView(736 Model1,737 form_extra_fields={738 'extra_field': fields.StringField('Extra Field')739 }740 )741 admin.add_view(view)742 client = app.test_client()743 rv = client.get('/admin/model1/new/')744 eq_(rv.status_code, 200)745 # Check presence and order746 data = rv.data.decode('utf-8')747 ok_('Extra Field' in data)748 pos1 = data.find('Extra Field')749 pos2 = data.find('Test1')750 ok_(pos2 < pos1)751def test_custom_form_base():752 app, db, admin = setup()753 class TestForm(form.BaseForm):754 pass755 Model1, _ = create_models(db)756 view = CustomModelView(757 Model1,758 form_base_class=TestForm759 )760 admin.add_view(view)761 ok_(hasattr(view._create_form_class, 'test1'))762 create_form = view.create_form()763 ok_(isinstance(create_form, TestForm))764def test_form_args():765 app, db, admin = setup()766 class BaseModel(peewee.Model):767 class Meta:768 database = db769 class Model(BaseModel):770 test = peewee.CharField(null=False)771 Model.create_table()772 shared_form_args = {'test': {'validators': [validators.Regexp('test')]}}773 view = CustomModelView(Model, form_args=shared_form_args)774 admin.add_view(view)775 # ensure shared field_args don't create duplicate validators776 create_form = view.create_form()777 eq_(len(create_form.test.validators), 2)778 edit_form = view.edit_form()779 eq_(len(edit_form.test.validators), 2)780def test_ajax_fk():781 app, db, admin = setup()782 class BaseModel(peewee.Model):783 class Meta:784 database = db785 class Model1(BaseModel):786 test1 = peewee.CharField(max_length=20)787 test2 = peewee.CharField(max_length=20)788 def __str__(self):789 return self.test1790 class Model2(BaseModel):791 model1 = peewee.ForeignKeyField(Model1)792 Model1.create_table()793 Model2.create_table()794 view = CustomModelView(795 Model2,796 url='view',797 form_ajax_refs={798 'model1': {799 'fields': ('test1', 'test2')800 }801 }802 )803 admin.add_view(view)804 ok_(u'model1' in view._form_ajax_refs)805 model = Model1(test1=u'first', test2=u'')806 model.save()807 model2 = Model1(test1=u'foo', test2=u'bar')808 model2.save()809 # Check loader810 loader = view._form_ajax_refs[u'model1']811 mdl = loader.get_one(model.id)812 eq_(mdl.test1, model.test1)813 items = loader.get_list(u'fir')814 eq_(len(items), 1)815 eq_(items[0].id, model.id)816 items = loader.get_list(u'bar')817 eq_(len(items), 1)818 eq_(items[0].test1, u'foo')819 # Check form generation820 form = view.create_form()821 eq_(form.model1.__class__.__name__, u'AjaxSelectField')822 with app.test_request_context('/admin/view/'):823 ok_(u'value=""' not in form.model1())824 form.model1.data = model825 needle = u'data-json="[%s, &quot;first&quot;]"' % as_unicode(model.id)826 ok_(needle in form.model1())827 ok_(u'value="%s"' % as_unicode(model.id) in form.model1())828 # Check querying829 client = app.test_client()830 req = client.get(u'/admin/view/ajax/lookup/?name=model1&query=foo')831 eq_(req.data, u'[[%s, "foo"]]' % model2.id)832 # Check submitting833 client.post('/admin/view/new/', data={u'model1': as_unicode(model.id)})834 mdl = Model2.select().first()835 ok_(mdl is not None)836 ok_(mdl.model1 is not None)837 eq_(mdl.model1.id, model.id)838 eq_(mdl.model1.test1, u'first')839def test_export_csv():840 app, db, admin = setup()841 Model1, Model2 = create_models(db)842 view = CustomModelView(Model1, can_export=True,843 column_list=['test1', 'test2'], export_max_rows=2,844 endpoint='row_limit_2')845 admin.add_view(view)846 for x in range(5):847 fill_db(Model1, Model2)848 client = app.test_client()849 # test export_max_rows850 rv = client.get('/admin/row_limit_2/export/csv/')851 data = rv.data.decode('utf-8')852 eq_(rv.status_code, 200)853 ok_("Test1,Test2\r\n"854 "test1_val_1,test2_val_1\r\n"855 "test1_val_2,test2_val_2\r\n" == data)856 view = CustomModelView(Model1, can_export=True,857 column_list=['test1', 'test2'],858 endpoint='no_row_limit')859 admin.add_view(view)860 # test row limit without export_max_rows861 rv = client.get('/admin/no_row_limit/export/csv/')862 data = rv.data.decode('utf-8')863 eq_(rv.status_code, 200)...

Full Screen

Full Screen

api_v2_handlers_tests.py

Source:api_v2_handlers_tests.py Github

copy

Full Screen

...15 # Act16 board = handlers.create_board('Test', BoardKind.public, 'id', 'name', 'board_kind')17 18 # Assert19 ok_(board != None)20 ok_(type(board) is dict)21 ok_(board['name'] == 'Test')22 ok_(board['board_kind'] == 'public')23@patch(EXECUTE_QUERY_PATCH)24def test_get_board(execute_query):25 # Arrange26 execute_query.return_value = [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}, {'id': '5'}]27 # Act28 boards = handlers.get_boards('id', limit=5)29 30 # Assert31 ok_(boards != None)32 ok_(type(boards) is list)33 ok_(len(boards) == 5)34@patch(EXECUTE_QUERY_PATCH)35def test_archive_board(execute_query):36 # Arrange37 execute_query.return_value = {'id': '1', 'state': 'archived'}38 # Act39 archived_board = handlers.archive_board('1', 'id', 'state')40 41 # Assert42 ok_(archived_board != None)43 ok_(type(archived_board) is dict)44 ok_(archived_board['state'] == 'archived')45@patch(EXECUTE_QUERY_PATCH)46def test_add_subscribers_to_board(execute_query):47 # Arrange48 user_id = '1'49 name = 'name'50 execute_query.return_value = {'id': user_id, 'name': name}51 # Act52 subscriber = handlers.add_subscribers_to_board('1', ['1'])53 # Assert54 ok_(subscriber)55 eq_(subscriber['id'], user_id)56 eq_(subscriber['name'], name)57@patch(EXECUTE_QUERY_PATCH)58def test_remove_subscribers_from_board(execute_query):59 # Arrange60 user_id = '1'61 name = 'name'62 execute_query.return_value = [{'id': user_id, 'name': name}]63 print(execute_query)64 # Act65 subscribers = handlers.delete_subscribers_from_board('1', ['1'])66 # Assert67 ok_(subscribers)68 eq_(subscribers[0]['id'], user_id)69 eq_(subscribers[0]['name'], name)70@patch(EXECUTE_QUERY_PATCH)71def test_create_column(execute_query):72 # Arrange73 title = 'Text Column One'74 execute_query.return_value = {'id': 'text_column_1', 'title': title, 'type': 'text'}75 # Act76 new_column = handlers.create_column('1', title, ColumnType.text, 'id', 'title', 'type')77 78 # Assert79 ok_(new_column != None)80 ok_(type(new_column) is dict)81 ok_(new_column['title'] == title)82 ok_(new_column['type'] == ColumnType.text.name)83@patch(EXECUTE_QUERY_PATCH)84def test_change_column_title(execute_query):85 # Arrange86 column_id='text_column_1'87 board_id='12345678'88 title='Hello, world!'89 execute_query.return_value = {'id': '1'}90 # Act91 updated_item = handlers.change_column_title(column_id='text_column_1', board_id='12345678', title='Hello, world!')92 93 # Assert94 ok_(updated_item != None)95 ok_(type(updated_item) is dict)96 ok_(updated_item['id'] == '1')97@patch(EXECUTE_QUERY_PATCH)98def test_change_column_value(execute_query):99 # Arrange100 execute_query.return_value = {'id': '1'}101 # Act102 updated_item = handlers.change_column_value('1', 'text_column_1', '1', 'Hello, world!', 'id')103 104 # Assert105 ok_(updated_item != None)106 ok_(type(updated_item) is dict)107 ok_(updated_item['id'] == '1')108@patch(EXECUTE_QUERY_PATCH)109def test_change_simple_column_value(execute_query):110 # Arrange111 board_id = '12345678'112 item_id = '2345678'113 column_id = 'new_column'114 value = "Simple Value to update"115 execute_query.return_value = {'id': '2345678'}116 # Act117 updated_item = handlers.change_simple_column_value(board_id='12345678',item_id='2345678',column_id='new_column',value="Simple Value to update")118 119 # Assert120 ok_(updated_item != None)121 ok_(updated_item['id'] == item_id)122@patch(EXECUTE_QUERY_PATCH)123def test_change_multiple_column_value(execute_query):124 # Arrange125 column_values = {'text_column_1': 'Let\'s eat, Grandma!', 'numbers_column_1': 8675309}126 execute_query.return_value = {'id': '1'}127 # Act128 updated_item = handlers.change_multiple_column_value('1', '1', column_values, 'id')129 130 # Assert131 ok_(updated_item != None)132 ok_(type(updated_item) is dict)133 ok_(updated_item['id'] == '1')134@patch(EXECUTE_QUERY_PATCH)135def test_duplicate_group(execute_query):136 # Arrange137 group_id = 'group_2'138 execute_query.return_value = {'id': group_id}139 # Act140 duplicated_group = handlers.duplicate_group('1', 'group_1', 'id')141 142 # Assert143 ok_(duplicated_group != None)144 ok_(duplicated_group['id'] == 'group_2')145@patch(EXECUTE_QUERY_PATCH)146def test_create_group(execute_query):147 # Arrange148 group_id = 'group_1'149 group_name = 'New Group One'150 execute_query.return_value = {'id': group_id, 'title': group_name}151 # Act152 new_group = handlers.create_group('1', group_name, 'id', 'title')153 154 # Assert155 ok_(new_group != None)156 ok_(type(new_group) is dict)157 ok_(new_group['id'] == group_id)158 ok_(new_group['title'] == group_name)159@patch(EXECUTE_QUERY_PATCH)160def test_archive_group(execute_query):161 # Arrange162 execute_query.return_value = {'id': 'group_1', 'archived': True}163 # Act164 archived_group = handlers.archive_group('1', 'group_1', 'archived')165 166 # Assert167 ok_(archived_group != None)168 ok_(type(archived_group) is dict)169 ok_(archived_group.__contains__('id'))170 ok_(archived_group['archived'] == True)171@patch(EXECUTE_QUERY_PATCH)172def test_delete_group(execute_query):173 # Arrange174 execute_query.return_value = {'id': 'group_1', 'deleted': True}175 # Act176 deleted_group = handlers.delete_group('1', 'group_1', 'deleted')177 178 # Assert179 ok_(deleted_group != None)180 ok_(type(deleted_group) is dict)181 ok_(deleted_group.__contains__('id'))182 ok_(deleted_group['deleted'] == True)183@patch(EXECUTE_QUERY_PATCH)184def test_create_item(execute_query):185 # Arrange186 item_name = 'Item One'187 execute_query.return_value = {'id': '1', 'name': item_name}188 # Act189 new_item = handlers.create_item(item_name, '1', 'id', 'name')190 191 # Assert192 ok_(new_item != None)193 ok_(type(new_item) is dict)194 ok_(new_item.__contains__('id'))195 ok_(new_item['name'] == item_name)196@patch(EXECUTE_QUERY_PATCH)197def test_create_subitem(execute_query):198 # Arrange199 id = '2'200 item_name = 'Item One'201 execute_query.return_value = {'id': id, 'name': item_name}202 # Act203 subitem = handlers.create_subitem('1', item_name)204 205 # Assert206 ok_(subitem != None)207 ok_(type(subitem) is dict)208 eq_(subitem['id'], id)209 eq_(subitem['name'], item_name)210@patch(EXECUTE_QUERY_PATCH)211def test_clear_item_updates(execute_query):212 # Arrange213 id = '1'214 item_name = 'Item One'215 execute_query.return_value = {'id': id, 'name': item_name}216 # Act217 item = handlers.clear_item_updates(id)218 219 # Assert220 ok_(item)221 ok_(type(item) is dict)222 eq_(item['id'], id)223 eq_(item['name'], item_name)224@patch(EXECUTE_QUERY_PATCH)225def test_get_items(execute_query):226 # Arrange227 execute_query.return_value = [{'id': '1', 'name': 'Item One'}, {'id': '2', 'name': 'Item Two'}]228 # Act229 items = handlers.get_items(page=1, limit=2)230 231 # Assert232 ok_(items != None)233 ok_(type(items) is list)234 ok_(len(items) == 2)235@patch(EXECUTE_QUERY_PATCH)236def test_get_items_by_column_values(execute_query):237 # Arrange238 execute_query.return_value = [{'id': '1', 'name': 'Item One'}]239 # Act240 items = handlers.get_items_by_column_values('1', 'name', 'Item One', 'id', 'name')241 242 # Assert243 ok_(items != None)244 ok_(type(items) is list)245 ok_(len(items) == 1)246@patch(EXECUTE_QUERY_PATCH)247def test_archive_item(execute_query):248 # Arrange249 execute_query.return_value = {'id': '1', 'state': 'archived'}250 # Act251 archived_item = handlers.archive_item('1', 'id', 'state')252 253 # Assert254 ok_(archived_item != None)255 ok_(type(archived_item) is dict)256 ok_(archived_item['state'] == State.archived.name)257@patch(EXECUTE_QUERY_PATCH)258def test_delete_item(execute_query):259 # Arrange260 execute_query.return_value = {'id': '1', 'state': 'deleted'}261 # Act262 deleted_item = handlers.delete_item('1', 'id', 'state')263 264 # Assert265 ok_(deleted_item != None)266 ok_(type(deleted_item) is dict)267 ok_(deleted_item['state'] == State.deleted.name)268@patch(EXECUTE_QUERY_PATCH)269def test_duplicate_item(execute_query):270 # Arrange271 id = '1'272 name = 'dupe'273 execute_query.return_value = {'id': id, 'name': name}274 # Act275 duplicate_item = handlers.duplicate_item('1', '1')276 277 # Assert278 ok_(duplicate_item)279 eq_(duplicate_item['id'], id)280 eq_(duplicate_item['name'], name)281@patch(EXECUTE_QUERY_PATCH)282def test_create_update(execute_query):283 # Arrange284 body = 'Hello, world! Let\'s eat, Grandma!'285 item_id = '1'286 execute_query.return_value = {'id': '1', 'body': body, 'item_id': item_id}287 # Act288 new_update = handlers.create_update(body, item_id, 'id', 'body', 'item_id')289 290 # Assert291 ok_(new_update != None)292 ok_(type(new_update) is dict)293 ok_(new_update['body'] == body)294 ok_(new_update['item_id'] == item_id)295@patch(EXECUTE_QUERY_PATCH)296def test_get_updates(execute_query):297 # Arrange298 execute_query.return_value = [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}, {'id': '5'}]299 # Act300 updates = handlers.get_updates('id', limit=5)301 302 # Assert303 ok_(updates != None)304 ok_(type(updates) is list)305 ok_(len(updates) == 5)306@patch(EXECUTE_QUERY_PATCH)307def test_delete_update(execute_query):308 # Arrange309 id = '1'310 item_id = '1'311 creator_id = '1'312 execute_query.return_value = {'id': id, 'item_id': item_id, 'creator_id': creator_id}313 # Act314 update = handlers.delete_update('1')315 316 # Assert317 ok_(update)318 ok_(type(update) is dict)319 eq_(update['id'], id)320 eq_(update['item_id'], item_id)321 eq_(update['creator_id'], creator_id)322@patch(EXECUTE_QUERY_PATCH)323def test_create_notification(execute_query):324 # Arrange325 text = 'Did you eat, Grandma?'326 execute_query.return_value = {'text': text}327 328 # Act329 notification = handlers.create_notification(text, '1', '2', NotificationTargetType.Project, 'text')330 331 # Assert332 ok_(notification != None)333 ok_(type(notification) is dict)334 ok_(notification['text'] == text)335@patch(EXECUTE_QUERY_PATCH)336def test_create_or_get_tag(execute_query):337 # Arrange338 name = 'Tag One'339 execute_query.return_value = {'id': '1', 'name': 'Tag One'}340 341 # Act342 tag = handlers.create_or_get_tag(name, 'id', 'name')343 344 # Assert345 ok_(tag != None)346 ok_(type(tag) is dict)347 ok_(tag['name'] == name)348@patch(EXECUTE_QUERY_PATCH)349def test_get_tags(execute_query):350 # Arrange351 execute_query.return_value = [{'id': '1'}, {'id': '2'}, {'id': '3'}]352 # Act353 tags = handlers.get_tags('id')354 355 # Assert356 ok_(tags != None)357 ok_(type(tags) is list)358 ok_(len(tags) == 3)359@patch(EXECUTE_QUERY_PATCH)360def test_get_users(execute_query):361 # Arrange362 execute_query.return_value = [{'id': '1', 'name': 'Grandma'}, {'id': '2', 'name': 'Osamu Dazai'}]363 # Act364 users = handlers.get_users('id', 'name')365 366 # Assert367 ok_(users != None)368 ok_(type(users) is list)369 ok_(len(users) == 2)370@patch(EXECUTE_QUERY_PATCH)371def test_get_teams(execute_query):372 # Arrange373 team_name = 'Grandma\'s House'374 execute_query.return_value = [{'id': '1', 'name': team_name}]375 # Act376 teams = handlers.get_teams('id', 'name')377 378 # Assert379 ok_(teams != None)380 ok_(type(teams) is list)381 ok_(len(teams) == 1)382 383@patch(EXECUTE_QUERY_PATCH)384def test_get_me(execute_query):385 # Arrange386 name = 'Meeeeeeeeee!'387 execute_query.return_value = {'id': '1', 'name': name}388 # Act389 me = handlers.get_me('')390 391 # Assert392 ok_(me != None)393 ok_(type(me) is dict)394 ok_(me['name'] == name)395@patch(EXECUTE_QUERY_PATCH)396def test_create_webhook(execute_query):397 # Arrange398 board_id = '12345'399 url = 'http://test.webhook.com/webhook/test'400 event = WebhookEventType.create_item401 webhook_id = '12345678'402 execute_query.return_value = {'id': webhook_id, 'board_id': int(board_id)}403 # Act404 webhook = handlers.create_webhook(board_id, url, event)405 # Assert406 ok_(webhook != None)407 ok_(type(webhook) is dict)408 ok_(webhook['id'] == webhook_id)409 ok_(webhook['board_id'] == int(board_id))410@patch(EXECUTE_QUERY_PATCH)411def test_delete_webhook(execute_query):412 # Arrange413 board_id = '12345'414 webhook_id = '12345678'415 execute_query.return_value = {'id': webhook_id, 'board_id': int(board_id)}416 # Act417 webhook = handlers.delete_webhook(webhook_id)418 # Assert419 ok_(webhook != None)420 ok_(type(webhook) is dict)421 ok_(webhook['id'] == webhook_id)422 ok_(webhook['board_id'] == int(board_id))423@patch(UPLOAD_FILE_PATCH)424def test_add_file_to_update(upload_file):425 # Arrange426 name = '33.jpg'427 url = 'https://test.monday.com/12345/{}'.format(name)428 upload_file.return_value = {'id': '12345', 'name': name, 'url': url}429 # Act430 asset = handlers.add_file_to_update('12345', '/Users/test/{}'.format(name))431 432 # Assert433 ok_(asset != None)434 ok_(type(asset) is dict)435 ok_(asset['name'] == name)436 ok_(asset['url'] == url)437@patch(UPLOAD_FILE_PATCH)438def test_add_file_to_column(upload_file):439 # Arrange440 name = '33.jpg'441 url = 'https://test.monday.com/12345/{}'.format(name)442 upload_file.return_value = {'id': '12345', 'name': name, 'url': url}443 # Act444 asset = handlers.add_file_to_column('12345', 'files', '/Users/test/{}'.format(name))445 446 # Assert447 ok_(asset != None)448 ok_(type(asset) is dict)449 ok_(asset['name'] == name)450 ok_(asset['url'] == url)451@patch(EXECUTE_QUERY_PATCH)452def test_create_workspace(execute_query):453 # Arrange454 id = '12345'455 name = 'Workspace'456 kind = WorkspaceKind.open457 description = 'This is a test workspace'458 execute_query.return_value = {'id': id, 'name': name, 'kind': kind.name, 'description': description}459 # Act460 workspace = handlers.create_workspace(name, kind, description=description)461 # Assert462 ok_(workspace != None)463 ok_(type(workspace) is dict)464 ok_(workspace['id'] == id)465 ok_(workspace['name'] == name)466 ok_(workspace['kind'] == kind.name)467 ok_(workspace['description'] == description)468 469@patch(EXECUTE_QUERY_PATCH)470def test_add_users_to_workspace(execute_query):471 # Arrange472 id = '12345'473 user_ids = ['1','2','3','4','5']474 kind = SubscriberKind.subscriber475 execute_query.return_value = {'id': '12345', 'kind': kind.name }476 # Act477 workspace = handlers.add_users_to_workspace(id,user_ids, kind)478 # Assert479 ok_(workspace != None)480 ok_(type(workspace) is dict)481 ok_(workspace['id'] == id)482 ok_(workspace['kind'] == kind.name)483 484@patch(EXECUTE_QUERY_PATCH)485def test_remove_users_from_workspace(execute_query):486 #Arrange487 workspace_id = '12345'488 user_ids=['1','2','3','4','5']489 execute_query.return_value = {'id': '12345'}490 #Act491 workspace = handlers.delete_users_from_workspace(workspace_id,user_ids)492 #Assert493 ok_(workspace != None)494 ok_(workspace['id'] == workspace_id)495@patch(EXECUTE_QUERY_PATCH)496def test_add_teams_to_workspace(execute_query):497 #Arrange498 workspace_id = '12345'499 team_ids = ['105939', '105940', '105941']500 execute_query.return_value = [{'id': '105939'}, {'id': '105940'}, {'id': '105940'}]501 # Act502 teams = handlers.add_teams_to_workspace(workspace_id, team_ids)503 # Assert504 ok_(teams != None)505 ok_(type(teams is list))506 eq_(len(teams), 3)507 508@patch(EXECUTE_QUERY_PATCH)509def test_remove_teams_from_workspace(execute_query):510 #Arrange511 workspace_id = '12345'512 team_ids = ['105939', '105940', '105941']513 execute_query.return_value = [{'id': '105939'}, {'id': '105940'}, {'id': '105940'}]514 # Act515 teams = handlers.delete_teams_from_workspace(workspace_id, team_ids)516 # Assert517 ok_(teams != None)518 ok_(type(teams is list))...

Full Screen

Full Screen

identifier_utils_test.py

Source:identifier_utils_test.py Github

copy

Full Screen

...89 eq_( [ "foo", "goo-foo", "zoo", "bar", "aa", "z", "b@g" ],90 iu.ExtractIdentifiersFromText(91 '<foo> <goo-foo zoo=bar aa="" z=\'\'/> b@g', "html" ) )92def IsIdentifier_generic_test():93 ok_( iu.IsIdentifier( 'foo' ) )94 ok_( iu.IsIdentifier( 'foo129' ) )95 ok_( iu.IsIdentifier( 'f12' ) )96 ok_( not iu.IsIdentifier( '1foo129' ) )97 ok_( not iu.IsIdentifier( '-foo' ) )98 ok_( not iu.IsIdentifier( 'foo-' ) )99 ok_( not iu.IsIdentifier( 'font-face' ) )100 ok_( not iu.IsIdentifier( None ) )101 ok_( not iu.IsIdentifier( '' ) )102def IsIdentifier_Css_test():103 ok_( iu.IsIdentifier( 'foo' , 'css' ) )104 ok_( iu.IsIdentifier( 'a1' , 'css' ) )105 ok_( iu.IsIdentifier( 'a-' , 'css' ) )106 ok_( iu.IsIdentifier( 'a-b' , 'css' ) )107 ok_( iu.IsIdentifier( '_b' , 'css' ) )108 ok_( iu.IsIdentifier( '-ms-foo' , 'css' ) )109 ok_( iu.IsIdentifier( '-_o' , 'css' ) )110 ok_( iu.IsIdentifier( 'font-face', 'css' ) )111 ok_( not iu.IsIdentifier( '-3b', 'css' ) )112 ok_( not iu.IsIdentifier( '-3' , 'css' ) )113 ok_( not iu.IsIdentifier( '3' , 'css' ) )114 ok_( not iu.IsIdentifier( 'a' , 'css' ) )115def IsIdentifier_R_test():116 ok_( iu.IsIdentifier( 'a' , 'r' ) )117 ok_( iu.IsIdentifier( 'a.b' , 'r' ) )118 ok_( iu.IsIdentifier( 'a.b.c', 'r' ) )119 ok_( iu.IsIdentifier( 'a_b' , 'r' ) )120 ok_( iu.IsIdentifier( 'a1' , 'r' ) )121 ok_( iu.IsIdentifier( 'a_1' , 'r' ) )122 ok_( iu.IsIdentifier( '.a' , 'r' ) )123 ok_( iu.IsIdentifier( '.a_b' , 'r' ) )124 ok_( iu.IsIdentifier( '.a1' , 'r' ) )125 ok_( iu.IsIdentifier( '...' , 'r' ) )126 ok_( iu.IsIdentifier( '..1' , 'r' ) )127 ok_( not iu.IsIdentifier( '.1a', 'r' ) )128 ok_( not iu.IsIdentifier( '.1' , 'r' ) )129 ok_( not iu.IsIdentifier( '1a' , 'r' ) )130 ok_( not iu.IsIdentifier( '123', 'r' ) )131 ok_( not iu.IsIdentifier( '_1a', 'r' ) )132 ok_( not iu.IsIdentifier( '_a' , 'r' ) )133def IsIdentifier_Clojure_test():134 ok_( iu.IsIdentifier( 'foo' , 'clojure' ) )135 ok_( iu.IsIdentifier( 'f9' , 'clojure' ) )136 ok_( iu.IsIdentifier( 'a.b.c', 'clojure' ) )137 ok_( iu.IsIdentifier( 'a.c' , 'clojure' ) )138 ok_( iu.IsIdentifier( 'a/c' , 'clojure' ) )139 ok_( iu.IsIdentifier( '*' , 'clojure' ) )140 ok_( iu.IsIdentifier( 'a*b' , 'clojure' ) )141 ok_( iu.IsIdentifier( '?' , 'clojure' ) )142 ok_( iu.IsIdentifier( 'a?b' , 'clojure' ) )143 ok_( iu.IsIdentifier( ':' , 'clojure' ) )144 ok_( iu.IsIdentifier( 'a:b' , 'clojure' ) )145 ok_( iu.IsIdentifier( '+' , 'clojure' ) )146 ok_( iu.IsIdentifier( 'a+b' , 'clojure' ) )147 ok_( iu.IsIdentifier( '-' , 'clojure' ) )148 ok_( iu.IsIdentifier( 'a-b' , 'clojure' ) )149 ok_( iu.IsIdentifier( '!' , 'clojure' ) )150 ok_( iu.IsIdentifier( 'a!b' , 'clojure' ) )151 ok_( not iu.IsIdentifier( '9f' , 'clojure' ) )152 ok_( not iu.IsIdentifier( '9' , 'clojure' ) )153 ok_( not iu.IsIdentifier( 'a/b/c', 'clojure' ) )154 ok_( not iu.IsIdentifier( '(a)' , 'clojure' ) )155def IsIdentifier_Haskell_test():156 ok_( iu.IsIdentifier( 'foo' , 'haskell' ) )157 ok_( iu.IsIdentifier( "foo'", 'haskell' ) )158 ok_( iu.IsIdentifier( "x'" , 'haskell' ) )159 ok_( iu.IsIdentifier( "_x'" , 'haskell' ) )160 ok_( iu.IsIdentifier( "_x" , 'haskell' ) )161 ok_( iu.IsIdentifier( "x9" , 'haskell' ) )162 ok_( not iu.IsIdentifier( "'x", 'haskell' ) )163 ok_( not iu.IsIdentifier( "9x", 'haskell' ) )164 ok_( not iu.IsIdentifier( "9" , 'haskell' ) )165def StartOfLongestIdentifierEndingAtIndex_Simple_test():166 eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', 3 ) )167 eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( 'f12', 3 ) )168def StartOfLongestIdentifierEndingAtIndex_BadInput_test():169 eq_( 0, iu.StartOfLongestIdentifierEndingAtIndex( '', 0 ) )170 eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( '', 1 ) )171 eq_( 5, iu.StartOfLongestIdentifierEndingAtIndex( None, 5 ) )172 eq_( -1, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', -1 ) )173 eq_( 10, iu.StartOfLongestIdentifierEndingAtIndex( 'foo', 10 ) )174def StartOfLongestIdentifierEndingAtIndex_Punctuation_test():175 eq_( 1, iu.StartOfLongestIdentifierEndingAtIndex( '(foo', 4 ) )176 eq_( 6, iu.StartOfLongestIdentifierEndingAtIndex( ' foo', 9 ) )177 eq_( 4, iu.StartOfLongestIdentifierEndingAtIndex( 'gar;foo', 7 ) )178 eq_( 2, iu.StartOfLongestIdentifierEndingAtIndex( '...', 2 ) )...

Full Screen

Full Screen

test_queue.py

Source:test_queue.py Github

copy

Full Screen

...78 queue = self._makeOne()79 queue.put(b"one")80 queue.put_all([b"two", b"three"])81 eq_(len(queue), 3)82 ok_(not queue.consume())83 ok_(not queue.holds_lock())84 eq_(queue.get(1), b"one")85 ok_(queue.holds_lock())86 # Without consuming, should return the same element87 eq_(queue.get(1), b"one")88 ok_(queue.consume())89 ok_(not queue.holds_lock())90 eq_(queue.get(1), b"two")91 ok_(queue.holds_lock())92 ok_(queue.consume())93 ok_(not queue.holds_lock())94 eq_(queue.get(1), b"three")95 ok_(queue.holds_lock())96 ok_(queue.consume())97 ok_(not queue.holds_lock())98 ok_(not queue.consume())99 eq_(len(queue), 0)100 def test_consume(self):101 queue = self._makeOne()102 queue.put(b"one")103 ok_(not queue.consume())104 queue.get(.1)105 ok_(queue.consume())106 ok_(not queue.consume())107 def test_holds_lock(self):108 queue = self._makeOne()109 ok_(not queue.holds_lock())110 queue.put(b"one")111 queue.get(.1)112 ok_(queue.holds_lock())113 queue.consume()114 ok_(not queue.holds_lock())115 def test_priority(self):116 queue = self._makeOne()117 queue.put(b"four", priority=101)118 queue.put(b"one", priority=0)119 queue.put(b"two", priority=0)120 queue.put(b"three", priority=10)121 eq_(queue.get(1), b"one")122 ok_(queue.consume())123 eq_(queue.get(1), b"two")124 ok_(queue.consume())125 eq_(queue.get(1), b"three")126 ok_(queue.consume())127 eq_(queue.get(1), b"four")128 ok_(queue.consume())129 def test_concurrent_execution(self):130 queue = self._makeOne()131 value1 = []132 value2 = []133 value3 = []134 event1 = self.client.handler.event_object()135 event2 = self.client.handler.event_object()136 event3 = self.client.handler.event_object()137 def get_concurrently(value, event):138 q = self.client.LockingQueue(queue.path)139 value.append(q.get(.1))140 event.set()141 self.client.handler.spawn(get_concurrently, value1, event1)142 self.client.handler.spawn(get_concurrently, value2, event2)...

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 Nose 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