How to use in_docker method in localstack

Best Python code snippet using localstack_python

test_classifierd_ft_acl_ingress_apply.py

Source:test_classifierd_ft_acl_ingress_apply.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# Copyright (C) 2016 Hewlett Packard Enterprise Development LP4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing,12# software distributed under the License is distributed on an13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14# KIND, either express or implied. See the License for the15# specific language governing permissions and limitations16# under the License.17"""18OpenSwitch Test for ACE apply to interfaces.19"""20from pytest import mark, raises21from topology_lib_vtysh import exceptions22import time23TOPOLOGY = """24# +--------+25# | ops1 |26# +--------+27# Nodes28[type=openswitch name="OpenSwitch 1"] ops129# Links30"""31@mark.gate32@mark.test_id(10403)33def test_ace_apply(topology, step):34 """35 Test apply of ACEs to ports.36 Build a topology of one switch. Tested the ability to properly add ACL,37 delete ACL.38 """39 ops1 = topology.get('ops1')40 assert ops1 is not None41 # check if running in Docker -- will need to sleep after apply42 # and un-apply if so.43 _shell = ops1.get_shell('bash')44 _shell.send_command('ovs-appctl container/show-acl')45 out = _shell.get_response()46 print(out)47 if "server returned an error" in out:48 print("TEST ON HARDWARE")49 in_docker = 050 else:51 print("TEST IN DOCKER")52 in_docker = 153 step('################ T0 Make sure there are no ACLs defined ###########')54 out = ops1.libs.vtysh.show_access_list_commands('')55 for acl_type in out['access-list']:56 for acl_name in out['access-list'][acl_type]:57 print("Cleaning: " + acl_type + " " + acl_name)58 with ops1.libs.vtysh.Configure() as ctx:59 ctx.no_access_list(type=acl_type, access_list=acl_name)60 step('################ T1 Add Permit ACE ###########')61 step('################ to existing ACL ###############')62 with ops1.libs.vtysh.ConfigAccessListIp('test1') as ctx:63 ctx.permit('', '1', 'pim', '1.2.3.4', '', '5.6.7.8', '')64 out = ops1.libs.vtysh.show_access_list_commands('')65 assert('test1' in out['access-list']['ip'])66 step('################ T2 Replace ACE with Deny ###########')67 step('################ in existing ACL ###############')68 with ops1.libs.vtysh.ConfigAccessListIp('test1') as ctx:69 ctx.deny('', '1', 'igmp', '1.2.3.4', '', '5.6.7.8', '')70 if in_docker:71 time.sleep(2)72 out = ops1.libs.vtysh.show_running_config()73 assert('test1' in out['access-list']['ip'])74 aces = out['access-list']['ip']['test1']['aces']75 assert(len(aces) == 1)76 step('################ T3 Remove ACE ###########')77 step('################ from existing ACL ###############')78 with ops1.libs.vtysh.ConfigAccessListIp('test1') as ctx:79 ctx.no('1')80 if in_docker:81 time.sleep(2)82 out = ops1.libs.vtysh.show_running_config()83 assert('test1' in out['access-list']['ip'])84 aces = out['access-list']['ip']['test1']['aces']85 assert(len(aces) == 0)86 step('################ T4a Apply ACL ###########')87 step('################ to interface ###############')88 step('################ ACL does not exist ###############')89 with raises(exceptions.AclDoesNotExistException):90 with ops1.libs.vtysh.ConfigInterface('4') as ctx:91 ctx.apply_access_list('ip', 'test4', 'in')92 step('################ T4b Apply ACL ###########')93 step('################ to interface ###############')94 step('################ igmp protocol ###############')95 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:96 ctx.permit(97 '',98 '4', 'igmp', '1.2.3.4/255.0.0.0',99 '', '5.6.7.8/255.255.0.0', '')100 if in_docker:101 time.sleep(2)102 out = ops1.libs.vtysh.show_access_list_commands('')103 assert('test4' in out['access-list']['ip'])104 aces = out['access-list']['ip']['test4']['aces']105 assert(len(aces) == 1)106 ace = out['access-list']['ip']['test4']['aces'][0]107 assert(ace['seq'] == '4')108 assert(ace['action'] == 'permit')109 assert(ace['protocol'] == 'igmp')110 assert(ace['src'] == '1.2.3.4')111 assert(ace['dst'] == '5.6.7.8')112 with ops1.libs.vtysh.ConfigInterface('4') as ctx:113 ctx.apply_access_list('ip', 'test4', 'in')114 if in_docker:115 time.sleep(2)116 out = ops1.libs.vtysh.show_access_list_commands('ip')117 acl = out['access-list']['ip']['test4']118 assert(acl['applied'] == 'yes')119 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:120 ctx.no('4')121 if in_docker:122 time.sleep(2)123 out = ops1.libs.vtysh.show_access_list_commands('ip')124 aces = out['access-list']['ip']['test4']['aces']125 assert(len(aces) == 0)126 step('################ T5 Apply no ACL ###########')127 step('################ on interface 4 ###############')128 with ops1.libs.vtysh.ConfigInterface('4') as ctx:129 ctx.no_apply_access_list('ip', 'test4', 'in')130 if in_docker:131 time.sleep(2)132 out = ops1.libs.vtysh.show_access_list_commands('')133 acl = out['access-list']['ip']['test4']134 assert('applied' not in acl)135 step('################ T6 Apply ACL ###########')136 step('################ to interface ###############')137 step('################ A.B.C.D/M Network ###############')138 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:139 ctx.permit(140 '',141 '6', 'igmp', '1.2.3.4/8',142 '', '5.6.7.8/24', '')143 if in_docker:144 time.sleep(2)145 out = ops1.libs.vtysh.show_running_config()146 assert('test4' in out['access-list']['ip'])147 aces = out['access-list']['ip']['test4']['aces']148 assert(len(aces) == 1)149 ace = out['access-list']['ip']['test4']['aces'][0]150 assert(ace['seq'] == '6')151 assert(ace['action'] == 'permit')152 assert(ace['protocol'] == 'igmp')153 assert(ace['src_mask'] == '255.0.0.0')154 assert(ace['dst_mask'] == '255.255.255.0')155 with ops1.libs.vtysh.ConfigInterface('5') as ctx:156 ctx.apply_access_list('ip', 'test4', 'in')157 if in_docker:158 time.sleep(2)159 out = ops1.libs.vtysh.show_access_list_commands('ip')160 acl = out['access-list']['ip']['test4']161 assert(acl['applied'] == 'yes')162 with ops1.libs.vtysh.ConfigInterface('5') as ctx:163 ctx.no_apply_access_list('ip', 'test4', 'in')164 if in_docker:165 time.sleep(2)166 out = ops1.libs.vtysh.show_access_list_commands('ip')167 acl = out['access-list']['ip']['test4']168 assert('applied' not in acl)169 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:170 ctx.no('6')171 if in_docker:172 time.sleep(2)173 out = ops1.libs.vtysh.show_running_config()174 aces = out['access-list']['ip']['test4']['aces']175 assert(len(aces) == 0)176 step('################ T7 Apply ACL ###########')177 step('################ to interface ###############')178 step('################ A.B.C.D Host ###############')179 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:180 ctx.permit(181 '',182 '7', 'igmp', '1.2.3.4',183 '', '5.6.7.8', '')184 with ops1.libs.vtysh.ConfigInterface('7') as ctx:185 ctx.apply_access_list('ip', 'test4', 'in')186 if in_docker:187 time.sleep(2)188 out = ops1.libs.vtysh.show_running_config()189 assert('test4' in out['access-list']['ip'])190 aces = out['access-list']['ip']['test4']['aces']191 assert(len(aces) == 1)192 ace = out['access-list']['ip']['test4']['aces'][0]193 assert(ace['seq'] == '7')194 assert(ace['action'] == 'permit')195 assert(ace['protocol'] == 'igmp')196 assert(ace['src'] == '1.2.3.4')197 assert(ace['dst_mask'] is None)198 with ops1.libs.vtysh.ConfigInterface('7') as ctx:199 ctx.apply_access_list('ip', 'test4', 'in')200 if in_docker:201 time.sleep(2)202 out = ops1.libs.vtysh.show_access_list_commands('ip')203 acl = out['access-list']['ip']['test4']204 assert(acl['applied'] == 'yes')205 with ops1.libs.vtysh.ConfigInterface('7') as ctx:206 ctx.no_apply_access_list('ip', 'test4', 'in')207 if in_docker:208 time.sleep(2)209 out = ops1.libs.vtysh.show_access_list_commands('ip')210 acl = out['access-list']['ip']['test4']211 assert('applied' not in acl)212 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:213 ctx.no('7')214 if in_docker:215 time.sleep(2)216 out = ops1.libs.vtysh.show_running_config()217 aces = out['access-list']['ip']['test4']['aces']218 assert(len(aces) == 0)219 step('################ T8 Apply IPV4 ACL ###########')220 step('################ to interface ###############')221 step('################ proto any Host ###############')222 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:223 ctx.permit(224 '',225 '8', '4', 'any',226 '', 'any', '')227 if in_docker:228 time.sleep(2)229 out = ops1.libs.vtysh.show_running_config()230 assert('test4' in out['access-list']['ip'])231 aces = out['access-list']['ip']['test4']['aces']232 assert(len(aces) == 1)233 ace = out['access-list']['ip']['test4']['aces'][0]234 assert(ace['seq'] == '8')235 assert(ace['action'] == 'permit')236 assert(ace['protocol'] == '4')237 assert(ace['src'] == 'any')238 with ops1.libs.vtysh.ConfigInterface('8') as ctx:239 ctx.apply_access_list('ip', 'test4', 'in')240 if in_docker:241 time.sleep(2)242 out = ops1.libs.vtysh.show_access_list_commands('ip')243 acl = out['access-list']['ip']['test4']244 assert(acl['applied'] == 'yes')245 with ops1.libs.vtysh.ConfigInterface('8') as ctx:246 ctx.no_apply_access_list('ip', 'test4', 'in')247 if in_docker:248 time.sleep(2)249 out = ops1.libs.vtysh.show_access_list_commands('ip')250 acl = out['access-list']['ip']['test4']251 assert('applied' not in acl)252 step('################ T9 Apply ACL ###########')253 step('################ to interface ###############')254 step('################ sctp eq L4 ###############')255 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:256 ctx.permit(257 '',258 '9', 'sctp', '172.21.30.4/24',259 'eq 10', '5.6.7.8/24', 'eq 11')260 if in_docker:261 time.sleep(2)262 out = ops1.libs.vtysh.show_access_list_commands('ip')263 assert('test4' in out['access-list']['ip'])264 aces = out['access-list']['ip']['test4']['aces']265 assert(len(aces) == 2) # ace from test 8 was not removed!266 ace = out['access-list']['ip']['test4']['aces'][1]267 assert(ace['seq'] == '9')268 assert(ace['protocol'] == 'sctp')269 assert(ace['src_eq'] == '10')270 assert(ace['dst_eq'] == '11')271 with ops1.libs.vtysh.ConfigInterface('9') as ctx:272 ctx.apply_access_list('ip', 'test4', 'in')273 if in_docker:274 time.sleep(2)275 out = ops1.libs.vtysh.show_access_list_commands('ip')276 acl = out['access-list']['ip']['test4']277 assert(acl['applied'] == 'yes')278 with ops1.libs.vtysh.ConfigInterface('9') as ctx:279 ctx.no_apply_access_list('ip', 'test4', 'in')280 if in_docker:281 time.sleep(2)282 out = ops1.libs.vtysh.show_access_list_commands('ip')283 acl = out['access-list']['ip']['test4']284 assert('applied' not in acl)285 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:286 ctx.no('9')287 if in_docker:288 time.sleep(2)289 out = ops1.libs.vtysh.show_running_config()290 aces = out['access-list']['ip']['test4']['aces']291 assert(len(aces) == 1)292 with ops1.libs.vtysh.Configure() as ctx:293 ctx.no_access_list('ip', 'test4')294 if in_docker:295 time.sleep(2)296 out = ops1.libs.vtysh.show_access_list_commands('ip')297 assert('test4' not in out['access-list']['ip'])298 step('################ T10 Apply ACL ###########')299 step('################ to interface ###############')300 step('################ sctp eq L4 ###############')301 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:302 ctx.permit(303 '',304 '10', 'sctp', '172.21.30.4/24',305 'eq 10', '5.6.7.8/24', 'eq 11')306 if in_docker:307 time.sleep(2)308 out = ops1.libs.vtysh.show_running_config()309 assert('test4' in out['access-list']['ip'])310 aces = out['access-list']['ip']['test4']['aces']311 assert(len(aces) == 1)312 ace = out['access-list']['ip']['test4']['aces'][0]313 assert(ace['seq'] == '10')314 assert(ace['action'] == 'permit')315 assert(ace['protocol'] == 'sctp')316 with ops1.libs.vtysh.ConfigInterface('10') as ctx:317 ctx.apply_access_list('ip', 'test4', 'in')318 if in_docker:319 time.sleep(2)320 out = ops1.libs.vtysh.show_access_list_commands('ip')321 acl = out['access-list']['ip']['test4']322 assert(acl['applied'] == 'yes')323 with ops1.libs.vtysh.ConfigInterface('10') as ctx:324 ctx.no_apply_access_list('ip', 'test4', 'in')325 if in_docker:326 time.sleep(2)327 out = ops1.libs.vtysh.show_access_list_commands('ip')328 acl = out['access-list']['ip']['test4']329 assert('applied' not in acl)330 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:331 ctx.no('10')332 if in_docker:333 time.sleep(2)334 out = ops1.libs.vtysh.show_running_config()335 aces = out['access-list']['ip']['test4']['aces']336 assert(len(aces) == 0)337 step('################ T11 Apply ACL ###########')338 step('################ to interface ###############')339 step('################ sctp gt L4 ###############')340 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:341 ctx.permit(342 '',343 '11', 'sctp', '172.21.30.4/24',344 'gt 10', '5.6.7.8/24', 'gt 11')345 if in_docker:346 time.sleep(2)347 out = ops1.libs.vtysh.show_running_config()348 assert('test4' in out['access-list']['ip'])349 aces = out['access-list']['ip']['test4']['aces']350 assert(len(aces) == 1)351 ace = out['access-list']['ip']['test4']['aces'][0]352 assert(ace['seq'] == '11')353 assert(ace['dst_gt'] == '11')354 with ops1.libs.vtysh.ConfigInterface('11') as ctx:355 ctx.apply_access_list('ip', 'test4', 'in')356 if in_docker:357 time.sleep(2)358 out = ops1.libs.vtysh.show_access_list_commands('ip')359 acl = out['access-list']['ip']['test4']360 assert(acl['applied'] == 'yes')361 with ops1.libs.vtysh.ConfigInterface('11') as ctx:362 ctx.no_apply_access_list('ip', 'test4', 'in')363 if in_docker:364 time.sleep(2)365 out = ops1.libs.vtysh.show_access_list_commands('ip')366 acl = out['access-list']['ip']['test4']367 assert('applied' not in acl)368 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:369 ctx.no('11')370 if in_docker:371 time.sleep(2)372 out = ops1.libs.vtysh.show_running_config()373 aces = out['access-list']['ip']['test4']['aces']374 assert(len(aces) == 0)375 step('################ T12 Apply ACL ###########')376 step('################ to interface ###############')377 step('################ sctp lt L4 ###############')378 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:379 ctx.permit(380 '',381 '12', 'sctp', '172.21.30.4/24',382 'lt 10', '5.6.7.8/24', 'lt 11')383 if in_docker:384 time.sleep(2)385 out = ops1.libs.vtysh.show_running_config()386 assert('test4' in out['access-list']['ip'])387 aces = out['access-list']['ip']['test4']['aces']388 assert(len(aces) == 1)389 ace = out['access-list']['ip']['test4']['aces'][0]390 assert(ace['seq'] == '12')391 assert(ace['src_lt'] == '10')392 with ops1.libs.vtysh.ConfigInterface('12') as ctx:393 ctx.apply_access_list('ip', 'test4', 'in')394 if in_docker:395 time.sleep(2)396 out = ops1.libs.vtysh.show_access_list_commands('ip')397 acl = out['access-list']['ip']['test4']398 assert(acl['applied'] == 'yes')399 with ops1.libs.vtysh.ConfigInterface('12') as ctx:400 ctx.no_apply_access_list('ip', 'test4', 'in')401 if in_docker:402 time.sleep(2)403 out = ops1.libs.vtysh.show_access_list_commands('ip')404 acl = out['access-list']['ip']['test4']405 assert('applied' not in acl)406 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:407 ctx.no('12')408 if in_docker:409 time.sleep(2)410 out = ops1.libs.vtysh.show_running_config()411 aces = out['access-list']['ip']['test4']['aces']412 assert(len(aces) == 0)413 step('################ T13 Apply ACL ###########')414 step('################ to interface ###############')415 step('################ sctp range L4 ###############')416 step('################ EchoCommandException ###############')417 with raises(exceptions.EchoCommandException):418 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:419 ctx.permit(420 '',421 '13', 'sctp', '1.2.3.4/1', 'range 100 500',422 '5.6.7.8/32', 'range 40 50')423 out = ops1.libs.vtysh.show_running_config()424 assert('test4' in out['access-list']['ip'])425 aces = out['access-list']['ip']['test4']['aces']426 assert(len(aces) == 1)427 ace = out['access-list']['ip']['test4']['aces'][0]428 assert(ace['seq'] == '13')429 assert(ace['src_range'] == '100 500')430 assert(ace['dst_op'] == 'range 40 50')431 with ops1.libs.vtysh.ConfigInterface('13') as ctx:432 ctx.apply_access_list('ip', 'test4', 'in')433 if in_docker:434 time.sleep(2)435 out = ops1.libs.vtysh.show_access_list_commands('ip')436 acl = out['access-list']['ip']['test4']437 assert(acl['applied'] == 'yes')438 with ops1.libs.vtysh.ConfigInterface('13') as ctx:439 ctx.no_apply_access_list('ip', 'test4', 'in')440 if in_docker:441 time.sleep(2)442 out = ops1.libs.vtysh.show_access_list_commands('ip')443 acl = out['access-list']['ip']['test4']444 assert('applied' not in acl)445 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:446 ctx.no('13')447 if in_docker:448 time.sleep(2)449 out = ops1.libs.vtysh.show_running_config()450 aces = out['access-list']['ip']['test4']['aces']451 assert(len(aces) == 0)452 step('################ T14 Apply ACL ###########')453 step('################ to interface tcp ###############')454 step('################ 6(UnknownCommand) eq L4 ###############')455 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:456 ctx.deny(457 '',458 '14', 'tcp', '1.2.3.4/8', 'eq 4',459 '5.6.7.8/24', 'eq 40')460 if in_docker:461 time.sleep(2)462 out = ops1.libs.vtysh.show_running_config()463 assert('test4' in out['access-list']['ip'])464 aces = out['access-list']['ip']['test4']['aces']465 assert(len(aces) == 1)466 ace = out['access-list']['ip']['test4']['aces'][0]467 assert(ace['seq'] == '14')468 assert(ace['src_eq'] == '4')469 with ops1.libs.vtysh.ConfigInterface('14') as ctx:470 ctx.apply_access_list('ip', 'test4', 'in')471 if in_docker:472 time.sleep(2)473 out = ops1.libs.vtysh.show_access_list_commands('ip')474 acl = out['access-list']['ip']['test4']475 assert(acl['applied'] == 'yes')476 with ops1.libs.vtysh.ConfigInterface('14') as ctx:477 ctx.no_apply_access_list('ip', 'test4', 'in')478 if in_docker:479 time.sleep(2)480 out = ops1.libs.vtysh.show_access_list_commands('ip')481 acl = out['access-list']['ip']['test4']482 assert('applied' not in acl)483 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:484 ctx.no('14')485 if in_docker:486 time.sleep(2)487 out = ops1.libs.vtysh.show_running_config()488 aces = out['access-list']['ip']['test4']['aces']489 assert(len(aces) == 0)490 step('################ T15 Apply ACL ###########')491 step('################ to interface tcp ###############')492 step('################ range L4 ###############')493 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:494 ctx.deny(495 '',496 '15', 'tcp', '1.2.3.4/8', 'range 4 6',497 '5.6.7.8/24', 'range 40 60')498 if in_docker:499 time.sleep(2)500 out = ops1.libs.vtysh.show_running_config()501 assert('test4' in out['access-list']['ip'])502 aces = out['access-list']['ip']['test4']['aces']503 assert(len(aces) == 1)504 ace = out['access-list']['ip']['test4']['aces'][0]505 assert(ace['seq'] == '15')506 assert(ace['dst_range'] == '40 60')507 with ops1.libs.vtysh.ConfigInterface('15') as ctx:508 ctx.apply_access_list('ip', 'test4', 'in')509 if in_docker:510 time.sleep(2)511 out = ops1.libs.vtysh.show_access_list_commands('ip')512 acl = out['access-list']['ip']['test4']513 assert(acl['applied'] == 'yes')514 with ops1.libs.vtysh.ConfigInterface('15') as ctx:515 ctx.no_apply_access_list('ip', 'test4', 'in')516 if in_docker:517 time.sleep(2)518 out = ops1.libs.vtysh.show_access_list_commands('ip')519 acl = out['access-list']['ip']['test4']520 assert('applied' not in acl)521 with ops1.libs.vtysh.ConfigAccessListIp('test4') as ctx:522 ctx.no('15')523 if in_docker:524 time.sleep(2)525 out = ops1.libs.vtysh.show_running_config()526 aces = out['access-list']['ip']['test4']['aces']...

