Best Python code snippet using localstack_python
test_task.py
Source:test_task.py
2from random import randint3from task import start_dns_server, add_to_dns, dns_lookup4class TestCase(unittest.TestCase):5 def test_create_dns_dict_type(self):6 dns = start_dns_server()7 self.assertEqual(type(dns), dict)8 def test_create_network_three_records(self):9 dns = start_dns_server()10 self.assertEqual(len(dns), 3)11 def test_add_server_dict_type(self):12 dns = start_dns_server()13 self.assertEqual(type(dns), dict)14 random_ip = str(randint(2, 254)) # Start at 2 to make 127.0.0.1 impossible15 for i in range(0, 3):16 random_ip += "." + str(randint(1, 254))17 add_to_dns(dns, "Random", random_ip)18 self.assertEqual(type(dns), dict)19 def test_add_server_four_servers(self):20 dns = start_dns_server()21 self.assertEqual(len(dns), 3)22 random_ip = str(randint(2, 254)) # Start at 2 to make 127.0.0.1 impossible23 for i in range(0, 3):24 random_ip += "." + str(randint(1, 254))25 add_to_dns(dns, "Random", random_ip)26 self.assertEqual(len(dns), 4)27 def test_get_record_exists(self):28 dns = start_dns_server()29 random_ip = str(randint(2, 254)) # Start at 2 to make 127.0.0.1 impossible30 for i in range(0, 3):31 random_ip += "." + str(randint(1, 254))32 add_to_dns(dns, "Random", random_ip)33 # Most recent server should be at the end. -1 is needed to avoid an off-by-one error.34 added_server = dns_lookup(dns, "Random")...
google_redirect.py
Source:google_redirect.py
1from socket import socket, AF_INET, SOCK_DGRAM2def start_dns_server(IP: str, PORT: int):3 with socket(AF_INET, SOCK_DGRAM) as s:4 print("[++] Starting DNS server ...")5 s.bind((IP, PORT))6 while True:7 data, conn = s.recvfrom(512)8 parse_dns_req_header(data)9 10def parse_dns_req_header(req: bytes):11 id_ = "".join([hex(v)[2:] for v in req[:2]])12 print(id_)13if __name__ == "__main__":...
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!!