How to use should_not_be method in Selene

Best Python code snippet using selene_python

test_FilterSpec_class.py

Source:test_FilterSpec_class.py Github

copy

Full Screen

1"""2This file contains tests of the context NetworkDataRequestTest class.3Functions tested:4- add_entity_type()5- get_entity_for_identifier()6- get_entity_trait()7- get_identifier()8- set_entity_trait()9- set_identifier()10"""11# base Python imports12import json13import logging14import os15import sys16# import six17import six18# django imports19import django.test20# context imports21from context.export.network.filter_spec import FilterSpec22from context.export.network.network_data_request import NetworkDataRequest23from context.tests.export.network.test_helper import TestHelper24# python_utilities25from python_utilities.booleans.boolean_helper import BooleanHelper26from python_utilities.exceptions.exception_helper import ExceptionHelper27class FilterSpecTest( django.test.TestCase ):28 29 #----------------------------------------------------------------------------30 # ! ==> Constants-ish31 #----------------------------------------------------------------------------32 # DEBUG33 DEBUG = False34 # CLASS NAME35 CLASS_NAME = "FilterSpecTest"36 37 # test - get()/set()38 TEST_SET_COMPARISON_TYPE = "test_set_comparison_type"39 TEST_SET_DATA_TYPE = "test_set_data_type"40 TEST_SET_FILTER_SPEC = "test_set_filter_spec"41 TEST_SET_FILTER_SPEC_PROPERTY_NAME = "test_set_filter_spec_property_name"42 TEST_SET_FILTER_SPEC_PROPERTY = "test_set_filter_spec_property"43 TEST_SET_FILTER_TYPE = "test_set_filter_type"44 TEST_SET_MY_Q = "test_set_my_q"45 TEST_SET_NAME = "test_set_name"46 TEST_SET_RELATION_ROLES_LIST = [ FilterSpec.PROP_VALUE_RELATION_ROLES_LIST_FROM, FilterSpec.PROP_VALUE_RELATION_ROLES_LIST_TO ]47 TEST_SET_TYPE_ID = "test_set_type_id"48 TEST_SET_TYPE_LABEL = "test_set_type_label"49 TEST_SET_VALUE = "test_set_value"50 TEST_SET_VALUE_FROM = "test_set_value_from"51 TEST_SET_VALUE_LIST = "test_set_value_list"52 TEST_SET_VALUE_TO = "test_set_value_to"53 TEST_AGAIN = "_again"54 #----------------------------------------------------------------------55 # ! ==> class methods56 #----------------------------------------------------------------------57 #---------------------------------------------------------------------------58 # ! ==> overridden built-in methods59 #---------------------------------------------------------------------------60 #----------------------------------------------------------------------------61 # ! ==> instance methods - setup62 #----------------------------------------------------------------------------63 def setUp( self ):64 65 """66 setup tasks. Call function that we'll re-use.67 """68 # call TestHelper.standardSetUp()69 TestHelper.standardSetUp( self )70 #-- END function setUp() --#71 72 def test_setup( self ):73 """74 Tests whether there were errors in setup.75 """76 77 # declare variables78 me = "test_setup"79 error_count = -180 error_message = ""81 82 print( '\n====> In {}.{}'.format( self.CLASS_NAME, me ) )83 84 # get setup error count85 setup_error_count = self.setup_error_count86 87 # should be 088 error_message = ";".join( self.setup_error_list )89 self.assertEqual( setup_error_count, 0, msg = error_message )90 91 #-- END test method test_django_config_installed() --#92 #----------------------------------------------------------------------------93 # ! ==> instance methods - shared methods94 #----------------------------------------------------------------------------95 #----------------------------------------------------------------------------96 # ! ==> instance methods - tests97 #----------------------------------------------------------------------------98 def test_child_filter_set_list( self ):99 # declare variables100 me = "test_child_filter_set_list"101 debug_flag = None102 test_instance = None103 test_method = None104 original_value = None105 new_value = None106 test_value = None107 should_be = None108 error_string = None109 test_list = None110 test_list_count = None111 test_filter_spec = None112 113 # init debug114 debug_flag = self.DEBUG115 116 # print test header117 TestHelper.print_test_header( self.CLASS_NAME, me )118 119 # create a test instance 120 test_instance = FilterSpec()121 122 # Test:123 # - get original value and store (should be empty list)124 # - set new value (new list, with something in it)125 # - get value.126 # - assertEquals( get value, new value )127 # - assertNotEqual( get value, original value )128 129 # get130 test_list = test_instance.get_child_filter_spec_list()131 original_value = test_list132 133 # list should not be none...134 test_value = test_list135 error_string = "Retrieving initial child filter spec list for filter spec {}, returned None".format( test_instance )136 self.assertIsNotNone( test_value, msg = error_string )137 # ...should have length 0.138 test_value = len( test_list )139 should_be = 0140 error_string = "new list length = {}, should = {}.".format( test_value, should_be )141 self.assertEqual( test_value, should_be, msg = error_string )142 143 # add an item144 test_filter_spec = FilterSpec()145 test_instance.add_to_child_filter_spec_list( test_filter_spec )146 # previously retrieved list should now have length 1147 test_value = len( test_list )148 should_be = 1149 error_string = "new list length = {}, should = {}.".format( test_value, should_be )150 self.assertEqual( test_value, should_be, msg = error_string )151 152 # add an item153 test_filter_spec = FilterSpec()154 test_instance.add_to_child_filter_spec_list( test_filter_spec )155 # previously retrieved list should now have length 2156 test_value = len( test_list )157 should_be = 2158 error_string = "new list length = {}, should = {}.".format( test_value, should_be )159 self.assertEqual( test_value, should_be, msg = error_string )160 # get161 test_list = test_instance.get_child_filter_spec_list()162 163 # should have length 2164 test_value = len( test_list )165 should_be = 2166 error_string = "new list length = {}, should = {}.".format( test_value, should_be )167 self.assertEqual( test_value, should_be, msg = error_string )168 # should be equal to original_list169 test_value = test_list170 should_be = original_value171 error_string = "list retrieved from instance = {}, should = {}.".format( test_value, should_be )172 self.assertEqual( test_value, should_be, msg = error_string )173 # make totally new list.174 new_list = []175 new_list.append( FilterSpec() )176 new_list.append( FilterSpec() )177 new_list.append( FilterSpec() )178 179 # set list in instance.180 test_instance.set_child_filter_spec_list( new_list )181 182 # get list183 test_list = test_instance.get_child_filter_spec_list()184 185 # should not be equal to original list186 test_value = test_list187 should_not_be = original_value188 error_string = "new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )189 self.assertNotEqual( test_value, should_not_be, msg = error_string )190 # should be equal to new_list191 test_value = test_list192 should_be = new_list193 error_string = "list retrieved from instance = {}, should = {}.".format( test_value, should_be )194 self.assertEqual( test_value, should_be, msg = error_string )195 # should have length 3196 test_value = len( test_list )197 should_be = 3198 error_string = "new list length = {}, should = {}.".format( test_value, should_be )199 self.assertEqual( test_value, should_be, msg = error_string )200 #-- END test method test_child_filter_set_list() --#201 def test_getters_and_setters( self ):202 # declare variables203 me = "test_getters_and_setters"204 debug_flag = None205 test_instance = None206 test_method = None207 original_value = None208 new_value = None209 test_value = None210 should_be = None211 error_string = None212 213 # init debug214 debug_flag = self.DEBUG215 216 # print test header217 TestHelper.print_test_header( self.CLASS_NAME, me )218 219 # create a test instance 220 test_instance = FilterSpec()221 222 # ! ----> test get()-ers and set()-ers together223 224 # for each (using last loaded test instance):225 # - get original value and store226 # - set new value227 # - get value.228 # - assertEquals( get value, new value )229 # - assertNotEqual( get value, original value )230 231 #----------------------------------------------------------------------#232 # ! --------> set_comparison_type()233 test_method = "set_comparison_type"234 original_value = test_instance.get_comparison_type()235 new_value = self.TEST_SET_COMPARISON_TYPE236 test_instance.set_comparison_type( new_value )237 test_value = test_instance.get_comparison_type()238 # new should equal test239 should_be = new_value240 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )241 self.assertEqual( test_value, should_be, msg = error_string )242 243 # new should not equal original244 should_not_be = original_value245 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )246 self.assertNotEqual( test_value, should_not_be, msg = error_string )247 # set it again.248 original_value = test_instance.get_comparison_type()249 new_value = "{}{}".format( self.TEST_SET_COMPARISON_TYPE, self.TEST_AGAIN )250 test_instance.set_comparison_type( new_value )251 test_value = test_instance.get_comparison_type()252 # new should equal test253 should_be = new_value254 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )255 self.assertEqual( test_value, should_be, msg = error_string )256 257 # new should not equal original258 should_not_be = original_value259 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )260 self.assertNotEqual( test_value, should_not_be, msg = error_string )261 #----------------------------------------------------------------------#262 # ! --------> set_data_type()263 test_method = "set_data_type"264 original_value = test_instance.get_data_type()265 new_value = self.TEST_SET_DATA_TYPE266 test_instance.set_data_type( new_value )267 test_value = test_instance.get_data_type()268 # new should equal test269 should_be = new_value270 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )271 self.assertEqual( test_value, should_be, msg = error_string )272 273 # new should not equal original274 should_not_be = original_value275 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )276 self.assertNotEqual( test_value, should_not_be, msg = error_string )277 # set it again.278 original_value = test_instance.get_data_type()279 new_value = "{}{}".format( self.TEST_SET_DATA_TYPE, self.TEST_AGAIN )280 test_instance.set_data_type( new_value )281 test_value = test_instance.get_data_type()282 # new should equal test283 should_be = new_value284 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )285 self.assertEqual( test_value, should_be, msg = error_string )286 287 # new should not equal original288 should_not_be = original_value289 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )290 self.assertNotEqual( test_value, should_not_be, msg = error_string )291 292 #----------------------------------------------------------------------#293 # ! --------> set_filter_spec()294 test_method = "set_filter_spec"295 original_value = test_instance.get_filter_spec()296 new_value = self.TEST_SET_FILTER_SPEC297 test_instance.set_filter_spec( new_value )298 test_value = test_instance.get_filter_spec()299 # new should equal test300 should_be = new_value301 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )302 self.assertEqual( test_value, should_be, msg = error_string )303 304 # new should not equal original305 should_not_be = original_value306 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )307 self.assertNotEqual( test_value, should_not_be, msg = error_string )308 309 # put back the original so we have a dictionary there.310 test_instance.set_filter_spec( original_value )311 #----------------------------------------------------------------------#312 # ! --------> set_filter_spec_property()313 test_method = "set_filter_spec_property"314 test_name = self.TEST_SET_FILTER_SPEC_PROPERTY_NAME315 original_value = test_instance.get_filter_spec_property( test_name )316 new_value = self.TEST_SET_FILTER_SPEC_PROPERTY317 test_instance.set_filter_spec_property( test_name, new_value )318 test_value = test_instance.get_filter_spec_property( test_name )319 # new should equal test320 should_be = new_value321 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )322 self.assertEqual( test_value, should_be, msg = error_string )323 324 # new should not equal original325 should_not_be = original_value326 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )327 self.assertNotEqual( test_value, should_not_be, msg = error_string )328 # set it again.329 original_value = test_instance.get_filter_spec_property( test_name )330 new_value = "{}{}".format( self.TEST_SET_FILTER_SPEC_PROPERTY_NAME, self.TEST_AGAIN )331 test_instance.set_filter_spec_property( test_name, new_value )332 test_value = test_instance.get_filter_spec_property( test_name )333 # new should equal test334 should_be = new_value335 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )336 self.assertEqual( test_value, should_be, msg = error_string )337 338 # new should not equal original339 should_not_be = original_value340 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )341 self.assertNotEqual( test_value, should_not_be, msg = error_string )342 # set to None.343 original_value = test_instance.get_filter_spec_property( test_name )344 new_value = None345 test_instance.set_filter_spec_property( test_name, new_value )346 test_value = test_instance.get_filter_spec_property( test_name )347 # new should equal test348 should_be = new_value349 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )350 self.assertEqual( test_value, should_be, msg = error_string )351 352 # new should not equal original353 should_not_be = original_value354 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )355 self.assertNotEqual( test_value, should_not_be, msg = error_string )356 357 #----------------------------------------------------------------------#358 # ! --------> set_filter_type()359 test_method = "set_filter_type"360 original_value = test_instance.get_filter_type()361 new_value = self.TEST_SET_FILTER_TYPE362 test_instance.set_filter_type( new_value )363 test_value = test_instance.get_filter_type()364 # new should equal test365 should_be = new_value366 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )367 self.assertEqual( test_value, should_be, msg = error_string )368 369 # new should not equal original370 should_not_be = original_value371 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )372 self.assertNotEqual( test_value, should_not_be, msg = error_string )373 # set it again.374 original_value = test_instance.get_filter_type()375 new_value = "{}{}".format( self.TEST_SET_FILTER_TYPE, self.TEST_AGAIN )376 test_instance.set_filter_type( new_value )377 test_value = test_instance.get_filter_type()378 # new should equal test379 should_be = new_value380 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )381 self.assertEqual( test_value, should_be, msg = error_string )382 383 # new should not equal original384 should_not_be = original_value385 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )386 self.assertNotEqual( test_value, should_not_be, msg = error_string )387 #----------------------------------------------------------------------#388 # ! --------> set_my_q()389 test_method = "set_my_q"390 original_value = test_instance.get_my_q()391 new_value = self.TEST_SET_MY_Q392 test_instance.set_my_q( new_value )393 test_value = test_instance.get_my_q()394 # new should equal test395 should_be = new_value396 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )397 self.assertEqual( test_value, should_be, msg = error_string )398 399 # new should not equal original400 should_not_be = original_value401 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )402 self.assertNotEqual( test_value, should_not_be, msg = error_string )403 # set it again.404 original_value = test_instance.get_my_q()405 new_value = "{}{}".format( self.TEST_SET_MY_Q, self.TEST_AGAIN )406 test_instance.set_my_q( new_value )407 test_value = test_instance.get_my_q()408 # new should equal test409 should_be = new_value410 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )411 self.assertEqual( test_value, should_be, msg = error_string )412 413 # new should not equal original414 should_not_be = original_value415 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )416 self.assertNotEqual( test_value, should_not_be, msg = error_string )417 #----------------------------------------------------------------------#418 # ! --------> set_name()419 test_method = "set_name"420 original_value = test_instance.get_name()421 new_value = self.TEST_SET_NAME422 test_instance.set_name( new_value )423 test_value = test_instance.get_name()424 # new should equal test425 should_be = new_value426 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )427 self.assertEqual( test_value, should_be, msg = error_string )428 429 # new should not equal original430 should_not_be = original_value431 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )432 self.assertNotEqual( test_value, should_not_be, msg = error_string )433 # set it again.434 original_value = test_instance.get_name()435 new_value = "{}{}".format( self.TEST_SET_NAME, self.TEST_AGAIN )436 test_instance.set_name( new_value )437 test_value = test_instance.get_name()438 # new should equal test439 should_be = new_value440 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )441 self.assertEqual( test_value, should_be, msg = error_string )442 443 # new should not equal original444 should_not_be = original_value445 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )446 self.assertNotEqual( test_value, should_not_be, msg = error_string )447 #----------------------------------------------------------------------#448 # ! --------> set_relation_roles_list()449 test_method = "set_relation_roles_list"450 original_value = list( test_instance.get_relation_roles_list() )451 new_value = self.TEST_SET_RELATION_ROLES_LIST452 test_instance.set_relation_roles_list( new_value )453 test_value = test_instance.get_relation_roles_list()454 # new should equal test455 should_be = new_value456 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )457 self.assertEqual( test_value, should_be, msg = error_string )458 459 # new should not equal original460 should_not_be = original_value461 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )462 self.assertNotEqual( test_value, should_not_be, msg = error_string )463 # set it again.464 original_value = list ( test_instance.get_relation_roles_list() )465 new_value.append( FilterSpec.PROP_VALUE_RELATION_ROLES_LIST_THROUGH )466 test_instance.set_relation_roles_list( new_value )467 test_value = test_instance.get_relation_roles_list()468 # new should equal test469 should_be = new_value470 error_string = "Testing {}(), new = {}, retrieved {}, should = {}.".format( test_method, new_value, test_value, should_be )471 self.assertEqual( test_value, should_be, msg = error_string )472 473 # new should not equal original474 should_not_be = original_value475 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )476 self.assertNotEqual( test_value, should_not_be, msg = error_string )477 #----------------------------------------------------------------------#478 # ! TODO set_type_id()479 test_method = "set_type_id"480 original_value = test_instance.get_type_id()481 new_value = self.TEST_SET_TYPE_ID482 test_instance.set_type_id( new_value )483 test_value = test_instance.get_type_id()484 # new should equal test485 should_be = new_value486 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )487 self.assertEqual( test_value, should_be, msg = error_string )488 489 # new should not equal original490 should_not_be = original_value491 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )492 self.assertNotEqual( test_value, should_not_be, msg = error_string )493 # set it again.494 original_value = test_instance.get_type_id()495 new_value = "{}{}".format( self.TEST_SET_TYPE_ID, self.TEST_AGAIN )496 test_instance.set_type_id( new_value )497 test_value = test_instance.get_type_id()498 # new should equal test499 should_be = new_value500 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )501 self.assertEqual( test_value, should_be, msg = error_string )502 503 # new should not equal original504 should_not_be = original_value505 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )506 self.assertNotEqual( test_value, should_not_be, msg = error_string )507 #----------------------------------------------------------------------#508 # ! TODO set_type_label()509 test_method = "set_type_label"510 original_value = test_instance.get_type_label()511 new_value = self.TEST_SET_TYPE_LABEL512 test_instance.set_type_label( new_value )513 test_value = test_instance.get_type_label()514 # new should equal test515 should_be = new_value516 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )517 self.assertEqual( test_value, should_be, msg = error_string )518 519 # new should not equal original520 should_not_be = original_value521 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )522 self.assertNotEqual( test_value, should_not_be, msg = error_string )523 # set it again.524 original_value = test_instance.get_type_label()525 new_value = "{}{}".format( self.TEST_SET_TYPE_LABEL, self.TEST_AGAIN )526 test_instance.set_type_label( new_value )527 test_value = test_instance.get_type_label()528 # new should equal test529 should_be = new_value530 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )531 self.assertEqual( test_value, should_be, msg = error_string )532 533 # new should not equal original534 should_not_be = original_value535 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )536 self.assertNotEqual( test_value, should_not_be, msg = error_string )537 #----------------------------------------------------------------------#538 # ! TODO set_value()539 test_method = "set_value"540 original_value = test_instance.get_value()541 new_value = self.TEST_SET_VALUE542 test_instance.set_value( new_value )543 test_value = test_instance.get_value()544 # new should equal test545 should_be = new_value546 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )547 self.assertEqual( test_value, should_be, msg = error_string )548 549 # new should not equal original550 should_not_be = original_value551 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )552 self.assertNotEqual( test_value, should_not_be, msg = error_string )553 # set it again.554 original_value = test_instance.get_value()555 new_value = "{}{}".format( self.TEST_SET_VALUE, self.TEST_AGAIN )556 test_instance.set_value( new_value )557 test_value = test_instance.get_value()558 # new should equal test559 should_be = new_value560 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )561 self.assertEqual( test_value, should_be, msg = error_string )562 563 # new should not equal original564 should_not_be = original_value565 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )566 self.assertNotEqual( test_value, should_not_be, msg = error_string )567 #----------------------------------------------------------------------#568 # ! TODO set_value_from()569 test_method = "set_value_from"570 original_value = test_instance.get_value_from()571 new_value = self.TEST_SET_VALUE_FROM572 test_instance.set_value_from( new_value )573 test_value = test_instance.get_value_from()574 # new should equal test575 should_be = new_value576 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )577 self.assertEqual( test_value, should_be, msg = error_string )578 579 # new should not equal original580 should_not_be = original_value581 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )582 self.assertNotEqual( test_value, should_not_be, msg = error_string )583 # set it again.584 original_value = test_instance.get_value_from()585 new_value = "{}{}".format( self.TEST_SET_VALUE_FROM, self.TEST_AGAIN )586 test_instance.set_value_from( new_value )587 test_value = test_instance.get_value_from()588 # new should equal test589 should_be = new_value590 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )591 self.assertEqual( test_value, should_be, msg = error_string )592 593 # new should not equal original594 should_not_be = original_value595 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )596 self.assertNotEqual( test_value, should_not_be, msg = error_string )597 #----------------------------------------------------------------------#598 # ! TODO set_value_list()599 test_method = "set_value_list"600 original_value = test_instance.get_value_list()601 new_value = self.TEST_SET_VALUE_LIST602 test_instance.set_value_list( new_value )603 test_value = test_instance.get_value_list()604 # new should equal test605 should_be = new_value606 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )607 self.assertEqual( test_value, should_be, msg = error_string )608 609 # new should not equal original610 should_not_be = original_value611 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )612 self.assertNotEqual( test_value, should_not_be, msg = error_string )613 # set it again.614 original_value = test_instance.get_value_list()615 new_value = "{}{}".format( self.TEST_SET_VALUE_LIST, self.TEST_AGAIN )616 test_instance.set_value_list( new_value )617 test_value = test_instance.get_value_list()618 # new should equal test619 should_be = new_value620 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )621 self.assertEqual( test_value, should_be, msg = error_string )622 623 # new should not equal original624 should_not_be = original_value625 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )626 self.assertNotEqual( test_value, should_not_be, msg = error_string )627 #----------------------------------------------------------------------#628 # ! TODO set_value_to()629 test_method = "set_value_to"630 original_value = test_instance.get_value_to()631 new_value = self.TEST_SET_VALUE_TO632 test_instance.set_value_to( new_value )633 test_value = test_instance.get_value_to()634 # new should equal test635 should_be = new_value636 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )637 self.assertEqual( test_value, should_be, msg = error_string )638 639 # new should not equal original640 should_not_be = original_value641 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )642 self.assertNotEqual( test_value, should_not_be, msg = error_string )643 # set it again.644 original_value = test_instance.get_value_to()645 new_value = "{}{}".format( self.TEST_SET_VALUE_TO, self.TEST_AGAIN )646 test_instance.set_value_to( new_value )647 test_value = test_instance.get_value_to()648 # new should equal test649 should_be = new_value650 error_string = "Testing {}(), new = {}, should = {}.".format( test_method, test_value, should_be )651 self.assertEqual( test_value, should_be, msg = error_string )652 653 # new should not equal original654 should_not_be = original_value655 error_string = "Testing {}(), new = {}, should NOT = {}.".format( test_method, test_value, should_not_be )656 self.assertNotEqual( test_value, should_not_be, msg = error_string )657 #-- END test method test_getters_and_setters() --#...

