Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
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"))
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
    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."))
Exemplo n.º 6
0
    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))
Exemplo n.º 7
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."))
Exemplo n.º 8
0
    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"))
Exemplo n.º 9
0
    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"))
Exemplo n.º 10
0
    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"))
Exemplo n.º 11
0
    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"))
Exemplo n.º 12
0
 def setUp(self):
     HttpStub.start()
Exemplo n.º 13
0
 def tearDown(self):
     HttpStub.stop()
Exemplo n.º 14
0
 def setUp(self):
     HttpStub.start()
Exemplo n.º 15
0
 def tearDown(self):
     HttpStub.stop()