Best Python code snippet using django-test-plus_python
constants.py
Source: constants.py
...72 {73 "description": "Search criterion does not exist",74 "detail": "Search criterion does not exist, should be in ['bh_mass', 'gas_mass', 'dm_mass', 'star_mass', 'bh_mdot']."75 }76def construct_response_404(error_list):77 response = {78 "description": "",79 "content": {80 "application/json": {81 "example": {82 "detail": ""},83 "schema": {84 "$ref": "#/components/schemas/HTTPValidationError"}85 }86 }87 }88 for error in error_list:89 if response["description"] == "":90 response["description"] += response_404[error]["description"]91 else:92 response["description"] += " | " + response_404[error]["description"]93 if response["content"]["application/json"]["example"]["detail"] == "":94 response["content"]["application/json"]["example"]["detail"] += response_404[error]["detail"]95 else:96 response["content"]["application/json"]["example"]["detail"] += " Or " + response_404[error]["detail"]97 return response98response_404["read_snapshot_info"] = construct_response_404(["pig_id"])99response_404["read_snapshot_type_info"] = construct_response_404(["pig_id", "ptype"])100response_404["read_lbt_file"] = construct_response_404(["pig_id", "group_id"])101response_404["read_lbt_by_haloid_list"] = construct_response_404(["pig_id", "haloid_list", "halo_id"])102response_404["read_lbht"] = construct_response_404(["pig_id", "halo_id", "type_id"])103response_404["read_haloid_by_criterion"] = construct_response_404(["pig_id", "ptype", "feature"])104response_404["read_particle_data_by_criterion"] = construct_response_404(["pig_id", "ptype", "feature", "criterion", ])105response_404["read_fofgroup_data"] = construct_response_404(["pig_id", "feature", "group_id"])106response_404["read_fofgroup_data_all"] = construct_response_404(["pig_id", "feature"])107response_404["read_particle_data_by_groupid"] = construct_response_404(["pig_id", "ptype", "feature", "group_id"])108response_404["read_particle_data_by_post_groupid_list"] = construct_response_404(["pig_id", "ptype", "feature", "haloid_list"])109# 200 response description110response_200 = {}111def construct_response_200(description, example, model):112 response = {113 "description": description,114 "content": {115 "application/json": {116 "example": example,117 "schema": {118 "$ref": "#/components/schemas/" + model119 }120 }121 }122 }...
tcpserver.py
Source: tcpserver.py
1#!/usr/bin/python32from socket import *3from datetime import *4def send_back_index():5 f = open("index.html", "r")6 html = f.read()7 return html8def send_back_test():9 f = open("test.html", "r")10 html = f.read()11 return html12def logging(response_code):13 f = open("logfile.log", "a")14 ip_from_client = client_address[0]15 response = modified_message.split(" ")[0:3]16 last_line_reponse = response[-1][0:10]17 response.pop()18 response.append(last_line_reponse)19 print(response)20 print(client_address)21 if(response_code == response_404):22 lengh_packet = str(len(str(send_back_index().encode() + response_404.encode())))23 if(response_code == response_400):24 lengh_packet = str(len(str(send_back_index().encode() + response_400.encode())))25 if(response_code == response_200):26 lengh_packet = str(len(str(send_back_index().encode() + response_200.encode())))27 f.write(str(ip_from_client + " "))28 f.write("-- ")29 f.write(str(datetime.now()) + " ")30 f.write(str(response) + " ")31 new_respose_code = response_code.strip()32 f.write(new_respose_code)33 f.write(" " + lengh_packet + "\n")34 35server_port = 814236server_socket = socket(AF_INET,SOCK_STREAM)37#server_socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)38server_socket.bind(('',server_port))39server_socket.listen(1)40print("The server is ready to receive")41while True:42 conn_socket,client_address = server_socket.accept()43 modified_message = conn_socket.recv(2048).decode().upper()44 #conn_socket.send(modified_message.encode())45 print("incoming ip:",client_address)46 print("connection received from {}, and {} is sent back".format(client_address[1],modified_message))47 response_200 = "HTTP/1.1 200 OK\r\n\r\n"48 response_400 = "HTTP/1.1 400 Bad Request\r\n\r\n"49 response_404 = "HTTP/1.1 404 Not Found\r\n\r\n"50 if modified_message.split(" ")[1] == "/":51 conn_socket.send((response_200).encode())52 conn_socket.send(send_back_index().encode())53 logging(response_200)54 elif modified_message.split(" ")[1] == "/TEST":55 conn_socket.send((response_200).encode())56 conn_socket.send(send_back_test().encode())57 logging(response_200)58 elif modified_message.split(" ")[0] != "GET":59 conn_socket.send((response_400).encode())60 logging(response_400)61 else:62 conn_socket.send((response_404).encode())63 conn_socket.send(('<html><body><h1>404 Not Found</h1></body></html>').encode())64 logging(response_404)65 conn_socket.close()...
task_5_test_3.py
Source: task_5_test_3.py
1import datetime2import unittest3import urllib.parse4import requests5from main import HerokuApp6class HerokuSetupTest(unittest.TestCase):7 def setUp(self):8 self.app_path = urllib.parse.urljoin(HerokuApp.app_url, "/events")9 def test_retrieve_incorrect(self):10 retrieve_response = requests.get(self.app_path + "/2022-13-22")11 self.assertEqual(retrieve_response.status_code, 400)12 def test_retrieve_404(self):13 # At least one of those should be 404, unless we are really unlucky14 try_dates = ["/1994-12-29", "/1995-11-28", "/2054-01-05", "/2021-02-04"]15 response_404 = None16 for date in try_dates:17 retrieve_response = requests.get(self.app_path + date)18 if retrieve_response.status_code == 404:19 response_404 = retrieve_response20 self.assertEqual(response_404.status_code, 404)21if __name__ == "__main__":...
Check out the latest blogs from LambdaTest on this topic:
“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
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.
While there is a huge demand and need to run Selenium Test Automation, the experts always suggest not to automate every possible test. Exhaustive Testing is not possible, and Automating everything is not sustainable.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
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!!