Full Screen

Full Screen

test_templates.py

Source:test_templates.py Github

copy

Full Screen

1from django.contrib.auth.models import User2from django.core.urlresolvers import reverse3from django.test import TestCase, Client4from recipes.models import Recipe5class HomePageTests(TestCase):6 def setUp(self):7 self.client = Client()8 self.user = User.objects.create_user(username='test', password='test')9 self.url = reverse('home')10 def test_search_bar_on_front_page(self):11 element = f'<form action="{self.url}" method="post" id="search-bar">'12 response = self.client.get(self.url)13 # assertContains does not recognize the form for some reason14 self.assertIn(element, str(response.content))15 def test_most_popular_recipes_shown(self):16 least_pop, *_, most_pop = recipes_asc_views(count=5, user=self.user)17 expected = f'<h3>{most_pop.title}</h3>'18 should_not_be = f'<h3>{least_pop.title}</h3>'19 response = self.client.get(self.url)20 self.assertContains(response, expected, html=True)21 self.assertNotContains(response, should_not_be, html=True)22 def test_most_popular_category_not_shown_with_no_recipes(self):23 should_not_be = '<h2>Popular</h2>'24 response = self.client.get(self.url)25 self.assertNotContains(response, should_not_be, html=True)26 def test_most_recent_recipes_shown(self):27 oldest, *_, newest = recipes_asc_views(count=5, user=self.user)28 expected = f'<h3>{newest.title}</h3>'29 should_not_be = f'<h3>{oldest.title}</h3>'30 response = self.client.get(self.url)31 self.assertContains(response, expected, html=True)32 self.assertNotContains(response, should_not_be, html=True)33 def test_most_recent_not_shown_with_no_recipes(self):34 should_not_be = '<h2>Recent</h2>'35 response = self.client.get(self.url)36 self.assertNotContains(response, should_not_be, html=True)37 def test_new_additions_shown_on_front_page(self):38 user2 = User.objects.create_user(username='test2', password='test')39 old, *_ = recipes_asc_views(count=5, user=user2)40 new = Recipe.objects.create(author=self.user, title='test6', views=1)41 expected = f'<h3>{new.title}</h3>'42 should_not_be = f'<h3>{old.title}</h3>'43 response = self.client.get(self.url)44 self.assertContains(response, expected, html=True)45 self.assertNotContains(response, should_not_be, html=True)46 def test_recent_additions_not_shown_with_no_recipes(self):47 should_not_be = '<h2>Your new additions</h2>'48 response = self.client.get(self.url)49 self.assertNotContains(response, should_not_be, html=True)50# Helper functions51def recipes_asc_views(count, user):52 recipes = []53 for views in range(count):54 title = f'test{views}'55 recipes.append(Recipe.objects.create(author=user, title=title, views=views))56 return recipes57class RegisterTests(TestCase):58 def setUp(self):59 self.client = Client()60 self.url = reverse('register')61 def test_registered_user_invalid_data(self):62 data = {'username': 'test', 'password1': 'test', 'password2': 'test'}63 response = self.client.post(self.url, data=data)64 self.assertContains(response, 'This password is too common.')65 self.assertContains(response, 'The password is too similar to the username.')66 self.assertContains(response, 'This password is too short. It must contain at '67 'least 8 characters.')68 def test_all_fields_missing(self):69 response = self.client.post(self.url, data=(dict()))70 self.assertContains(response, 'This field is required.')71 def test_username_field_missing(self):72 data = {'password1': 'test', 'password2': 'test'}73 response = self.client.post(self.url, data=data)74 self.assertContains(response, 'This field is required.')75 def test_password1_field_missing(self):76 data = {'username': 'test', 'password2': 'test'}77 response = self.client.post(self.url, data=data)78 self.assertContains(response, 'This field is required.')79 def test_password2_field_missing(self):80 data = {'username': 'test', 'password1': 'test'}81 response = self.client.post(self.url, data=data)82 self.assertContains(response, 'This field is required.')83 def test_register_user_already_exists(self):84 User.objects.create_user(username='test', password='test')85 data = {'username': 'test', 'password1': 'test', 'password2': 'test'}86 response = self.client.post(self.url, data=data)87 self.assertContains(response, 'A user with that username already exists.')88 def test_register_not_shown_in_register_view(self):89 expected_html = f'<a href={self.url}?next={self.url}>Register</a>'90 response = self.client.get(self.url)91 self.assertNotContains(response, expected_html, html=True)92 def test_register_shown_in_other_views(self):93 url = reverse('recipes:recipes')94 expected_html = f'<a href={self.url}?next={url}>Register</a>'95 response = self.client.get(url)96 self.assertContains(response, expected_html, html=True)97class LoginTests(TestCase):98 def setUp(self):99 self.client = Client()100 self.url = reverse('login')101 def test_login_not_shown_in_login_view(self):102 expected_html = f'<a href={self.url}?next={self.url}>Login</a>'103 response = self.client.get(self.url)104 self.assertNotContains(response, expected_html, html=True)105 def test_login_shown_in_other_views(self):106 url = reverse('recipes:recipes')107 expected_html = f'<a href={self.url}?next={url}>Login</a>'108 response = self.client.get(url)...

