How to use test_invalid_request_method method in Django Test Plus

Best Python code snippet using django-test-plus_python

tests-Richard’s MacBook Pro.py

Source:tests-Richard’s MacBook Pro.py Github

copy

Full Screen

...10 self.assertEqual('HTTP/1.0', request.version)11 def invalid_request_method(self):12 request_string = "GE http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n\r\n"13 request = server.Request(request_string)14 def test_invalid_request_method(self):15 self.assertRaises(server.InvalidRequestFormat, self.invalid_request_method)16 def invalid_version(self):17 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.1\r\n\r\n"18 request = server.Request(request_string)19 def test_invalid_version(self):20 self.assertRaises(server.InvalidRequestFormat, self.invalid_version)21 def invalid_request_line(self):22 request_string = "GEThttp://www.cs.utah.edu/~kobus/simple.html HTTP/1.1\r\n\r\n"23 request = server.Request(request_string)24 def test_invalid_request_line(self):25 self.assertRaises(server.InvalidRequestFormat, self.invalid_request_line)26 def test_wrong_request_method(self):27 request_string = "POST http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n\r\n"28 request = server.Request(request_string)29 self.assertEqual(501, request.status)30 def test_valid_host_uri_port(self):31 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n\r\n"32 request = server.Request(request_string)33 self.assertEqual('www.cs.utah.edu', request.host)34 self.assertEqual('/~kobus/simple.html', request.uri)35 self.assertEqual(80, request.port)36 def test_valid_inline_port(self):37 request_string = "GET http://www.cs.utah.edu:8000/~kobus/simple.html HTTP/1.0\r\n\r\n"38 request = server.Request(request_string)39 self.assertEqual(8000, request.port)40 # need to test invalid hostname41 # def invalid_url(self):42 # request_string = "GET hp:/blahblahblah/23458568~kobus/simple.html HTTP/1.0\r\n\r\n"43 # request = server.Request(request_string)44 #45 # def test_invalid_url(self):46 # self.assertRaises(server.InvalidRequestUrl, self.invalid_url)47 def test_valid_headers(self):48 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \49 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" \50 "\r\n"51 request = server.Request(request_string)52 valid_header_dict = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'}53 self.assertEqual(valid_header_dict, request.headers)54 def invalid_header(self):55 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \56 "Accept text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" \57 "\r\n"58 request = server.Request(request_string)59 def test_invalid_header(self):60 self.assertRaises(server.InvalidRequestHeader, self.invalid_header)61 def invalid_request_format(self):62 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \63 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n"64 request = server.Request(request_string)65 def test_invalid_request_format(self):66 self.assertRaises(server.InvalidRequestFormat, self.invalid_request_format)67 def invalid_request_format2(self):68 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n"69 request = server.Request(request_string)70 def test_invalid_request_format2(self):71 self.assertRaises(server.InvalidRequestFormat, self.invalid_request_format2)72 def test_forward_request_string(self):73 request_string = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \74 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" \75 "\r\n"76 request = server.Request(request_string)77 valid_forward_request_string = "GET /~kobus/simple.html HTTP/1.0\r\n" \78 "Connection: close\r\n" \79 "Host: www.cs.utah.edu\r\n" \80 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" \81 "\r\n"82 request.set_forward_request_string()83 self.assertEqual(valid_forward_request_string, request.forward_request)84class ResponseClassTests(unittest.TestCase):85 def test_valid_response(self):86 response_string = "" \87 "HTTP/1.0 200 OK\r\n" \88 "Server: SimpleHTTP/0.6 Python/2.7.16\r\n" \89 "Date: Sat, 08 Feb 2020 17:22:05 GMT\r\n" \90 "Content-type: text/html\r\n" \91 "Content-Length: 102\r\n" \92 "Last-Modified: Mon, 20 Jan 2020 23:39:28 GMT\r\n" \93 "\r\n" \94 "<!DOCTYPE html>\n" \95 "<html>\n" \96 "<body>\n\n" \97 "<h1>My First Heading</h1>\n\n" \98 "<p>My first paragraph.</p>\n\n" \99 "</body>\n" \100 "</html>\n"101 response = server.Response(response_string)102 test_content = "<!DOCTYPE html>\n" \103 "<html>\n" \104 "<body>\n\n" \105 "<h1>My First Heading</h1>\n\n" \106 "<p>My first paragraph.</p>\n\n" \107 "</body>\n" \108 "</html>\n"109 self.assertEqual(test_content, response.content)110 def test_valid_response(self):111 response_string = "" \112 "HTTP/1.0 400 Bad Request\r\n\r\n"113 response = server.Response(response_string)114 self.assertEqual('HTTP/1.0', response.version)115 self.assertEqual(400, response.status)116 self.assertEqual('Bad Request', response.message)117 # def invalid_response(self):118 # response_string = "" \119 # "HTTP/1.0 200 OK\r\n" \120 # "Server: SimpleHTTP/0.6 Python/2.7.16\r\n" \121 # "Date: Sat, 08 Feb 2020 17:22:05 GMT\r\n" \122 # "Content-type: text/html\r\n" \123 # "Last-Modified: Mon, 20 Jan 2020 23:39:28 GMT\r\n" \124 # "\r\n" \125 # "<!DOCTYPE html>\n" \126 # "<html>\n" \127 # "<body>\n\n" \128 # "<h1>My First Heading</h1>\n\n" \129 # "<p>My first paragraph.</p>\n\n" \130 # "</body>\n" \131 # "</html>\n"132 # response = server.Response(response_string)133 #134 # def test_invalid_response(self):135 # self.assertRaises(server.InvalidResponse, self.invalid_response)136 def invalid_response2(self):137 response_string = "" \138 "HTTP/1.0\r\n\r\n"139 response = server.Response(response_string)140 def test_invalid_response2(self):141 self.assertRaises(server.InvalidResponse, self.invalid_response2)142def test_invalid_response(self):143 self.assertRaises(server.InvalidResponse, self.invalid_response)144 def test_nonvirus_file(self):145 server.Constants.apikey = '8d7036a42ebdbb676512461fcc426ce05d3f155d1f8770dade62190da3a223aa'146 response_string = "" \147 "HTTP/1.0 200 OK\r\n" \148 "Server: SimpleHTTP/0.6 Python/2.7.16\r\n" \149 "Date: Sat, 08 Feb 2020 17:22:05 GMT\r\n" \150 "Content-type: text/html\r\n" \151 "Content-Length: 102\r\n" \152 "Last-Modified: Mon, 20 Jan 2020 23:39:28 GMT\r\n" \153 "\r\n" \154 "<!DOCTYPE html>\n" \155 "<html>\n" \156 "<body>\n\n" \157 "<h1>My First Heading</h1>\n\n" \158 "<p>My first paragraph.</p>\n\n" \159 "</body>\n" \160 "</html>\n"161 response = server.Response(response_string)162 is_virus = response.virus_check()163 self.assertFalse(is_virus)164 def test_nonregistered_file(self):165 server.Constants.apikey = '8d7036a42ebdbb676512461fcc426ce05d3f155d1f8770dade62190da3a223aa'166 response_string = "" \167 "HTTP/1.0 200 OK\r\n" \168 "Server: SimpleHTTP/0.6 Python/2.7.16\r\n" \169 "Date: Sat, 08 Feb 2020 17:22:05 GMT\r\n" \170 "Content-type: text/html\r\n" \171 "Content-Length: 102\r\n" \172 "Last-Modified: Mon, 20 Jan 2020 23:39:28 GMT\r\n" \173 "\r\n" \174 "blah blah blah this is a random test"175 response = server.Response(response_string)176 is_virus = response.virus_check()177 self.assertFalse(is_virus)178class MyTests(unittest.TestCase):179 def test_valid_new_request(self):180 request = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n\r\n"181 new_request = "GET /~kobus/simple.html HTTP/1.0\r\nConnection: close\r\nHost: www.cs.utah.edu\r\n\r\n"182 lines = request.split('\r\n')183 valid_new_request, host, port = server.create_new_request(lines)184 print(valid_new_request)185 self.assertEqual(new_request, valid_new_request)186 def test_valid_new_request_2(self):187 request = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \188 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" \189 "\r\n"190 new_request = \191 "GET /~kobus/simple.html HTTP/1.0\r\n" \192 "Connection: close\r\n" \193 "Host: www.cs.utah.edu\r\n" \194 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" \195 "\r\n"196 lines = request.split('\r\n')197 valid_new_request, host, port = server.create_new_request(lines)198 print(valid_new_request)199 self.assertEqual(new_request, valid_new_request)200 def test_valid_request(self):201 request = "GET http://google.com/ HTTP/1.0\r\n"202 response = server.get_forward_response(request)203 print(response)204 def test_invalid_request(self):205 request = "GET http://www.cs.utah.edu/~kobus/simple.html\r\n\r\n"206 response = server.get_forward_response(request)207 self.assertEqual(response, server.Constants.response_400)208 def test_invalid_request_2(self):209 request = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \210 "Connection: Keep-Alive"211 response = server.get_forward_response(request)212 self.assertEqual(response, server.Constants.response_400)213 def test_invalid_request_3(self):214 request = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.1\r\n\r\n"215 response = server.get_forward_response(request)216 self.assertEqual(response, server.Constants.response_400)217 def test_invalid_request_4(self):218 request = "GE http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n\r\n"219 response = server.get_forward_response(request)220 self.assertEqual(response, server.Constants.response_400)221 # def test_invalid_request_method(self):222 # request = "POST http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n"223 # response = server.get_forward_response(request)224 # self.assertEqual(response, server.Constants.response_501)225 def test_invalid_request_header(self):226 request = "GET http://www.cs.utah.edu/~kobus/simple.html HTTP/1.0\r\n" \227 "Connection \r\n\r\n"228 response = server.get_forward_response(request)229 self.assertEqual(response, server.Constants.response_400)230if __name__ == '__main__':...

Full Screen

Full Screen

test_views.py

Source:test_views.py Github

copy

Full Screen

...49 limit = random.randint(1, 10)50 offset = random.randint(1, 10)51 response = client.get('/api/get-weather-data/', data = {'limit' : limit, 'offset' : offset, 'region': 'India', 'parameter': 'Rainfall'}, format='json')52 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)53 def test_invalid_request_method(self):54 response = client.post('/api/get-weather-data/', data = {'limit' : 10, 'offset' : 10, 'region': 'England', 'parameter': 'Rainfall'}, format='json')...

Full Screen

Full Screen

test_api.py

Source:test_api.py Github

copy

Full Screen

...69 response = client.post(endpoint, json=ticket)70 assert response.content_type == 'application/json'71 assert response.status_code == 40072 assert response.json == 'No parcel found with tracking number: 3SXBTA3091265'73def test_invalid_request_method(client):74 response = client.get(endpoint)75 assert response.content_type == 'application/json'76 assert response.status_code == 40577 assert response.json == {78 "message": "The method is not allowed for the requested URL."...

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 Django Test Plus 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