Beispiel #1
0
def test_resource_init_base_url(input, expected):
        if input is None:
                resource = Resource()
        else:
                resource = Resource(input)

        assert resource.base_url == expected
Beispiel #2
0
def test_resource_init_endpoint(input, expected):
        # TODO would be interesting to validate endpoints always start with '/'
        if input is None:
                resource = Resource()
        else:
                resource = Resource(endpoint=input)

        assert resource.endpoint == expected
Beispiel #3
0
def test_resource_create_error():
        with requests_mock.Mocker() as mock:
                mock.register_uri(
                        'POST', __SIGNALFX_API_ENDPOINT__ + '/', status_code=500
                )

                resource = Resource().with_api_token('test')
                resource.options = {'opt': 'val'}

                with pytest.raises(RuntimeError):
                        resource.create()
Beispiel #4
0
def test_resource_create_happy_path():
        with requests_mock.Mocker() as mock:
                expected = {'foo': 'bar'}

                mock.register_uri(
                        'POST', __SIGNALFX_API_ENDPOINT__ + '/', json=expected
                )

                resource = Resource().with_api_token('test')
                resource.options = {'opt': 'val'}

                response = resource.create()
                assert response == expected
Beispiel #5
0
def test_resource_with_api_token():
        expected = 'foo'
        resource = Resource().with_api_token(expected)

        assert resource.api_token == expected
Beispiel #6
0
def test_resource_init_api_token():
        expected = "foo"
        resource = Resource(api_token=expected)
        assert resource.api_token == expected
Beispiel #7
0
def test_resource_init_empty_opts_args(expected):
        with pytest.raises(ValueError):
                Resource(base_url=expected)
                Resource(endpoint=expected)
                Resource(api_token=expected)
                Resource().with_api_token(expected)