def test_get_http_status_error(mock_object): '''result should be a Timeout error message''' mock_object.side_effect = requests.exceptions.Timeout url = 'example.com' result = core.get_http_status(url) tools.assert_equals(result.request, None) tools.assert_equals(result.message, 'Error: The request timed out')
def test_get_http_status_connection_error(mock_object): '''result should be DNS lookup or other error''' mock_object.side_effect = requests.exceptions.ConnectionError url = 'http://example.com' result = core.get_http_status(url) tools.assert_equals(result.request, None) tools.assert_equals(result.message, "The connection was refused, DNS Lookup Failed, or that address does not exist.")
def test_get_http_status_too_many_redirects(mock_object): '''result should be too many redirects error''' mock_object.side_effect = requests.exceptions.TooManyRedirects url = 'http://example.com' result = core.get_http_status(url) tools.assert_equals(result.request, None) tools.assert_equals(result.message, 'Looks like the page you are trying to find has too many redirects, so I stopped looking.')
def test_get_http_status_error(): '''result should be an HTTP Error Message''' mock_object.side_effect = requests.exceptions.HTTPError url = 'example.com' result = core.get_http_status(url) tools.assert_equals(result.request, None) tools.assert_equals(result.message, 'Something is broken! I got an invalid http response')
def check_http(): url = request.form['url'] url_request = core.get_http_status(url) return render_template('response.html', status = url_request)
def store_results(users): for user in users: for item in user.url_users: http_result, date = core.get_http_status(item.url.url_address) core.add_result(item.url.id, date, http_result['code'], http_result['time'] ) print item.url.url_address, http_result['code']
def test_get_http_status_not_found(): '''url that should return status 404''' url = 'http://httpbin.org/status/404' result = core.get_http_status(url) tools.assert_equals(result.request.status_code, 404)
def test_get_http_status_ok(): '''url that should return status 200''' url = 'http://example.com' result = core.get_http_status(url) tools.assert_equals(result.request.status_code, 200)