Best Python code snippet using localstack_python
unittest_base.py
Source:unittest_base.py
...21 'communities': 'test_commu'22 }23 route_id = self.database.add_route(post)24 post2 = self.database.get_route_by_id({'_id': route_id})25 self.database.delete_route({'_id': route_id})26 self.assertEqual(post2['ip'], post['ip'], 'insertion failed')27 self.assertEqual(post2['next_hop'], post['next_hop'],28 'insertion failed')29 self.assertEqual(post2['communities'], post['communities'],30 'insertion failed')31 def test_add_route(self):32 """33 test_add_route34 Tests if the route has successfully been added to the database35 """36 post = {37 'ip': 'test_ip',38 'next_hop': 'test_nexthop',39 'communities': 'test_commu'40 }41 route_id = self.database.add_route(post)42 post2 = self.database.route.find_one({'ip': post['ip']})43 self.database.delete_route({'_id': route_id})44 self.assertEqual(post2['ip'], post['ip'], 'insertion failed')45 self.assertEqual(post2['next_hop'], post['next_hop'],46 'insertion failed')47 self.assertEqual(post2['communities'], post['communities'],48 'insertion failed')49 def test_get_all_routes(self):50 """51 test_get_all_routes52 Test is the route has succesfully been got to the database53 """54 post = {55 'ip': 'test_ip',56 'next_hop': 'test_nexthop',57 'communities': 'test_commu'58 }59 post2 = {60 'ip': 'test_ip2',61 'next_hop': 'test_nexthop2',62 'communities': 'test_commu2'63 }64 route1_id = self.database.add_route(post)65 route2_id = self.database.add_route(post2)66 post3 = self.database.get_all_routes()67 self.assertFalse(len(post3) > 2,68 'Database was not empty before this function')69 self.database.delete_route({'_id': route1_id})70 self.database.delete_route({'_id': route2_id})71 for r in post3:72 if r['ip'] == post['ip']:73 self.assertEqual(r['ip'], post['ip'], 'insertion failed')74 self.assertEqual(r['next_hop'], post['next_hop'],75 'insertion failed')76 self.assertEqual(r['communities'], post['communities'],77 'insertion failed')78 else:79 self.assertEqual(r['ip'], post2['ip'], 'insertion failed')80 self.assertEqual(r['next_hop'], post2['next_hop'],81 'insertion failed')82 self.assertEqual(r['communities'], post2['communities'],83 'insertion failed')84 def test_update_route(self):85 """86 test_update_route87 Test if the route has succesfully been updated in the database88 """89 patch = {90 'ip': 'test_ip',91 'next_hop': 'test_nexthop',92 'communities': 'test_commu'93 }94 route_id = self.database.add_route(patch)95 patch2 = self.database.update_route({96 '_id': route_id,97 'is_activated': False,98 })99 self.database.delete_route({'_id': route_id})100 self.assertEqual(patch2['is_activated'], False, 'activation failed')101 def test_delete_route(self):102 """103 test_delete_route104 Test if the route has succesfully been deleted in the database105 """106 delete = {107 'ip': 'test_ip',108 'next_hop': 'test_nexthop',109 'communities': 'test_commu'110 }111 route_id = self.database.add_route(delete)112 self.database.delete_route({'_id': route_id})113 route = self.database.route.find_one({'_id': route_id})114 self.assertEqual(route, None, 'deletion failed')115 def test_put_route(self):116 """117 test_put_route118 Test if the route has succesfully been updated in the database119 """120 post = {121 'ip': 'test_ip',122 'next_hop': 'test_nexthop',123 'communities': 'test_commu'124 }125 route_id = self.database.add_route(post)126 post3 = {127 'ip': 'test_ip',128 'next_hop': 'test_nexthop2',129 'communities': 'test_commu2',130 'is_activated': False,131 }132 put = self.database.route.find_one({'_id': route_id})133 route_id2 = self.database.put_route({134 '_id': put['_id'],135 'ip': post3['ip'],136 'communities': post3['communities'],137 'next_hop': post3['next_hop'],138 'is_activated': post3['is_activated']139 })140 post2 = self.database.route.find_one({'_id': route_id2['_id']})141 self.database.delete_route({'_id': route_id2['_id']})142 self.assertEqual(post2['ip'], post3['ip'], 'insertion failed')143 self.assertEqual(post2['next_hop'], post3['next_hop'],144 'insertion failed')145 self.assertEqual(post2['communities'], post3['communities'],146 'insertion failed')147 self.assertEqual(post2['is_activated'], post3['is_activated'],148 'activation failed')149 def test_update_route_and_activation(self):150 """151 test_update_route_and_activation152 Test if last_activation is updated when153 is_activated change from false to true154 """155 patch = {156 'ip': 'test_ip',157 'next_hop': 'test_nexthop',158 'communities': 'test_commu'159 }160 route_id = self.database.add_route(patch)161 patch_activated_false = self.database.update_route({162 '_id': route_id,163 'is_activated': False,164 })165 last_activation_when_false = patch_activated_false['last_activation']166 patch_activated_true = self.database.update_route({167 '_id': route_id,168 'is_activated': True,169 })170 last_activation_when_true = patch_activated_true['last_activation']171 self.database.delete_route({'_id': route_id})172 self.assertNotEqual(last_activation_when_false,173 last_activation_when_true,174 'last_activation must be change')175 def test_put_route_and_activation(self):176 """177 test_put_route_and_activation178 Test if last_activation is updated when179 is_activated change from false to true180 """181 patch = {182 'ip': 'test_ip',183 'next_hop': 'test_nexthop',184 'communities': 'test_commu'185 }186 route_id = self.database.add_route(patch)187 patch_activated_false = self.database.put_route({188 '_id': route_id,189 'ip': 'test_ip',190 'next_hop': 'test_nexthop2',191 'communities': 'test_commu2',192 'is_activated': False,193 })194 last_activation_when_false = patch_activated_false['last_activation']195 patch_activated_true = self.database.put_route({196 '_id': route_id,197 'ip': 'test_ip',198 'next_hop': 'test_nexthop2',199 'communities': 'test_commu2',200 'is_activated': True,201 })202 last_activation_when_true = patch_activated_true['last_activation']203 self.database.delete_route({'_id': route_id})204 self.assertNotEqual(last_activation_when_false,205 last_activation_when_true,206 'last_activation must be change')207if __name__ == '__main__':...
urls.py
Source:urls.py
1from django.urls import path2from .views import main_dashboard, all_routes, add_route, my_profile,edit_route,delete_route,\3 profile_settings, remove_profile_photo,find_user,searched_profile,like_profile, \4 load_grades,route_detail,find_route5urlpatterns = [6 path('', main_dashboard,name='main_dashboard'),7 path('routes/<str:category>/',all_routes,name='all_routes'),8 path('add_route/',add_route,name='add_route'),9 path('my_profile/<str:category>/',my_profile,name='my_profile'),10 path('edit_route/<int:id>/<str:actual_category>/',edit_route,name='edit_route'),11 path('delete_route/<int:id>/<str:actual_category>/',delete_route,name='delete_route'),12 path('profile_settings/',profile_settings,name='profile_settings'),13 path('remove_profile_photo/',remove_profile_photo,name='remove_profile_photo'),14 path('find_user/',find_user,name='find_user'),15 path('searched_profile/<str:category>/<int:id>/',searched_profile,name='searched_profile'),16 path('like_profile/<int:id>/',like_profile,name='like_profile'),17 path('load_grades',load_grades,name='ajax_load_grades'),18 path('route_detail/<int:id>/',route_detail,name='route_detail'),19 path('find_route/',find_route,name='find_route'),...
__init__.py
Source:__init__.py
1from fastapi import APIRouter2api_router = APIRouter()3from app.routes.read_route import read_route4api_router.include_router(read_route.router,tags=["Read the Database"])5from app.routes.post_route import post_route6api_router.include_router(post_route.route,tags=["Post a Cedula"])7from app.routes.delete_route import delete_route8api_router.include_router(delete_route.router, tags=["delete a blog"])9from app.routes.update_route import update_route...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!