def test_teardown(self): try: lock = threading.Lock() https = https_reader.server_plugin(lock, PORT) except Exception as e: print e self.fail("Failed to startup server") try: conn = httplib.HTTPSConnection('localhost', 4443, timeout=5, context=ssl._create_unverified_context()) conn.request("GET", "/") r1 = conn.getresponse() if r1.status == 404: connection = True else: connection = False conn.close() except Exception as e: print e self.fail("Client couldn't to server") try: https.tear_down() httplib.HTTPSConnection('localhost', 4443, timeout=5, context=ssl._create_unverified_context()) r2 = conn.getresponse() self.fail("Server failed to shutdown") except Exception as e: #sever shutdown self.assertTrue(True)
def test_run(self): try: lock = threading.Lock() self.https = https_reader.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") time.sleep(1) try: conn =httplib.HTTPSConnection('localhost', PORT, timeout=5, context=ssl._create_unverified_context()) conn.request("GET", "/") r1 = conn.getresponse() if r1.status == 404: connection = True else: connection = False except Exception as e: print e connection = False finally: self.assertTrue(connection) conn.close() self.https.server.shutdown() self.https.server.server_close() time.sleep(1)
def test_invalidPort(self): try: lock = threading.Lock() https = https_reader.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") try: conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect(("localhost", 81)) connection = False except Exception as e: print e connection = True try: conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect(("localhost", 79)) connection = False except Exception as e: print e connection = True finally: self.assertTrue(connection) conn.close()
def test_multithreads(self): try: lock = threading.Lock() self.https = https_reader.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") time.sleep(1) try: threads = [] for num in range(0, 4): thread = mulithread_client() thread.start() threads.append(thread) for thread in threads: thread.join() self.assertTrue(True) except Exception as e: print e self.fail("Server is not listening on multiple threads") finally: time.sleep(1) self.https.server.shutdown() self.https.server.server_close()
def test_startUp(self): try: lock = threading.Lock() https = https_reader.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") try: conn =httplib.HTTPSConnection('localhost', 4443, timeout=5, context=ssl._create_unverified_context()) connection = True except Exception as e: print e connection = False finally: self.assertTrue(connection) conn.close()