contiamo / contiamo-client-python

MIT License
2 stars 2 forks source link

Fix broken test_resources test #14

Closed bmwilly closed 6 years ago

bmwilly commented 6 years ago
➜  contiamo-client-python git:(update-contracts) ✗ pytest contiamo/tests/test_resources.py
======================================================== test session starts ========================================================
platform darwin -- Python 3.6.4, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /Users/brandon/projects/contiamo-client-python, inifile:
plugins: nbval-0.9.0, aspectlib-1.4.2
collected 8 items

contiamo/tests/test_resources.py ...F....                                                                                     [100%]

============================================================= FAILURES ==============================================================
_____________________________________________________ TestResources.test_create _____________________________________________________

self = <contiamo.tests.test_resources.TestResources object at 0x1136efcf8>

    @vcr.use_cassette(file_test_cassette('test_create.yaml'))
    def test_create(self):
        dashboard_name = 'New dashboard'
>       new_dashboard = self.project.Dashboard.create({'name': dashboard_name})

contiamo/tests/test_resources.py:59:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
contiamo/resources.py:140: in create
    response = cls.request('post', cls.class_url(), payload=model)
contiamo/resources.py:74: in request
    response = cls.client().request(method, url, payload=payload)
contiamo/http_client.py:37: in request
    self._handle_api_error(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <contiamo.http_client.HTTPClient object at 0x109808278>, response = <Response [422]>

    def _handle_api_error(self, response):
        logger.error('HTTP error %d: %s' %
                     (response.status_code, response.text))

        # check for authorization error first
        is_auth_error = False
        try:
            is_auth_error = not response.json()['logged_in']
        except:
            pass
        if is_auth_error:
            raise errors.AuthenticationError(
                http_body=response.content, http_status=response.status_code, headers=response.headers)

        ERROR_MAPPING = {
            404: errors.NotFoundError,
            412: errors.DataSourceError,
            410: errors.QueryError,
            424: errors.QueryError,
            409: errors.UpdateError,
            422: errors.UpdateError,
        }
        try:
            error_class = ERROR_MAPPING[response.status_code]
        except KeyError:
            error_class = errors.APIError  # catch all
        raise error_class(http_body=response.content,
>                         http_status=response.status_code, headers=response.headers)
E       contiamo.errors.UpdateError: An error happened while creating or updating the resource.
E       API error 422: {"errors":{"name":["has already been taken"]}}

contiamo/http_client.py:79: UpdateError
------------------------------------------------------- Captured stderr call --------------------------------------------------------
DEBUG:vcr.cassette:Entering context for cassette at /Users/brandon/projects/contiamo-client-python/contiamo/tests/cassettes/test_create.yaml.
DEBUG:contiamo.http_client:Sending POST request to https://api.contiamo.com/48590558/dashboards
DEBUG:contiamo.http_client:With payload: {'name': 'New dashboard'}
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.contiamo.com
DEBUG:vcr.stubs:Got <Request (POST) https://api.contiamo.com/48590558/dashboards>
INFO:vcr.stubs:Playing response for <Request (POST) https://api.contiamo.com/48590558/dashboards> from cassette
DEBUG:urllib3.connectionpool:https://api.contiamo.com:443 "POST /48590558/dashboards HTTP/1.1" 422 None
ERROR:contiamo.http_client:HTTP error 422: {"errors":{"name":["has already been taken"]}}
DEBUG:vcr.cassette:Exiting context for cassette at /Users/brandon/projects/contiamo-client-python/contiamo/tests/cassettes/test_create.yaml.
--------------------------------------------------------- Captured log call ---------------------------------------------------------
cassette.py                 64 DEBUG    Entering context for cassette at /Users/brandon/projects/contiamo-client-python/contiamo/tests/cassettes/test_create.yaml.
http_client.py              16 DEBUG    Sending POST request to https://api.contiamo.com/48590558/dashboards
http_client.py              18 DEBUG    With payload: {'name': 'New dashboard'}
connectionpool.py          824 DEBUG    Starting new HTTPS connection (1): api.contiamo.com
__init__.py                164 DEBUG    Got <Request (POST) https://api.contiamo.com/48590558/dashboards>
__init__.py                218 INFO     Playing response for <Request (POST) https://api.contiamo.com/48590558/dashboards> from cassette
connectionpool.py          396 DEBUG    https://api.contiamo.com:443 "POST /48590558/dashboards HTTP/1.1" 422 None
http_client.py              54 ERROR    HTTP error 422: {"errors":{"name":["has already been taken"]}}
cassette.py                 68 DEBUG    Exiting context for cassette at /Users/brandon/projects/contiamo-client-python/contiamo/tests/cassettes/test_create.yaml.
================================================ 1 failed, 7 passed in 1.23 seconds =================================================