class TestConditionHandler(unittest.TestCase): """ Tests for the ConditionHandler class. """ def __init__(self, name): """ :Parameters: name : str Unit test name. """ super(TestConditionHandler, self).__init__(name) def setUp(self): """ Create the RestyCodes instance. """ self._ch = ConditionHandler() def tearDown(self): pass def test_requestUrlTooLong(self): for size, code in ((20, 200), (19, 200), (18, 414)): self._ch.requestUrlTooLong("someverylongurl.com", size) self.__runTest(code, "with size: {}".format(size)) def test_requestEntityTooLarge(self): rawEntity = StringIO() rawEntity.write(u"GET / http/1.1\r\n") rawEntity.write(u"Host: example.org\r\n") rawEntity.write(u"\r\n") rawEntity.write(u"Some entity body text.\r\n") result = rawEntity.getvalue() rawEntity.close() for size, code in ((62, 200), (61, 200), (60, 413)): self._ch.requestEntityTooLarge(result, size) self.__runTest(code, "with size: {}".format(size)) def test_method(self): for method, code in (('DELETE', 200), ('GET', 200), ('HEAD', 200), ('PUT', 200), ('POST', 200), ('OPTIONS', 200), ('TRACE', 405), ('CONNECT', 405), ('MOVE', 405), ('PROPPATCH', 405), ('MKCOL', 405), ('COPY', 405), ('UNLOCK', 405), ('UNKNOWN', 501)): self._ch.method(method) self.__runTest(code, "with method: {}".format(method)) def __runTest(self, code, message=""): msg = "Invalid status: found {}, should be {}" found = self._ch.getStatus() status = getCodeStatus(code) msg += ", " + message self.assertTrue(found == status, msg.format(found, status))
def setUp(self): """ Create the RestyCodes instance. """ self._ch = ConditionHandler()