Full Screen

Full Screen

0017_migrate_application_type.py

Source:0017_migrate_application_type.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from __future__ import unicode_literals3import logging4from django.db import migrations5logger = logging.getLogger(__name__)6def update_type_and_status(apps, schema_editor):7 """8 - Update application_type for amendment and renewal application.9 By default the new application_type is set to 'new licence' (see previous migration) but this type should be10 updated to amendment or renewal for some applications.11 - We also need to update the now obsolete processing status ['renewal', 'licence_amendment'] to 'new'12 :param apps:13 :param schema_editor:14 :return:15 """16 obsolete_processing_status = ['renewal', 'licence_amendment']17 Application = apps.get_model("wl_applications", "Application")18 # search for application with a previous_application19 apps = Application.objects.filter(previous_application__isnull=False)20 # these applications are either amendment or renewal depending of the 'is_licence_amendment' flag.21 for app in apps:22 app.application_type = 'amendment' if app.is_licence_amendment else 'renewal'23 # we update also the processing status to 'new' if it is one of the now obsolete status24 if app.processing_status in obsolete_processing_status:25 app.processing_status = 'new'26 app.save()27 # double check status for applications without previous app28 should_not_be = Application.objects.exclude(previous_application__isnull=False).filter(29 processing_status__in=obsolete_processing_status)30 if should_not_be:31 logger.error("Some applications without parents have a status in {}: {}".32 format(obsolete_processing_status, should_not_be.values('pk')))33 should_not_be.update(processing_status='new')34def roll_back(apps, schema_editor):35 # nothing we can do36 pass37class Migration(migrations.Migration):38 dependencies = [39 ('wl_applications', '0016_application_application_type'),40 ]41 operations = [42 migrations.RunPython(update_type_and_status, roll_back)...

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