def test_http_fail_full(self, mock_get): mock_response = mock.Mock() mock_response.status_code = 404 mock_get.return_value = mock_response http_smoke_test.check_urls('pro1', full=True) self.assertEqual(mock_get.call_count, len(http_smoke_test.SHORT_RUN + http_smoke_test.FULL_RUN))
def test_http_success_full(self, mock_list, mock_get): mock_list.return_value = FALLBACK_URLS mock_response = mock.Mock() mock_response.status_code = 200 mock_get.return_value = mock_response self.assertTrue(check_urls('pro1')) self.assertEqual(mock_get.call_count, len(FALLBACK_URLS))
def test_http_fail_url_list(self, mock_get): mock_response = mock.Mock() mock_response.status_code = 404 mock_get.return_value = mock_response mock_response.json.return_value = [] result = check_urls('pro1', url_list='/') self.assertFalse(result) self.assertEqual(mock_get.call_count, 1)
def test_http_fail_full(self, mock_list, mock_get): mock_response = mock.Mock() mock_list.return_value = FALLBACK_URLS mock_response.status_code = 404 mock_get.return_value = mock_response result = check_urls('pro1') self.assertFalse(result) self.assertEqual(mock_get.call_count, len(FALLBACK_URLS))
def test_allowed_timeouts(self, mock_get): allowed = http_smoke_test.ALLOWED_TIMEOUTS mock_ok_response = mock.Mock() mock_ok_response.status_code = 200 short_run_remainder = len(http_smoke_test.SHORT_RUN) - allowed allowed_list = [requests.exceptions.Timeout] * allowed ok_list = [mock_ok_response] * short_run_remainder side_effect_list = allowed_list + ok_list mock_get.side_effect = side_effect_list self.assertTrue(http_smoke_test.check_urls('pro1'))
def test_http_fail_timeout_full(self, mock_get): mock_get.side_effect = requests.exceptions.Timeout http_smoke_test.check_urls('pro1', full=True) self.assertEqual(mock_get.call_count, len(http_smoke_test.FULL_RUN))
def test_http_fail_request_error(self, mock_get): mock_get.side_effect = requests.exceptions.RequestException http_smoke_test.check_urls('pro1') self.assertEqual(mock_get.call_count, len(http_smoke_test.SHORT_RUN))
def test_http_fail_full(self, mock_get): mock_response = mock.Mock() mock_response.status_code = 404 mock_get.return_value = mock_response http_smoke_test.check_urls('pro1', full=True) self.assertEqual(mock_get.call_count, len(http_smoke_test.FULL_RUN))
def test_http_fail_timeout_short(self, mock_get): mock_get.side_effect = requests.exceptions.Timeout http_smoke_test.check_urls('pro1') self.assertEqual(mock_get.call_count, len(http_smoke_test.SHORT_RUN))
def test_http_fail_short(self, mock_get): mock_response = mock.Mock() mock_response.status_code = 404 mock_get.return_value = mock_response http_smoke_test.check_urls('pro1') self.assertEqual(mock_get.call_count, len(http_smoke_test.SHORT_RUN))
def test_http_fail_timeout(self, mock_get): check_urls('pro1', url_list=['/']) self.assertEqual(mock_get.call_count, 1)
def test_http_success_short(self, mock_get): mock_response = mock.Mock() mock_response.status_code = 200 mock_get.return_value = mock_response http_smoke_test.check_urls('pro1') self.assertEqual(mock_get.call_count, len(http_smoke_test.SHORT_RUN))
def test_http_fail_timeout_full(self, mock_get): expected_call_count = len(FALLBACK_URLS) + 1 # one call for s3 self.assertFalse(check_urls('pro1')) self.assertEqual(mock_get.call_count, expected_call_count)
def test_http_success_url_list(self, mock_get): mock_response = mock.Mock() mock_response.status_code = 200 mock_get.return_value = mock_response self.assertTrue(check_urls('pro1', url_list=['/', '/ask-cfpb/'])) self.assertEqual(mock_get.call_count, 2)
def test_http_fail_request_error(self, mock_get): result = check_urls('www', url_list=['/', '/ask-cfpb']) self.assertFalse(result)
def test_http_fail_connection_error(self, mock_get): check_urls('pro1') self.assertEqual( mock_get.call_count, len(FALLBACK_URLS) + 1 # one call for s3 )
def test_allowed_timeouts(self, mock_get): too_many = ALLOWED_TIMEOUTS + 2 urls = FALLBACK_URLS[:too_many] self.assertFalse(check_urls('pro1', url_list=urls))