def test_simple(self): with test.Daemon() as d: rsp = requests.get("http://localhost:%s/p/202:da" % d.port) assert rsp.ok assert rsp.status_code == 202 with pytest.raises(requests.ConnectionError): requests.get("http://localhost:%s/p/202:da" % d.port)
def test_terminate_error(self): self.d = test.Daemon() sc = connections.ServerConnection((self.d.IFACE, self.d.port)) sc.connect() sc.connection = mock.Mock() sc.connection.recv = mock.Mock(return_value=False) sc.connection.flush = mock.Mock(side_effect=exceptions.TcpDisconnect) sc.finish() self.d.shutdown()
def setup_class(cls): cls.d = test.Daemon( ssl=cls.ssl, ssloptions=cls.ssloptions, staticdir=tutils.test_data.path("data"), anchors=[ (re.compile("/anchor/.*"), "202") ] )
def test_terminate_error(self): d = test.Daemon() c = connections.ServerConnection((d.IFACE, d.port)) c.connect() c.close() c.connection = mock.Mock() c.connection.recv = mock.Mock(return_value=False) c.connection.flush = mock.Mock(side_effect=exceptions.TcpDisconnect) d.shutdown()
def test_startstop_ssl(self): d = test.Daemon(ssl=True) rsp = requests.get("https://localhost:%s/p/202:da" % d.port, verify=False) assert rsp.ok assert rsp.status_code == 202 d.shutdown() with pytest.raises(requests.ConnectionError): requests.get("http://localhost:%s/p/202:da" % d.port)
def test_startstop_ssl_explicit(self): ssloptions = dict(certfile=tutils.test_data.path("data/testkey.pem"), cacert=tutils.test_data.path("data/testkey.pem"), ssl_after_connect=False) d = test.Daemon(ssl=ssloptions) rsp = requests.get("https://localhost:%s/p/202:da" % d.port, verify=False) assert rsp.ok assert rsp.status_code == 202 d.shutdown() with tutils.raises(requests.ConnectionError): requests.get("http://localhost:%s/p/202:da" % d.port)
def test_startstop_ssl(self, not_after_connect): ssloptions = SSLOptions( cn=b'localhost', sans=[b'localhost', b'127.0.0.1'], not_after_connect=not_after_connect, ) d = test.Daemon(ssl=True, ssloptions=ssloptions) rsp = requests.get("https://localhost:%s/p/202:da" % d.port, verify=os.path.expanduser( os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME))) assert rsp.ok assert rsp.status_code == 202 d.shutdown() with pytest.raises(requests.ConnectionError): requests.get("http://localhost:%s/p/202:da" % d.port)
def test_simple(self): self.d = test.Daemon() sc = connections.ServerConnection((self.d.IFACE, self.d.port)) sc.connect() f = tflow.tflow() f.server_conn = sc f.request.path = "/p/200:da" # use this protocol just to assemble - not for actual sending sc.wfile.write(http1.assemble_request(f.request)) sc.wfile.flush() assert http1.read_response(sc.rfile, f.request, 1000) assert self.d.last_log() sc.finish() self.d.shutdown()
def setup_class(cls): opts = cls.ssloptions or {} cls.confdir = tempfile.mkdtemp() opts["confdir"] = cls.confdir so = pathod.SSLOptions(**opts) cls.d = test.Daemon(staticdir=test_data.path("data"), anchors=[(re.compile("/anchor/.*"), "202:da")], ssl=cls.ssl, ssloptions=so, sizelimit=1 * 1024 * 1024, nohang=cls.nohang, timeout=cls.timeout, hexdump=cls.hexdump, nocraft=cls.nocraft, logreq=True, logresp=True, explain=cls.explain)
def test_simple(): """ Testing the requests module with a pathod context manager. """ # Start pathod in a separate thread with test.Daemon() as d: # Get a URL for a pathod spec url = d.p("200:b@100") # ... and request it r = requests.put(url) # Check the returned data assert r.status_code == 200 assert len(r.content) == 100 # Check pathod's internal log log = d.last_log()["request"] assert log["method"] == "PUT"
def setup(self): self.d = test.Daemon()
def setup_class(cls): cls.d = test.Daemon()