Full Screen

Full Screen

docker_test.py

Source:docker_test.py Github

copy

Full Screen

...49 ):50 assert docker.get_docker_user() == ()51def test_in_docker_no_file():52 with mock.patch.object(builtins, 'open', side_effect=FileNotFoundError):53 assert docker._is_in_docker() is False54def _mock_open(data):55 return mock.patch.object(56 builtins,57 'open',58 new_callable=mock.mock_open,59 read_data=data,60 )61def test_in_docker_docker_in_file():62 with _mock_open(DOCKER_CGROUP_EXAMPLE):63 assert docker._is_in_docker() is True64def test_in_docker_docker_not_in_file():65 with _mock_open(NON_DOCKER_CGROUP_EXAMPLE):66 assert docker._is_in_docker() is False67def test_get_container_id():68 with _mock_open(DOCKER_CGROUP_EXAMPLE):69 assert docker._get_container_id() == CONTAINER_ID70def test_get_container_id_failure():71 with _mock_open(b''), pytest.raises(RuntimeError):72 docker._get_container_id()73def test_get_docker_path_not_in_docker_returns_same():74 with mock.patch.object(docker, '_is_in_docker', return_value=False):75 assert docker._get_docker_path('abc') == 'abc'76@pytest.fixture77def in_docker():78 with mock.patch.object(docker, '_is_in_docker', return_value=True):79 with mock.patch.object(80 docker, '_get_container_id', return_value=CONTAINER_ID,81 ):82 yield83def _linux_commonpath():84 return mock.patch.object(os.path, 'commonpath', posixpath.commonpath)85def _nt_commonpath():86 return mock.patch.object(os.path, 'commonpath', ntpath.commonpath)87def _docker_output(out):88 ret = (0, out, b'')89 return mock.patch.object(docker, 'cmd_output_b', return_value=ret)90def test_get_docker_path_in_docker_no_binds_same_path(in_docker):91 docker_out = json.dumps([{'Mounts': []}]).encode()92 with _docker_output(docker_out):93 assert docker._get_docker_path('abc') == 'abc'94def test_get_docker_path_in_docker_binds_path_equal(in_docker):95 binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}]96 docker_out = json.dumps([{'Mounts': binds_list}]).encode()97 with _linux_commonpath(), _docker_output(docker_out):98 assert docker._get_docker_path('/project') == '/opt/my_code'99def test_get_docker_path_in_docker_binds_path_complex(in_docker):100 binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}]101 docker_out = json.dumps([{'Mounts': binds_list}]).encode()102 with _linux_commonpath(), _docker_output(docker_out):103 path = '/project/test/something'104 assert docker._get_docker_path(path) == '/opt/my_code/test/something'105def test_get_docker_path_in_docker_no_substring(in_docker):106 binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}]107 docker_out = json.dumps([{'Mounts': binds_list}]).encode()108 with _linux_commonpath(), _docker_output(docker_out):109 path = '/projectSuffix/test/something'110 assert docker._get_docker_path(path) == path111def test_get_docker_path_in_docker_binds_path_many_binds(in_docker):112 binds_list = [113 {'Source': '/something_random', 'Destination': '/not-related'},114 {'Source': '/opt/my_code', 'Destination': '/project'},115 {'Source': '/something-random-2', 'Destination': '/not-related-2'},116 ]117 docker_out = json.dumps([{'Mounts': binds_list}]).encode()118 with _linux_commonpath(), _docker_output(docker_out):119 assert docker._get_docker_path('/project') == '/opt/my_code'120def test_get_docker_path_in_docker_windows(in_docker):121 binds_list = [{'Source': r'c:\users\user', 'Destination': r'c:\folder'}]122 docker_out = json.dumps([{'Mounts': binds_list}]).encode()123 with _nt_commonpath(), _docker_output(docker_out):124 path = r'c:\folder\test\something'125 expected = r'c:\users\user\test\something'126 assert docker._get_docker_path(path) == expected127def test_get_docker_path_in_docker_docker_in_docker(in_docker):128 # won't be able to discover "self" container in true docker-in-docker129 err = CalledProcessError(1, (), 0, b'', b'')130 with mock.patch.object(docker, 'cmd_output_b', side_effect=err):...

Full Screen

Full Screen

database.py

Source:database.py Github

copy

Full Screen

1import motor.motor_asyncio2import os3# VERIFICA SE ESTÁ DENTRO DO DOCKER E ALTERA O NOME DO HOST4IN_DOCKER = os.environ.get('IN_DOCKER', False)5MONGO_DETAILS = f"mongodb://{'mongo' if IN_DOCKER else 'localhost'}:27017"6client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_DETAILS)7database = client.local8# Inicia as collections9endereco_collection = database.get_collection("endereco")...

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