Best Python code snippet using tempest_python
test_routers.py
Source:test_routers.py
...36 service="network")37 def test_create_update_router_description(self):38 body = self.create_router(description='d1', router_name='test')39 self.assertEqual('d1', body['description'])40 body = self.client.show_router(body['id'])['router']41 self.assertEqual('d1', body['description'])42 body = self.client.update_router(body['id'], description='d2')43 self.assertEqual('d2', body['router']['description'])44 body = self.client.show_router(body['router']['id'])['router']45 self.assertEqual('d2', body['description'])46 @test.idempotent_id('847257cc-6afd-4154-b8fb-af49f5670ce8')47 @test.requires_ext(extension='ext-gw-mode', service='network')48 @test.attr(type='smoke')49 def test_create_router_with_default_snat_value(self):50 # Create a router with default snat rule51 name = data_utils.rand_name('router')52 router = self._create_router(53 name, external_network_id=CONF.network.public_network_id)54 self._verify_router_gateway(55 router['id'], {'network_id': CONF.network.public_network_id,56 'enable_snat': True})57 @test.idempotent_id('ea74068d-09e9-4fd7-8995-9b6a1ace920f')58 @test.requires_ext(extension='ext-gw-mode', service='network')59 @test.attr(type='smoke')60 def test_create_router_with_snat_explicit(self):61 name = data_utils.rand_name('snat-router')62 # Create a router enabling snat attributes63 enable_snat_states = [False, True]64 for enable_snat in enable_snat_states:65 external_gateway_info = {66 'network_id': CONF.network.public_network_id,67 'enable_snat': enable_snat}68 create_body = self.admin_client.create_router(69 name, external_gateway_info=external_gateway_info)70 self.addCleanup(self.admin_client.delete_router,71 create_body['router']['id'])72 # Verify snat attributes after router creation73 self._verify_router_gateway(create_body['router']['id'],74 exp_ext_gw_info=external_gateway_info)75 def _verify_router_gateway(self, router_id, exp_ext_gw_info=None):76 show_body = self.admin_client.show_router(router_id)77 actual_ext_gw_info = show_body['router']['external_gateway_info']78 if exp_ext_gw_info is None:79 self.assertIsNone(actual_ext_gw_info)80 return81 # Verify only keys passed in exp_ext_gw_info82 for k, v in six.iteritems(exp_ext_gw_info):83 self.assertEqual(v, actual_ext_gw_info[k])84 def _verify_gateway_port(self, router_id):85 list_body = self.admin_client.list_ports(86 network_id=CONF.network.public_network_id,87 device_id=router_id)88 self.assertEqual(len(list_body['ports']), 1)89 gw_port = list_body['ports'][0]90 fixed_ips = gw_port['fixed_ips']91 self.assertGreaterEqual(len(fixed_ips), 1)92 public_net_body = self.admin_client.show_network(93 CONF.network.public_network_id)94 public_subnet_id = public_net_body['network']['subnets'][0]95 self.assertIn(public_subnet_id,96 [x['subnet_id'] for x in fixed_ips])97 @test.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33')98 @test.requires_ext(extension='ext-gw-mode', service='network')99 @test.attr(type='smoke')100 def test_update_router_set_gateway_with_snat_explicit(self):101 router = self._create_router(data_utils.rand_name('router-'))102 self.admin_client.update_router_with_snat_gw_info(103 router['id'],104 external_gateway_info={105 'network_id': CONF.network.public_network_id,106 'enable_snat': True})107 self._verify_router_gateway(108 router['id'],109 {'network_id': CONF.network.public_network_id,110 'enable_snat': True})111 self._verify_gateway_port(router['id'])112 @test.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279')113 @test.requires_ext(extension='ext-gw-mode', service='network')114 @test.attr(type='smoke')115 def test_update_router_set_gateway_without_snat(self):116 router = self._create_router(data_utils.rand_name('router-'))117 self.admin_client.update_router_with_snat_gw_info(118 router['id'],119 external_gateway_info={120 'network_id': CONF.network.public_network_id,121 'enable_snat': False})122 self._verify_router_gateway(123 router['id'],124 {'network_id': CONF.network.public_network_id,125 'enable_snat': False})126 self._verify_gateway_port(router['id'])127 @test.idempotent_id('f2faf994-97f4-410b-a831-9bc977b64374')128 @test.requires_ext(extension='ext-gw-mode', service='network')129 @test.attr(type='smoke')130 def test_update_router_reset_gateway_without_snat(self):131 router = self._create_router(132 data_utils.rand_name('router-'),133 external_network_id=CONF.network.public_network_id)134 self.admin_client.update_router_with_snat_gw_info(135 router['id'],136 external_gateway_info={137 'network_id': CONF.network.public_network_id,138 'enable_snat': False})139 self._verify_router_gateway(140 router['id'],141 {'network_id': CONF.network.public_network_id,142 'enable_snat': False})143 self._verify_gateway_port(router['id'])144 @test.idempotent_id('c86ac3a8-50bd-4b00-a6b8-62af84a0765c')145 @test.requires_ext(extension='extraroute', service='network')146 @test.attr(type='smoke')147 def test_update_extra_route(self):148 self.network = self.create_network()149 self.name = self.network['name']150 self.subnet = self.create_subnet(self.network)151 # Add router interface with subnet id152 self.router = self._create_router(153 data_utils.rand_name('router-'), True)154 self.create_router_interface(self.router['id'], self.subnet['id'])155 self.addCleanup(156 self._delete_extra_routes,157 self.router['id'])158 # Update router extra route, second ip of the range is159 # used as next hop160 cidr = netaddr.IPNetwork(self.subnet['cidr'])161 next_hop = str(cidr[2])162 destination = str(self.subnet['cidr'])163 extra_route = self.client.update_extra_routes(self.router['id'],164 next_hop, destination)165 self.assertEqual(1, len(extra_route['router']['routes']))166 self.assertEqual(destination,167 extra_route['router']['routes'][0]['destination'])168 self.assertEqual(next_hop,169 extra_route['router']['routes'][0]['nexthop'])170 show_body = self.client.show_router(self.router['id'])171 self.assertEqual(destination,172 show_body['router']['routes'][0]['destination'])173 self.assertEqual(next_hop,174 show_body['router']['routes'][0]['nexthop'])175 def _delete_extra_routes(self, router_id):176 self.client.delete_extra_routes(router_id)177 @test.attr(type='smoke')178 @test.idempotent_id('01f185d1-d1a6-4cf9-abf7-e0e1384c169c')179 def test_network_attached_with_two_routers(self):180 network = self.create_network(data_utils.rand_name('network1'))181 self.create_subnet(network)182 port1 = self.create_port(network)183 port2 = self.create_port(network)184 router1 = self._create_router(data_utils.rand_name('router1'))185 router2 = self._create_router(data_utils.rand_name('router2'))186 self.client.add_router_interface_with_port_id(187 router1['id'], port1['id'])188 self.client.add_router_interface_with_port_id(189 router2['id'], port2['id'])190 self.addCleanup(self.client.remove_router_interface_with_port_id,191 router1['id'], port1['id'])192 self.addCleanup(self.client.remove_router_interface_with_port_id,193 router2['id'], port2['id'])194 body = self.client.show_port(port1['id'])195 port_show1 = body['port']196 body = self.client.show_port(port2['id'])197 port_show2 = body['port']198 self.assertEqual(port_show1['network_id'], network['id'])199 self.assertEqual(port_show2['network_id'], network['id'])200 self.assertEqual(port_show1['device_id'], router1['id'])201 self.assertEqual(port_show2['device_id'], router2['id'])202class RoutersIpV6Test(RoutersTest):203 _ip_version = 6204class DvrRoutersTest(base.BaseRouterTest):205 @classmethod206 @test.requires_ext(extension="dvr", service="network")207 def skip_checks(cls):208 super(DvrRoutersTest, cls).skip_checks()209 @test.attr(type='smoke')210 @test.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a')211 def test_create_distributed_router(self):212 name = data_utils.rand_name('router')213 create_body = self.admin_client.create_router(214 name, distributed=True)215 self.addCleanup(self._delete_router,216 create_body['router']['id'],217 self.admin_client)218 self.assertTrue(create_body['router']['distributed'])219 @test.attr(type='smoke')220 @test.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729')221 def test_convert_centralized_router(self):222 router = self._create_router(data_utils.rand_name('router'))223 self.assertNotIn('distributed', router)224 update_body = self.admin_client.update_router(router['id'],225 distributed=True)226 self.assertTrue(update_body['router']['distributed'])227 show_body = self.admin_client.show_router(router['id'])228 self.assertTrue(show_body['router']['distributed'])229 show_body = self.client.show_router(router['id'])...
urls.py
Source:urls.py
1from django.conf import settings2from django.conf.urls import url, include3from django.contrib import admin4from django.views.static import serve5from rest_framework_nested import routers6from rest_framework.authtoken import views7from oidc_provider import urls8from program.views import APIUserViewSet, APIHostViewSet, APIShowViewSet, APIScheduleViewSet, APITimeSlotViewSet, APINoteViewSet, APICategoryViewSet, APITypeViewSet, APITopicViewSet, APIMusicFocusViewSet, APIRTRCategoryViewSet, APILanguageViewSet, json_day_schedule, json_playout, json_timeslots_specials9admin.autodiscover()10router = routers.DefaultRouter()11router.register(r'users', APIUserViewSet)12router.register(r'hosts', APIHostViewSet)13router.register(r'shows', APIShowViewSet)14router.register(r'schedules', APIScheduleViewSet)15router.register(r'timeslots', APITimeSlotViewSet)16router.register(r'notes', APINoteViewSet)17router.register(r'categories', APICategoryViewSet)18router.register(r'topics', APITopicViewSet)19router.register(r'types', APITypeViewSet)20router.register(r'musicfocus', APIMusicFocusViewSet)21router.register(r'rtrcategories', APIRTRCategoryViewSet)22router.register(r'languages', APILanguageViewSet)23'''Nested Routers'''24show_router = routers.NestedSimpleRouter(router, r'shows', lookup='show')25# /shows/1/schedules26show_router.register(r'schedules', APIScheduleViewSet, base_name='show-schedules')27# /shows/1/notes28show_router.register(r'notes', APINoteViewSet, base_name='show-notes')29# /shows/1/timeslots30show_router.register(r'timeslots', APITimeSlotViewSet, base_name='show-timeslots')31show_timeslot_router = routers.NestedSimpleRouter(show_router, r'timeslots', lookup='timeslot')32# /shows/1/timeslots/1/note/33show_timeslot_router.register(r'note', APINoteViewSet, base_name='show-timeslots-note')34# /shows/1/schedules35schedule_router = routers.NestedSimpleRouter(show_router, r'schedules', lookup='schedule')36# /shows/1/schedules/1/timeslots37schedule_router.register(r'timeslots', APITimeSlotViewSet, base_name='schedule-timeslots')38timeslot_router = routers.NestedSimpleRouter(schedule_router, r'timeslots', lookup='timeslot')39# /shows/1/schedules/1/timeslots/1/note40timeslot_router.register(r'note', APINoteViewSet, base_name='timeslots-note')41urlpatterns = [42 url(r'^openid/', include('oidc_provider.urls', namespace='oidc_provider')),43 url(r'^api/v1/', include(router.urls) ),44 url(r'^api/v1/', include(show_router.urls)),45 url(r'^api/v1/', include(show_timeslot_router.urls)),46 url(r'^api/v1/', include(schedule_router.urls)),47 url(r'^api/v1/', include(timeslot_router.urls)),48 url(r'^api/v1/playout', json_playout),49 url(r'^api/v1/program/week', json_playout),50 url(r'^api/v1/program/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', json_day_schedule),51 url(r'^admin/', admin.site.urls),52 url(r'^program/', include('program.urls')),53 url(r'^nop', include('nop.urls')),54 url(r'^api/', include('frapp.urls')),55 #url(r'^tinymce/', include('tinymce.urls')),56 url(r'^export/timeslots_specials.json$', json_timeslots_specials),57]58if settings.DEBUG:...
show_router.py
Source:show_router.py
1{ 'show_router': { 'head': [ { 'duration': 1.455,2 'name': u'show_router',3 'positions': [-0.1791, 0.7854],4 'starttime': 0.0}],5 'left_arm': [ { 'duration': 2.342,6 'name': u'show_router',7 'positions': [ -1.2197,8 -0.1458,9 -1.3245,10 0.0935,11 0.6873,12 0.9441,13 0.8189],14 'starttime': 0.0}],15 'left_hand': [],16 'left_leg': [],17 'right_arm': [],18 'right_hand': [],19 'right_leg': [],...
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!!