class HttpStatusTest(unittest.TestCase): def setUp(self): self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "200-300"}) def test_init(self): assert self.expectation.status_range == (200, 300) def test_init_with_one_status(self): """With only one value, we still expect a valid tuple""" self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "200"}) assert self.expectation.status_range == (200, 201) def test_init_with_invalid_number(self): """Invalid values should just fail with a ValueError, as we can't convert it to int.""" with pytest.raises(ValueError): self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "foo"}) def test_get_status_healthy(self): request = mock.Mock() request.status_code = 200 assert self.expectation.get_status(request) == ComponentStatus.OPERATIONAL def test_get_status_healthy_boundary(self): request = mock.Mock() request.status_code = 299 assert self.expectation.get_status(request) == ComponentStatus.OPERATIONAL def test_get_status_unhealthy(self): request = mock.Mock() request.status_code = 400 assert self.expectation.get_status(request) == ComponentStatus.PARTIAL_OUTAGE def test_get_status_unhealthy_boundary(self): request = mock.Mock() request.status_code = 300 assert self.expectation.get_status(request) == ComponentStatus.PARTIAL_OUTAGE def test_get_message(self): request = mock.Mock() request.status_code = 400 assert self.expectation.get_message(request) == ('Unexpected HTTP ' 'status (400)')
def test_init_with_invalid_number(self): """Invalid values should just fail with a ValueError, as we can't convert it to int.""" with pytest.raises(ValueError): self.expectation = HttpStatus({"type": "HTTP_STATUS", "status_range": "foo"})
def test_init_with_one_status(self): """With only one value, we still expect a valid tuple""" self.expectation = HttpStatus({"type": "HTTP_STATUS", "status_range": "200"}) assert self.expectation.status_range == (200, 201)
def setUp(self): self.expectation = HttpStatus({"type": "HTTP_STATUS", "status_range": "200-300"})
def setUp(self): self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "200-300"})