def test_ensure_auth_success(self):
        # GIVEN (auth)registry server that returns valid token
        responses.add(responses.POST,
                      'http://127.0.0.1:5000/api/auth/token',
                      json={"token": "12345"},
                      status=200)

        # AND the client
        client = Client(dp1_path, self.config)

        # WHEN _ensure_auth() is called
        try:
            result = client._ensure_auth()
        except Exception as e:
            result = e

        # THEN token should be returned in result
        assert result == '12345'
        # AND client should store the token
        assert client.token == '12345'
    def test_getting_empty_auth_token(self):
        # GIVEN registry server that returns empty token
        responses.add(responses.POST,
                      'http://127.0.0.1:5000/api/auth/token',
                      json={"token": ""},
                      status=200)

        # AND the client
        client = Client(dp1_path, self.config)

        # WHEN _ensure_auth() is called
        try:
            result = client._ensure_auth()
        except Exception as e:
            result = e

        # THEN AuthResponseError should be raised
        assert isinstance(result, AuthResponseError)
        # AND 'server did not return auth token' should be printed to stdout
        self.assertRegexpMatches(str(result),
                                 'Server did not return auth token')