Example #1
0
def test_client():
    http_client_testing = HttpClientTesting(HttpResponse())
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)

    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))"
    )
Example #2
0
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.__str__() == "Config(api-key, https://api.journy.io)"

    with pytest.raises(JournyException):
        Config(123, "https://api.journy.io")
    with pytest.raises(JournyException):
        Config("api-key", 123)
Example #3
0
def test_client_upsert_account():
    http_client_testing = HttpClientTesting(created_response)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)
    properties = Properties()

    properties["haveDog"] = False
    properties["name"] = "Journy"

    member1 = UserIdentified.by_user_id("hansId")
    member2 = UserIdentified.by_user_id("manuId")

    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 (
        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"}})'
    )
Example #4
0
def test_client_add_event_with_failure():
    http_client_testing = HttpClientTesting(too_many_requests_response)
    config = Config("api-key", "https://api.journy.io")

    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 (
        http_client_testing.received_request.__str__()
        == 'HttpRequest(https://api.journy.io/track, Method.POST, {"content-type": "application/json", "user-agent": "python-sdk/0.0.0", "x-api-key": "api-key"}, {"identification": {"user": {"email": "*****@*****.**", "userId": "user_id"}, "account": {"domain": "www.journy.io", "accountId": "account_id"}}, "name": "login", "metadata": {"true": true, "key": "value"}, "triggeredAt": "2020-11-02T13:37:40"})'
    )
Example #5
0
def test_client_link():
    http_client_testing = HttpClientTesting(created_response)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)

    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 (
        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": "*****@*****.**", "userId": "user_id"}})'
    )
Example #6
0
def test_client_delete_account():
    http_client_testing = HttpClientTesting(created_response_202)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)

    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 (
        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"}})'
    )
Example #7
0
def test_client_get_api_key_details():
    http_client_testing = HttpClientTesting(validate_api_key_response)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)

    response = client.get_api_key_details()

    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)

    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)'
    )
Example #8
0
def test_client_get_tracking_snippet():
    http_client_testing = HttpClientTesting(tracking_snippet_response)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)

    response = client.get_tracking_snippet("journy.io")

    assert isinstance(response, Success)
    assert (
        response.__str__()
        == "Success(requestId, 4999, TrackingSnippetResponse(journy.io, <script>snippet</script>))"
    )
    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)'
    )
Example #9
0
def test_client_remove_users_from_account():
    http_client_testing = HttpClientTesting(created_response)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)

    user1 = UserIdentified.by_user_id("hansId")
    user2 = UserIdentified.by_email("*****@*****.**")

    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 (
        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": "*****@*****.**"}}]})'
    )
Example #10
0
def test_client_upsert_user():
    http_client_testing = HttpClientTesting(created_response)
    config = Config("api-key", "https://api.journy.io")

    client = Client(http_client_testing, config)
    properties = Properties()

    properties["hasDog"] = False
    properties["name"] = "Manu"

    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 (
        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": "*****@*****.**", "userId": "user_id"}, "properties": {"hasdog": false, "name": "Manu"}})'
    )