How to use _send_headers method in autotest

Best Python code snippet using autotest_python

handler.py

Source:handler.py Github

copy

Full Screen

...58 return ('root', args)59 else:60 path = path[1:]61 return (path, args)62 def _send_headers(self, mimetype = 'text/html'):63 self.send_response(200)64 self.send_header('Content-type', mimetype)65 self.end_headers()66 def _get_handler(self, path):67 global handlers68 return handlers.get(path)69 def _handle_files(self, path):70 if path == 'style.css':71 self._send_headers('text/css')72 sendFile(self.wfile, 'html/style.css')73 return True74 elif path == 'js/brv.js':75 self._send_headers('text/javascript')76 sendFile(self.wfile, 'html/js/brv.js')77 return True78 elif path.endswith('.gif'):79 epath = join('html/', path)80 if isfile(epath):81 self._send_headers('image/gif')82 sendFile(self.wfile, epath)83 return True84 return False85 return False86 def do_GET(self):87 act, args = self._parsePath()88 handler = self._get_handler(act)89 if handler is None:90 if self._handle_files(act):91 # it was a file, we're fine92 return93 self._send_headers()94 self.send_error(404, 'Unhandled request')95 print(self.path)96 return97 self._send_headers()98 opts = _parse_args(args)...

Full Screen

Full Screen

MAS_test.py

Source:MAS_test.py Github

copy

Full Screen

1#! /usr/bin/env python2import unittest3from mock import Mock4import socket5import struct6import PyOBEX7from MAP import MAS8class MAS_client_test(unittest.TestCase):9 _mas = None10 _connection_id = None11 def setUp(self):12 13 address = "fake"14 port = 015 self._mas = MAS.Client(address, port)16 def connect(self):17 self._connection_id = PyOBEX.headers.Connection_ID(0x0001)18 response = PyOBEX.responses.ConnectSuccess()19 data = "\xa0\x00\x1f\x10\x00\xff\xfe\xcb\x00\x00\x00\x01\x4a\x00\x13\xbb\x58\x2b\x40\x42\x0c\x11\xdb\xb0\xde\x08\x00\x20\x0c\x9a\x66"20 obex_version, flags, max_packet_length = struct.unpack(">BBH", data[3:7])21 response.obex_version = PyOBEX.common.OBEX_Version()22 response.obex_version.from_byte(obex_version)23 response.flags = flags24 response.max_packet_length = max_packet_length25 response.read_data(data)26 27 PyOBEX.client.Client._send_headers = Mock(28 return_value = response)29 self._mas.set_socket(Mock())30 self._mas.connect()31 def test_not_connected(self):32 self.assertIsNone(self._mas.connection_id)33 def test_connect(self):34 self.connect()35 self.assertIsNotNone(self._mas.connection_id)36 self.assertEqual(self._connection_id.data, self._mas.connection_id.data)37 def test_disconnet(self):38 self.connect()39 self._mas.disconnect()40 self.assertIsNone(self._mas.connection_id)41 def test_set_notifiaction_registration(self):42 self.connect()43 response = PyOBEX.responses.Success()44 PyOBEX.client.Client._send_headers = Mock(45 return_value = response)46 self._mas.set_notification_registration()47 def test_get_folder_listing(self):48 self.connect()49 folder_list = "\x01\x02\x03"50 response = PyOBEX.responses.Success()51 response.add_header(self._connection_id, 8)52 response.add_header(PyOBEX.headers.End_Of_Body(folder_list, True), len(folder_list) + 3)53 PyOBEX.client.Client._send_headers = Mock(54 return_value = response)55 self.assertEqual(folder_list, self._mas.get_folder_listing())56 def test_get_message_listing(self):57 self.connect()58 data = "\xA0\x00\x13\xcb\x00\x00\x00\x01\x49\x00\x0b\x00\x6d\x00\x73\x00\x67\x00\x00"59 message_list = "\x00\x6d\x00\x73\x00\x67\x00\x00"60 response = PyOBEX.responses.Success()61 response.read_data(data)62 PyOBEX.client.Client._send_headers = Mock(63 return_value = response)64 self.assertEqual(message_list, self._mas.get_message_listing())65 def test_set_folder(self):66 self.connect()67 response = PyOBEX.responses.Success()68 response.add_header(self._connection_id, 8)69 PyOBEX.client.Client._send_headers = Mock(70 return_value = response)...

Full Screen

Full Screen

dbserver.py

Source:dbserver.py Github

copy

Full Screen

...12 self.db[key] = val13# This server is very low level, we might use something like flask to clean up14# a lot of this cruft, but let's stick to base Python for now.15class DBServer(BaseHTTPRequestHandler):16 def _send_headers(self, code):17 self.send_response(code)18 self.send_header("Content-type", "text/plain")19 self.end_headers()20 def _send_text(self, text):21 self.wfile.write(text.encode("utf8"))22 def do_GET(self):23 qs = urlparse(self.path)24 params = parse_qs(qs.query)25 if qs.path.endswith('/get'):26 if 'key' not in params:27 self._send_headers(400)28 self._send_text("Missing key")29 return30 try:31 val = db[params['key'][0]]32 except KeyError:33 self._send_headers(404)34 return35 self._send_headers(200)36 self._send_text(val)37 elif qs.path.endswith('/set'): 38 if 'key' not in params or 'value' not in params:39 self._send_headers(400)40 self._send_text("Missing key or value")41 return42 43 db[params['key'][0]] = params['value'][0]44 self._send_headers(200)45 else:46 self._send_headers(200)47if __name__ == "__main__":48 db = InMemoryDB() 49 ws = HTTPServer((host_name, server_port), DBServer)50 print("Server started http://%s:%s" % (host_name, server_port))51 try:52 ws.serve_forever()53 except KeyboardInterrupt:54 pass55 ws.server_close()...

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 autotest 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