diff --git a/tests/test_account_identified.py b/tests/test_account_identified.py index 68f4984..ff1994b 100644 --- a/tests/test_account_identified.py +++ b/tests/test_account_identified.py @@ -9,9 +9,12 @@ def test_user_identified(): user2 = AccountIdentified.by_account_id("account_id") user3 = AccountIdentified.by_domain("domain") - assert (user1.format_identification() == {"accountId": "account_id", "domain": "domain"}) - assert (user2.format_identification() == {"accountId": "account_id"}) - assert (user3.format_identification() == {"domain": "domain"}) + assert user1.format_identification() == { + "accountId": "account_id", + "domain": "domain", + } + assert user2.format_identification() == {"accountId": "account_id"} + assert user3.format_identification() == {"domain": "domain"} with pytest.raises(JournyException): AccountIdentified("", "") diff --git a/tests/test_client.py b/tests/test_client.py index f26c0a5..6df7000 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -14,10 +14,10 @@ def test_config(): config = Config("api-key", "https://api.journy.io") - assert (config.api_key == "api-key") - assert (config.root_url == "https://api.journy.io") + assert config.api_key == "api-key" + assert config.root_url == "https://api.journy.io" - assert (config.__str__() == "Config(api-key, https://api.journy.io)") + assert config.__str__() == "Config(api-key, https://api.journy.io)" with pytest.raises(JournyException): Config(123, "https://api.journy.io") @@ -27,15 +27,15 @@ def test_config(): def test_properties(): properties = Properties() - assert (properties["doesnotexist"] is None) + assert properties["doesnotexist"] is None properties["doesexist"] = "hallo" - assert (properties["doesexist"] == "hallo") + assert properties["doesexist"] == "hallo" properties["doesexisttoo"] = 2 - assert (properties["doesexisttoo"] == 2) + assert properties["doesexisttoo"] == 2 properties["thistoo"] = True properties["will_be_deleted"] = None properties["array_of_values"] = ["first_value", "second_value"] - assert (properties["thistoo"]) + assert properties["thistoo"] with pytest.raises(JournyException): properties[2] = "hallo" with pytest.raises(JournyException): @@ -43,9 +43,9 @@ def test_properties(): properties2 = Properties() properties2["new"] = "value" properties.union(properties2) - assert (properties["new"] == "value") - assert (properties["doesexist"] == "hallo") - assert (properties["thistoo"]) + assert properties["new"] == "value" + assert properties["doesexist"] == "hallo" + assert properties["thistoo"] def test_client(): @@ -54,41 +54,65 @@ def test_client(): client = Client(http_client_testing, config) - assert (client.httpclient.__str__() == http_client_testing.__str__()) - assert (client.config.__str__() == config.__str__()) + assert client.httpclient.__str__() == http_client_testing.__str__() + assert client.config.__str__() == config.__str__() assert ( - client.__str__() == "Client(HttpClientTesting(HttpResponse(200, {}, None), None), Config(api-key, https://api.journy.io))") + client.__str__() + == "Client(HttpClientTesting(HttpResponse(200, {}, None), None), Config(api-key, https://api.journy.io))" + ) rate_limit_header = HttpHeaders() rate_limit_header["X-RateLimit-Remaining"] = "4999" -created_response = HttpResponse(201, rate_limit_header, {"meta": {"requestId": "requestId"}}) -created_response_202 = HttpResponse(202, rate_limit_header, {"meta": {"requestId": "requestId"}}) -too_many_requests_response = HttpResponse(429, rate_limit_header, {"meta": {"requestId": "requestId"}}) -tracking_snippet_response = HttpResponse(200, rate_limit_header, {"data": { - "domain": "journy.io", - "snippet": "", -}, - "meta": { - "requestId": "requestId", - }}) -validate_api_key_response = HttpResponse(200, rate_limit_header, {"data": { - "permissions": [ - "TrackData", - "GetTrackingSnippet", - "ReadUserProfile", - ], -}, - "meta": { - "requestId": "requestId", - }}) +created_response = HttpResponse( + 201, rate_limit_header, {"meta": {"requestId": "requestId"}} +) +created_response_202 = HttpResponse( + 202, rate_limit_header, {"meta": {"requestId": "requestId"}} +) +too_many_requests_response = HttpResponse( + 429, rate_limit_header, {"meta": {"requestId": "requestId"}} +) +tracking_snippet_response = HttpResponse( + 200, + rate_limit_header, + { + "data": { + "domain": "journy.io", + "snippet": "", + }, + "meta": { + "requestId": "requestId", + }, + }, +) +validate_api_key_response = HttpResponse( + 200, + rate_limit_header, + { + "data": { + "permissions": [ + "TrackData", + "GetTrackingSnippet", + "ReadUserProfile", + ], + }, + "meta": { + "requestId": "requestId", + }, + }, +) metadata = Metadata() metadata["true"] = True metadata["key"] = "value" dt = datetime.strptime("2020-11-2 13:37:40", "%Y-%m-%d %H:%M:%S") user = UserIdentified("user_id", "user@journy.io") account = AccountIdentified("account_id", "www.journy.io") -event = Event.for_user_in_account("login", user, account).happened_at(dt).with_metadata(metadata) +event = ( + Event.for_user_in_account("login", user, account) + .happened_at(dt) + .with_metadata(metadata) +) def test_client_add_event(): @@ -98,14 +122,16 @@ def test_client_add_event(): client = Client(http_client_testing, config) response = client.add_event(event) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/events, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"user": {"email": "user@journy.io", "userId": "user_id"}, "account": {"domain": "www.journy.io", "accountId": "account_id"}}, "name": "login", "metadata": {"true": true, "key": "value"}, "triggeredAt": "2020-11-02T13:37:40"})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/events, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"user": {"email": "user@journy.io", "userId": "user_id"}, "account": {"domain": "www.journy.io", "accountId": "account_id"}}, "name": "login", "metadata": {"true": true, "key": "value"}, "triggeredAt": "2020-11-02T13:37:40"})' + ) def test_client_add_event_with_failure(): @@ -115,14 +141,16 @@ def test_client_add_event_with_failure(): client = Client(http_client_testing, config) response = client.add_event(event) - assert (isinstance(response, Failure)) - assert (response.__str__() == "Failure(requestId, 4999, APIError.TooManyRequests)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.error is APIError.TooManyRequests) + assert isinstance(response, Failure) + assert response.__str__() == "Failure(requestId, 4999, APIError.TooManyRequests)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.error is APIError.TooManyRequests assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/events, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"user": {"email": "user@journy.io", "userId": "user_id"}, "account": {"domain": "www.journy.io", "accountId": "account_id"}}, "name": "login", "metadata": {"true": true, "key": "value"}, "triggeredAt": "2020-11-02T13:37:40"})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/events, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"user": {"email": "user@journy.io", "userId": "user_id"}, "account": {"domain": "www.journy.io", "accountId": "account_id"}}, "name": "login", "metadata": {"true": true, "key": "value"}, "triggeredAt": "2020-11-02T13:37:40"})' + ) def test_client_upsert_user(): @@ -137,14 +165,17 @@ def test_client_upsert_user(): response = client.upsert_user(user, properties) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/users/upsert, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"email": "user@journy.io", "userId": "user_id"}, "properties": {"hasdog": false, "name": "Manu"}})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/users/upsert, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"email": "user@journy.io", "userId": "user_id"}, "properties": {"hasdog": false, "name": "Manu"}})' + ) + def test_client_delete_user(): http_client_testing = HttpClientTesting(created_response_202) @@ -154,14 +185,16 @@ def test_client_delete_user(): response = client.delete_user(user) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/users, Method.DELETE, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"email": "user@journy.io", "userId": "user_id"}})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/users, Method.DELETE, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"email": "user@journy.io", "userId": "user_id"}})' + ) def test_client_upsert_account(): @@ -179,14 +212,17 @@ def test_client_upsert_account(): response = client.upsert_account(account, properties) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/accounts/upsert, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"domain": "www.journy.io", "accountId": "account_id"}, "properties": {"havedog": false, "name": "Journy"}})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/accounts/upsert, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"domain": "www.journy.io", "accountId": "account_id"}, "properties": {"havedog": false, "name": "Journy"}})' + ) + def test_client_delete_account(): http_client_testing = HttpClientTesting(created_response_202) @@ -196,14 +232,17 @@ def test_client_delete_account(): response = client.delete_account(account) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/accounts, Method.DELETE, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"domain": "www.journy.io", "accountId": "account_id"}})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/accounts, Method.DELETE, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"domain": "www.journy.io", "accountId": "account_id"}})' + ) + def test_client_add_users_to_account(): http_client_testing = HttpClientTesting(created_response) @@ -216,14 +255,17 @@ def test_client_add_users_to_account(): response = client.add_users_to_account(account, [user1, user2]) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/accounts/users/add, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"account": {"domain": "www.journy.io", "accountId": "account_id"}, "users": [{"identification": {"userId": "hansId"}}, {"identification": {"email": "manu@journy.io"}}]})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/accounts/users/add, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"account": {"domain": "www.journy.io", "accountId": "account_id"}, "users": [{"identification": {"userId": "hansId"}}, {"identification": {"email": "manu@journy.io"}}]})' + ) + def test_client_remove_users_from_account(): http_client_testing = HttpClientTesting(created_response) @@ -236,14 +278,16 @@ def test_client_remove_users_from_account(): response = client.remove_users_from_account(account, [user1, user2]) - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/accounts/users/remove, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"account": {"domain": "www.journy.io", "accountId": "account_id"}, "users": [{"identification": {"userId": "hansId"}}, {"identification": {"email": "manu@journy.io"}}]})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/accounts/users/remove, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"account": {"domain": "www.journy.io", "accountId": "account_id"}, "users": [{"identification": {"userId": "hansId"}}, {"identification": {"email": "manu@journy.io"}}]})' + ) def test_client_link(): @@ -254,14 +298,16 @@ def test_client_link(): response = client.link(user, "device_id") - assert (isinstance(response, Success)) - assert (response.__str__() == "Success(requestId, 4999, None)") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (response.data is None) + assert isinstance(response, Success) + assert response.__str__() == "Success(requestId, 4999, None)" + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert response.data is None assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/link, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"deviceId": "device_id", "identification": {"email": "user@journy.io", "userId": "user_id"}})') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/link, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"deviceId": "device_id", "identification": {"email": "user@journy.io", "userId": "user_id"}})' + ) def test_client_get_tracking_snippet(): @@ -272,15 +318,19 @@ def test_client_get_tracking_snippet(): response = client.get_tracking_snippet("journy.io") - assert (isinstance(response, Success)) + assert isinstance(response, Success) assert ( - response.__str__() == "Success(requestId, 4999, TrackingSnippetResponse(journy.io, ))") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (isinstance(response.data, TrackingSnippetResponse)) + response.__str__() + == "Success(requestId, 4999, TrackingSnippetResponse(journy.io, ))" + ) + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert isinstance(response.data, TrackingSnippetResponse) assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/tracking/snippet?domain=journy.io, Method.GET, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, None)') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/tracking/snippet?domain=journy.io, Method.GET, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, None)' + ) def test_client_get_api_key_details(): @@ -291,12 +341,16 @@ def test_client_get_api_key_details(): response = client.get_api_key_details() - assert (isinstance(response, Success)) + assert isinstance(response, Success) assert ( - response.__str__() == "Success(requestId, 4999, ApiKeyDetails(['TrackData', 'GetTrackingSnippet', 'ReadUserProfile']))") - assert (response.calls_remaining == 4999) - assert (response.request_id == "requestId") - assert (isinstance(response.data, ApiKeyDetails)) + response.__str__() + == "Success(requestId, 4999, ApiKeyDetails(['TrackData', 'GetTrackingSnippet', 'ReadUserProfile']))" + ) + assert response.calls_remaining == 4999 + assert response.request_id == "requestId" + assert isinstance(response.data, ApiKeyDetails) assert ( - http_client_testing.received_request.__str__() == 'HttpRequest(https://api.journy.io/validate, Method.GET, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, None)') + http_client_testing.received_request.__str__() + == 'HttpRequest(https://api.journy.io/validate, Method.GET, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, None)' + ) diff --git a/tests/test_events.py b/tests/test_events.py index 3a7fb8e..29cbeda 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -10,13 +10,13 @@ def test_metadata(): metadata = Metadata() - assert (metadata["doesnotexist"] is None) + assert metadata["doesnotexist"] is None metadata["doesexist"] = "hallo" - assert (metadata["doesexist"] == "hallo") + assert metadata["doesexist"] == "hallo" metadata["doesexisttoo"] = 2 - assert (metadata["doesexisttoo"] == 2) + assert metadata["doesexisttoo"] == 2 metadata["thistoo"] = True - assert (metadata["thistoo"]) + assert metadata["thistoo"] with pytest.raises(JournyException): metadata[2] = "hallo" with pytest.raises(JournyException): @@ -24,9 +24,9 @@ def test_metadata(): metadata2 = Metadata() metadata2["new"] = "value" metadata.union(metadata2) - assert (metadata2["new"] == "value") - assert (metadata["doesexist"] == "hallo") - assert (metadata["thistoo"]) + assert metadata2["new"] == "value" + assert metadata["doesexist"] == "hallo" + assert metadata["thistoo"] def test_event(): @@ -43,14 +43,28 @@ def test_event(): event_1 = Event.for_user("login", user).happened_at(dt) event_2 = Event.for_user("logout", user).happened_at(dt2) event_3 = Event.for_account("login", account).happened_at(dt) - event_4 = Event.for_user_in_account("login", user, account).happened_at(dt2).with_metadata(metadata) + event_4 = ( + Event.for_user_in_account("login", user, account) + .happened_at(dt2) + .with_metadata(metadata) + ) - assert (event_1.__str__() == "Event(login, UserIdentified(user_id, email), None, 2020-11-02 13:37:40, {})") - assert (event_2.__str__() == "Event(logout, UserIdentified(user_id, email), None, 2020-11-02 13:37:50, {})") assert ( - event_3.__str__() == "Event(login, None, AccountIdentified(account_id, www.account.be), 2020-11-02 13:37:40, {})") + event_1.__str__() + == "Event(login, UserIdentified(user_id, email), None, 2020-11-02 13:37:40, {})" + ) assert ( - event_4.__str__() == 'Event(login, UserIdentified(user_id, email), AccountIdentified(account_id, www.account.be), 2020-11-02 13:37:50, {"true": true, "key": "value"})') + event_2.__str__() + == "Event(logout, UserIdentified(user_id, email), None, 2020-11-02 13:37:50, {})" + ) + assert ( + event_3.__str__() + == "Event(login, None, AccountIdentified(account_id, www.account.be), 2020-11-02 13:37:40, {})" + ) + assert ( + event_4.__str__() + == 'Event(login, UserIdentified(user_id, email), AccountIdentified(account_id, www.account.be), 2020-11-02 13:37:50, {"true": true, "key": "value"})' + ) with pytest.raises(JournyException): Event(None, None, None, None, Metadata()) diff --git a/tests/test_httpclient.py b/tests/test_httpclient.py index 6f08e2f..f0b13dd 100644 --- a/tests/test_httpclient.py +++ b/tests/test_httpclient.py @@ -1,16 +1,23 @@ import pytest -from journyio.httpclient import HttpHeaders, HttpRequest, HttpResponse, HttpClientRequests, Method, HttpClientTesting +from journyio.httpclient import ( + HttpHeaders, + HttpRequest, + HttpResponse, + HttpClientRequests, + Method, + HttpClientTesting, +) from journyio.utils import JournyException def test_http_headers(): headers = HttpHeaders() - assert (headers["doesnotexist"] is None) + assert headers["doesnotexist"] is None headers["doesexist"] = "hallo" - assert (headers["doesexist"] == "hallo") + assert headers["doesexist"] == "hallo" headers["thistoo"] = ["a", "b"] - assert (headers["thistoo"]) + assert headers["thistoo"] with pytest.raises(JournyException): headers[2] = "hallo" with pytest.raises(JournyException): @@ -18,19 +25,19 @@ def test_http_headers(): headers2 = HttpHeaders() headers2["new"] = "value" headers.union(headers2) - assert (headers["new"] == "value") - assert (headers["doesexist"] == "hallo") - assert (headers["thistoo"] == ["a", "b"]) + assert headers["new"] == "value" + assert headers["doesexist"] == "hallo" + assert headers["thistoo"] == ["a", "b"] def test_http_request(): request = HttpRequest("https://journy.io", Method.GET, None, None) - assert (request.url == "https://journy.io") - assert (request.method is Method.GET) - assert (request.headers == HttpHeaders()) + assert request.url == "https://journy.io" + assert request.method is Method.GET + assert request.headers == HttpHeaders() - assert (request.__str__() == "HttpRequest(https://journy.io, Method.GET, {}, None)") + assert request.__str__() == "HttpRequest(https://journy.io, Method.GET, {}, None)" with pytest.raises(JournyException): HttpRequest(123, Method.GET, HttpHeaders(), None) @@ -43,10 +50,10 @@ def test_http_request(): def test_http_response(): response = HttpResponse(200, HttpHeaders(), None) - assert (response.status_code == 200) - assert (response.headers == HttpHeaders()) + assert response.status_code == 200 + assert response.headers == HttpHeaders() - assert (response.__str__() == "HttpResponse(200, {}, None)") + assert response.__str__() == "HttpResponse(200, {}, None)" with pytest.raises(JournyException): HttpResponse("200", HttpHeaders(), None) @@ -67,8 +74,10 @@ def test_http_client_testing(): dummy_response = HttpResponse(201, HttpHeaders(), {"message": "created"}) client = HttpClientTesting(dummy_response) - dummy_request = HttpRequest("/test", Method.POST, HttpHeaders(), {"object": "hello"}) + dummy_request = HttpRequest( + "/test", Method.POST, HttpHeaders(), {"object": "hello"} + ) response = client.send(dummy_request) - assert (response.__str__() == dummy_response.__str__()) - assert (client.received_request.__str__() == dummy_request.__str__()) + assert response.__str__() == dummy_response.__str__() + assert client.received_request.__str__() == dummy_request.__str__() diff --git a/tests/test_results.py b/tests/test_results.py index 0803751..1429312 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -1,14 +1,20 @@ import pytest -from journyio.results import Success, Failure, TrackingSnippetResponse, ApiKeyDetails, APIError +from journyio.results import ( + Success, + Failure, + TrackingSnippetResponse, + ApiKeyDetails, + APIError, +) from journyio.utils import JournyException def test_success(): success = Success[None]("request_id", 100, None) - assert (success.data is None) - assert (success.request_id == "request_id") - assert (success.calls_remaining == 100) + assert success.data is None + assert success.request_id == "request_id" + assert success.calls_remaining == 100 with pytest.raises(JournyException): Success[None](1234, 100, None) @@ -16,18 +22,18 @@ def test_success(): with pytest.raises(JournyException): Success[None]("request_id", "100", None) - assert (success.__str__() == "Success(request_id, 100, None)") + assert success.__str__() == "Success(request_id, 100, None)" def test_failure(): failure = Failure(None, None, APIError.ServerError) failure2 = Failure("request_id", 100, APIError.UnknownError) - assert (failure2.request_id == "request_id") - assert (failure2.calls_remaining == 100) - assert (failure2.error is APIError.UnknownError) - assert (failure.__str__() == "Failure(None, None, APIError.ServerError)") - assert (failure2.__str__() == "Failure(request_id, 100, APIError.UnknownError)") + assert failure2.request_id == "request_id" + assert failure2.calls_remaining == 100 + assert failure2.error is APIError.UnknownError + assert failure.__str__() == "Failure(None, None, APIError.ServerError)" + assert failure2.__str__() == "Failure(request_id, 100, APIError.UnknownError)" with pytest.raises(JournyException): Failure("request_id", "100", APIError.ServerError) @@ -40,10 +46,13 @@ def test_failure(): def test_tracking_snippet_response(): response = TrackingSnippetResponse("www.journy.io", "