def test_it_fails_fast_when_flag_is_set(self): HttpStub.set_response_codes(500, 200) cmd = command.do("./backdrop-send " "--url http://localhost:8000/data_set " "--token token " "--failfast", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_(8))
def test_it_passes_after_default_number_of_retries(self): HttpStub.set_response_codes(500, 500, 200) cmd = command.do("./backdrop-send " "--url http://localhost:8000/data_set " "--sleep 0 " "--token data_set-auth-token", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_(0))
def test_it_reports_http_errors(self): HttpStub.set_response_codes(500) cmd = command.do("./backdrop-send " "--url http://localhost:8000/data_set " "--token data_set-auth-token", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_not(0)) assert_that(cmd.stderr, contains_string("Unable to send to backdrop")) assert_that(cmd.stderr, contains_string("500"))
def test_it_fails_fast_when_flag_is_set(self): HttpStub.set_response_codes(500, 200) cmd = command.do( "./backdrop-send " "--url http://localhost:8000/data_set " "--token token " "--failfast", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_(8))
def test_it_reports_authorization_errors(self): HttpStub.set_response_codes(403) cmd = command.do("./backdrop-send " "--url http://localhost:8000/data_set " "--token wrong-token", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_not(0)) assert_that(cmd.stderr, contains_string( "Unable to send to backdrop. " "Unauthorised: check your access token."))
def test_it_passes_when_request_takes_less_than_specified_timeout(self): HttpStub.set_response_delay(1) cmd = command.do( "./backdrop-send " "--url http://localhost:8000/data_set " "--token token " "--timeout 5 " "--failfast", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_(0))
def test_it_fails_when_request_takes_longer_than_default_timeout(self): HttpStub.set_response_delay(7) cmd = command.do( "./backdrop-send " "--url http://localhost:8000/data_set " "--token token " "--failfast", stdin='{"key": "value"}') assert_that(cmd.exit_status, is_not(0)) assert_that( cmd.stderr, contains_string("Unable to send to backdrop. " "Request timeout."))
def test_it_reads_data_from_stdin_to_post_to_backdrop(self): command.do("./backdrop-send " "--url http://localhost:8000/data_set " "--token data_set-auth-token", stdin='{"key": "value"}') request = HttpStub.last_request() assert_that(request["path"], is_("/data_set")) assert_that(request["body"], is_('{"key": "value"}')) assert_that(request["headers"]["content-type"], is_("application/json")) assert_that(request["headers"]["authorization"], is_("Bearer data_set-auth-token"))
def test_it_reads_data_from_stdin_to_post_to_backdrop(self): command.do( "./backdrop-send " "--url http://localhost:8000/data_set " "--token data_set-auth-token", stdin='{"key": "value"}') request = HttpStub.last_request() assert_that(request["path"], is_("/data_set")) assert_that(request["body"], is_('{"key": "value"}')) assert_that(request["headers"]["content-type"], is_("application/json")) assert_that(request["headers"]["authorization"], is_("Bearer data_set-auth-token"))
def test_it_posts_data_to_data_set_url_with_auth_token(self): f = tempfile.NamedTemporaryFile(suffix=".json") f.write('{"key": "value"}') f.flush() command.do("./backdrop-send " "--url http://localhost:8000/data_set " "--token data_set-auth-token %s" % f.name) request = HttpStub.last_request() assert_that(request["path"], is_("/data_set")) assert_that(request["body"], is_('{"key": "value"}')) assert_that(request["headers"]["content-type"], is_("application/json")) assert_that(request["headers"]["authorization"], is_("Bearer data_set-auth-token"))
def setUp(self): HttpStub.start()
def tearDown(self): HttpStub.stop()