How to use unblock method in pytest-django

Best Python code snippet using pytest-django_python

test_rfkill.py

Source:test_rfkill.py Github

copy

Full Screen

...40 raise Exception("RECONNECT accepted while disabled")41 if "FAIL" not in dev[0].request("FETCH_OSU"):42 raise Exception("FETCH_OSU accepted while disabled")43 logger.info("rfkill unblock")44 rfk.unblock()45 dev[0].wait_connected(timeout=10,46 error="Missing connection event on rfkill unblock")47 hwsim_utils.test_connectivity(dev[0], hapd)48 finally:49 rfk.unblock()50def test_rfkill_wpa2_psk(dev, apdev):51 """rfkill block/unblock during WPA2-PSK connection"""52 rfk = get_rfkill(dev[0])53 ssid = "test-wpa2-psk"54 passphrase = 'qwertyuiop'55 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)56 hapd = hostapd.add_ap(apdev[0], params)57 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")58 try:59 logger.info("rfkill block")60 rfk.block()61 dev[0].wait_disconnected(timeout=10,62 error="Missing disconnection event on rfkill block")63 logger.info("rfkill unblock")64 rfk.unblock()65 dev[0].wait_connected(timeout=10,66 error="Missing connection event on rfkill unblock")67 hwsim_utils.test_connectivity(dev[0], hapd)68 finally:69 rfk.unblock()70def test_rfkill_autogo(dev, apdev):71 """rfkill block/unblock for autonomous P2P GO"""72 rfk0 = get_rfkill(dev[0])73 rfk1 = get_rfkill(dev[1])74 dev[0].p2p_start_go()75 dev[1].request("SET p2p_no_group_iface 0")76 dev[1].p2p_start_go()77 try:78 logger.info("rfkill block 0")79 rfk0.block()80 ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)81 if ev is None:82 raise Exception("Group removal not reported")83 if "reason=UNAVAILABLE" not in ev:84 raise Exception("Unexpected group removal reason: " + ev)85 if "FAIL" not in dev[0].request("P2P_LISTEN 1"):86 raise Exception("P2P_LISTEN accepted unexpectedly")87 if "FAIL" not in dev[0].request("P2P_LISTEN"):88 raise Exception("P2P_LISTEN accepted unexpectedly")89 logger.info("rfkill block 1")90 rfk1.block()91 ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)92 if ev is None:93 raise Exception("Group removal not reported")94 if "reason=UNAVAILABLE" not in ev:95 raise Exception("Unexpected group removal reason: " + ev)96 logger.info("rfkill unblock 0")97 rfk0.unblock()98 logger.info("rfkill unblock 1")99 rfk1.unblock()100 time.sleep(1)101 finally:102 rfk0.unblock()103 rfk1.unblock()104def _test_rfkill_p2p_discovery(dev0, dev1):105 """rfkill block/unblock P2P Discovery"""106 rfk0 = get_rfkill(dev0)107 rfk1 = get_rfkill(dev1)108 try:109 addr0 = dev0.p2p_dev_addr()110 logger.info("rfkill block 0")111 rfk0.block()112 logger.info("rfkill block 1")113 rfk1.block()114 for i in range(10):115 time.sleep(0.1)116 if dev0.get_status_field("wpa_state") == "INTERFACE_DISABLED" and dev1.get_status_field("wpa_state") == "INTERFACE_DISABLED":117 break118 if "OK" in dev0.p2p_listen():119 raise Exception("P2P Listen success although in rfkill")120 if "OK" in dev1.p2p_find():121 raise Exception("P2P Find success although in rfkill")122 dev0.dump_monitor()123 dev1.dump_monitor()124 logger.info("rfkill unblock 0")125 rfk0.unblock()126 logger.info("rfkill unblock 1")127 rfk1.unblock()128 for i in range(10):129 time.sleep(0.1)130 if dev0.get_status_field("wpa_state") != "INTERFACE_DISABLED" and dev1.get_status_field("wpa_state") != "INTERFACE_DISABLED":131 break132 if not "OK" in dev0.p2p_listen():133 raise Exception("P2P Listen failed after unblocking rfkill")134 if not dev1.discover_peer(addr0, social=True):135 raise Exception("Failed to discover peer after unblocking rfkill")136 finally:137 rfk0.unblock()138 rfk1.unblock()139 dev0.p2p_stop_find()140 dev1.p2p_stop_find()141 dev0.dump_monitor()142 dev1.dump_monitor()143def test_rfkill_p2p_discovery(dev, apdev):144 """rfkill block/unblock P2P Discovery"""145 _test_rfkill_p2p_discovery(dev[0], dev[1])146def test_rfkill_p2p_discovery_p2p_dev(dev, apdev):147 """rfkill block/unblock P2P Discovery with P2P Device"""148 with HWSimRadio(use_p2p_device=True) as (radio, iface):149 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')150 wpas.interface_add(iface)151 _test_rfkill_p2p_discovery(dev[0], wpas)152 _test_rfkill_p2p_discovery(wpas, dev[1])153def test_rfkill_hostapd(dev, apdev):154 """rfkill block/unblock during and prior to hostapd operations"""155 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })156 rfk = get_rfkill(hapd)157 try:158 rfk.block()159 ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=5)160 if ev is None:161 raise Exception("INTERFACE-DISABLED event not seen")162 rfk.unblock()163 ev = hapd.wait_event(["INTERFACE-ENABLED"], timeout=5)164 if ev is None:165 raise Exception("INTERFACE-ENABLED event not seen")166 # hostapd does not current re-enable beaconing automatically167 hapd.disable()168 hapd.enable()169 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")170 rfk.block()171 ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=5)172 if ev is None:173 raise Exception("INTERFACE-DISABLED event not seen")174 dev[0].wait_disconnected(timeout=10)175 dev[0].request("DISCONNECT")176 hapd.disable()177 hglobal = HostapdGlobal(apdev[0])178 hglobal.flush()179 hglobal.remove(apdev[0]['ifname'])180 hapd = hostapd.add_ap(apdev[0], { "ssid": "open2" },181 no_enable=True)182 if "FAIL" not in hapd.request("ENABLE"):183 raise Exception("ENABLE succeeded unexpectedly (rfkill)")184 finally:185 rfk.unblock()186def test_rfkill_wpas(dev, apdev):187 """rfkill block prior to wpa_supplicant start"""188 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')189 wpas.interface_add("wlan5")190 rfk = get_rfkill(wpas)191 wpas.interface_remove("wlan5")192 try:193 rfk.block()194 wpas.interface_add("wlan5")195 time.sleep(0.5)196 state = wpas.get_status_field("wpa_state")197 if state != "INTERFACE_DISABLED":198 raise Exception("Unexpected state with rfkill blocked: " + state)199 rfk.unblock()200 time.sleep(0.5)201 state = wpas.get_status_field("wpa_state")202 if state == "INTERFACE_DISABLED":203 raise Exception("Unexpected state with rfkill unblocked: " + state)204 finally:...

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 pytest-django 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