Best Python code snippet using molotov_python
client.py
Source: client.py
...46}47#############################48### Funciones ###49#############################50def print_request(response):51 print("Código de estado: {}".format(response.status_code))52 print(response.text)53#############################54### Historias de usuario ###55#############################56# Ruta inicial de bienvenida57print("Ruta iniciial de bienvenida")58print_request(requests.get(RUTA + "/"))59# [HU1] Como administrador quiero dar de alta una asignatura60print("[HU1] Como administrador quiero dar de alta una asignatura")61print_request(requests.post(RUTA + "/asignaturas", json.dumps(asignatura), headers=PARAM))62# [HU2] Como administrador quiero modificar una asignatura63print("[HU2] Como administrador quiero modificar una asignatura")64print_request(requests.put(RUTA + "/asignaturas/001", json.dumps(asignatura2), headers=PARAM))65# [HU3] Como administrador quiero borrar una asignatura66print("[HU3] Como administrador quiero borrar una asignatura")67print_request(requests.delete(RUTA + "/asignaturas/001"))68# [HU4] Como alumno quiero matricularme de ciertas asignaturas69print("[HU4] Como alumno quiero matricularme de ciertas asignaturas")70print_request(requests.post(RUTA + "/alumnos/74585246H/asignaturas",71 json.dumps({"nombre_asignatura": "Lenguaje Musical"}),72 headers=PARAM))73# [HU5] Como alumno quiero desmatricularme de ciertas asignaturas74print("[HU5] Como alumno quiero desmatricularme de ciertas asignaturas")75print_request(requests.delete(RUTA + "/alumnos/74585246H/asignaturas/Coro"))76# [HU6] Como alumno consultar mis asignaturas matriculadas77print("[HU6] Como alumno consultar mis asignaturas matriculadas")78print_request(requests.get(RUTA + "/alumnos/74585246H/asignaturas"))79# [HU7] Como alumno quiero modificar la dirección de correo80print("[HU7] Como alumno quiero modificar la dirección de correo")81print_request(requests.put(RUTA + "/alumnos/74585246H",82 json.dumps({"email": "otroemail@gmail.com"}),83 headers=PARAM))84# [HU8] Como alumno quiero consultar el horario de una asignatura85print("[HU8] Como alumno quiero consultar el horario de una asignatura")86print_request(requests.get(RUTA + "/alumnos/75931715K/asignaturas/Coro/horario"))87# [HU9] Como alumno quiero consultar el aula de una asignatura88print("[HU9] Como alumno quiero consultar el aula de una asignatura")89print_request(requests.get(RUTA + "/alumnos/75931715K/asignaturas/Coro/aula"))90# [HU10] Como alumno quiero saber mi horario completo91print("[HU10] Como alumno quiero saber mi horario completo")92print_request(requests.get(RUTA + "/alumnos/75931715K/horario"))93# [HU11] Como administrador quiero saber en el número de alumnos y asignaturas del conservatorio94print("[HU11] Como administrador quiero saber en el número de alumnos y asignaturas del conservatorio")95print_request(requests.get(RUTA + "/alumnos/num"))96print_request(requests.get(RUTA + "/asignaturas/num"))97# [HU12] Como administrador quiero saber las asignaturas que imparte un profesor98print("[HU12] Como administrador quiero saber las asignaturas que imparte un profesor")99print_request(requests.get(RUTA + "/profesor/Javi/asignaturas"))100# [HU13] Como administrador quiero saber el horario completo de un profesor101print("[HU13] Como administrador quiero saber el horario completo de un profesor")102print_request(requests.get(RUTA + "/profesor/Javi/horario"))103# [HU14] Como administrador quiero saber las aulas que usa un profesor104print("[HU14] Como administrador quiero saber las aulas que usa un profesor")105print_request(requests.get(RUTA + "/profesor/Javi/aula"))106# [HU15] Como administrador quiero dar de alta un alumno107print("[HU15] Como administrador quiero dar de alta un alumno")108print_request(requests.post(RUTA + "/alumnos",109 json.dumps(alumno),110 headers=PARAM))111# [HU16] Como administrador quiero obtener un listado de los alumnos y su información112print("[HU16] Como administrador quiero obtener un listado de los alumnos y su información")113print_request(requests.get(RUTA + "/alumnos"))114# [HU17] Como administrador quiero obtener un listado de las asignaturas y su información115print("[HU17] Como administrador quiero obtener un listado de las asignaturas y su información")...
testData.py
Source: testData.py
1import requests2def print_request(r):3 print(" status:" + str(r.status_code))4 print(" text:" + r.text)5def main():6 # URL7 base = "http://127.0.0.1:9080"8 # Timeout9 timeout_ms = 500010 # Headers11 h = {'Content-type': 'application/json'}12 # Add a profile13 print("Add profile")14 j = {"name": "I am profile", "description": "This is my description"}15 r = requests.post(base + "/profiles/add", json=j, headers=h)16 print_request(r)17 # Add a zone to that profile18 print("Add Zone to profile 1")19 j = {"name": "I am Zone"}20 r = requests.post(base + "/profiles/1/zones/add", json=j, headers=h, timeout=timeout_ms)21 print_request(r)22 # Add an LED state23 print("Add LED State 1")24 j = {25 "r": 255,26 "g": 0,27 "b": 0,28 "intensity":80,29 "power":True30 }31 r = requests.post(base + "/led_states/add", json=j, headers=h, timeout=timeout_ms)32 print_request(r)33 # Add another LED state34 print("Add LED State 2")35 j = {36 "r": 0,37 "g": 255,38 "b": 0,39 "intensity":70,40 "power":True41 }42 r = requests.post(base + "/led_states/add", json=j, headers=h, timeout=timeout_ms)43 print_request(r)44 # Add a daily state45 print("Add Daily State")46 j = {47 "timeStateMap":48 [49 {"time":28800,"state":1}, #8 am50 {"time":64800,"state":2} #6 pm51 ]52 }53 r = requests.post(base + "/daily_states/add", json=j, headers=h, timeout=timeout_ms)54 print_request(r)55 # Add a controller56 print("Add Controller 1")57 j = {58 "io": 0,59 "address":"blahblah",60 "details":""61 }62 r = requests.post(base + "/controllers/add", json=j, headers=h, timeout=timeout_ms)63 print_request(r)64 # Add LEDs to controller 165 n = 1066 print("Adding {} LEDs".format(n))67 for i in range(n):68 print("Add LED {}".format(i))69 j = {70 "strip_idx":(i+1),71 "controller":172 }73 r = requests.post(base + "/leds/add", json=j, headers=h, timeout=timeout_ms)74 print_request(r)75 # Add LEDs to zone 176 print("Add LEDs to Zone 1")77 j = range(1,n+1)78 r = requests.put(base + "/profiles/1/zones/1/leds/add", json=j, headers=h, timeout=timeout_ms)79 print_request(r)80 # Add DailyState 1 to Zone 1 on day 2 (Tuesday)81 print("Add DailyState to Zone (Tuesday)")82 r = requests.put(base + "/profiles/1/zones/1/day/2/add/1", timeout=timeout_ms)83 print_request(r)84 # Get active state for zone 1 (Varies based on time)85 print("Get active state for zone 1")86 print("If currently after Tuesday 6pm, will return LEDState ID 2")87 print("If before Tuesday 6pm and after Tuesday 8am, will return LEDState ID 1")88 r = requests.get(base + "/profiles/1/zones/1/active_state", timeout=timeout_ms)89 print_request(r)...
test.py
Source: test.py
1import requests2def print_request(r):3 print(" status:" + str(r.status_code))4 print(" text:" + r.text)5def main():6 # URL7 base = "http://localhost:9080"8 # Headers9 h = {'Content-type': 'application/json'}10 print("Get profiles")11 r = requests.get(base + "/profiles", "")12 print_request(r)13 print("Add profile")14 j = {"name": "Test Profile 1", "description": "Potatoes 2"}15 r = requests.post(base + "/profiles/add", json=j, headers=h, timeout=2)16 print_request(r)17 print("Get profiles")18 r = requests.get(base + "/profiles", "")19 print_request(r)20 print("Add Zone to profile 1")21 j = {"name": "Zone 1"}22 r = requests.post(base + "/profiles/1/zones/add", json=j, headers=h, timeout=200)23 print_request(r)24 print("Add Controler")25 j = {"io": 1}26 r = requests.post(base +"/controllers/add", json=j, headers=h)27 print_request(r)28 for i in range(10):29 print("Add LEDS")30 j = {"strip_idx": i, "controller": 1}31 r = requests.post(base + "/leds/add", json=j, headers=h)32 print_request(r)33 print("Add LEDS to Zone1")34 j = range(1,11)35 r = requests.put(base + "/profiles/1/zones/1/leds/add", json=j, headers=h)36 print_request(r)37 print("add LED states")38 j = {39 "r": 255,40 "g": 255,41 "b": 255,42 "intensity": 100,43 "power": True44 }45 r = requests.post(base + "/led_states/add", json=j, headers=h)46 print_request(r)47 print("add LED2 states")48 j = {49 "r": 255,50 "g": 0,51 "b": 0,52 "intensity": 100,53 "power": True54 }55 r = requests.post(base + "/led_states/add", json=j, headers=h)56 print("Add daily state")57 j = [{"time":0, "state":1},{"time":61200, "state":2}]58 r = requests.post(base + "/daily_states/add", json=j, headers=h)59 print_request(r)60 print("Assign daily state to zone")61 r = requests.put(base + "/profiles/1/zones/1/day/0/add/1")62 print_request(r)63 print("add LED states")64 j = {65 "r": 255,66 "g": 255,67 "b": 255,68 "intensity": 100,69 "power": True70 }71 r = requests.post(base + "/led_states/add", json=j, headers=h)72 print_request(r)73 print("add LED2 states")74 j = {75 "r": 255,76 "g": 0,77 "b": 0,78 "intensity": 100,79 "power": True80 }81 r = requests.post(base + "/led_states/add", json=j, headers=h)82 print_request(r)83 print("Add daily state")84 j = [{"time":0, "state":1},{"time":58500, "state":2}]85 r = requests.post(base + "/daily_states/add", json=j, headers=h)86 print_request(r)87 print("Get profiles")88 r = requests.get(base + "/profiles", "")89 print_request(r)...
Check out the latest blogs from LambdaTest on this topic:
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
The best agile teams are built from people who work together as one unit, where each team member has both the technical and the personal skills to allow the team to become self-organized, cross-functional, and self-motivated. These are all big words that I hear in almost every agile project. Still, the criteria to make a fantastic agile team are practically impossible to achieve without one major factor: motivation towards a common goal.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.
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!!