def test_traffic_client_traffic_completes_full_url():
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/traffic?UserKey=test_key")
    f = "{0}/fixtures/traffic_client_traffic_good_response.json".format(TD)
    with open(f) as data_file:
        stringified = json.dumps(json.load(data_file))
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = TrafficClient("test_key")
        client.traffic("example.com")

    assert client.full_url == target_url
def test_traffic_client_traffic_completes_full_url():
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/traffic?UserKey=test_key")
    f = "{0}/fixtures/traffic_client_traffic_good_response.json".format(TD)
    with open(f) as data_file:
        stringified = json.dumps(json.load(data_file))
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = TrafficClient("test_key")
        client.traffic("example.com")

    assert client.full_url == target_url
def test_traffic_client_traffic_from_good_inputs():
    expected = {"GlobalRank": 2,
                "CountryCode": 840,
                "CountryRank": 1,
                "TopCountryShares": {
                    "840": 0.4191358779109708,
                    "356": 0.04602783067100975,
                    "876": 6.869084578359956e-7,
                    "10": 0},
                "TrafficReach": {
                    "02/01/2015": 0.16306846864268815,
                    "09/01/2015": 0.16501993162160358,
                    "16/01/2015": 0.1655193577048118,
                    "23/01/2015": 0.1665235785224394,
                    "30/01/2015": 0.16295290825680991},
                "TrafficShares": {
                    "Search": 0.10429090056545187,
                    "Social": 0.030245335003191837,
                    "Mail": 0.0041178890588041694,
                    "Paid Referrals": 0.0015840071128134063,
                    "Direct": 0.6771397777323854,
                    "Referrals": 0.1826220905273533},
                "Date": "01/2015"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/traffic?UserKey=test_key")
    f = "{0}/fixtures/traffic_client_traffic_good_response.json".format(TD)
    with open(f) as data_file:
        stringified = json.dumps(json.load(data_file))
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = TrafficClient("test_key")
        result = client.traffic("example.com")

        assert result == expected
def test_traffic_client_traffic_response_from_empty_response():
    expected = {"Error": "Unknown Error"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/traffic?UserKey=test_key")
    f = "{0}/fixtures/traffic_client_traffic_empty_response.json".format(TD)
    with open(f) as data_file:
        stringified = json.dumps(json.load(data_file))
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = TrafficClient("test_key")
        result = client.traffic("example.com")

        assert result == expected
def test_traffic_client_traffic_response_from_empty_response():
    expected = {"Error": "Unknown Error"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/traffic?UserKey=test_key")
    f = "{0}/fixtures/traffic_client_traffic_empty_response.json".format(TD)
    with open(f) as data_file:
        stringified = json.dumps(json.load(data_file))
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = TrafficClient("test_key")
        result = client.traffic("example.com")

        assert result == expected
def test_traffic_client_traffic_from_good_inputs():
    expected = {
        "GlobalRank": 2,
        "CountryCode": 840,
        "CountryRank": 1,
        "TopCountryShares": {
            "840": 0.4191358779109708,
            "356": 0.04602783067100975,
            "876": 6.869084578359956e-7,
            "10": 0
        },
        "TrafficReach": {
            "02/01/2015": 0.16306846864268815,
            "09/01/2015": 0.16501993162160358,
            "16/01/2015": 0.1655193577048118,
            "23/01/2015": 0.1665235785224394,
            "30/01/2015": 0.16295290825680991
        },
        "TrafficShares": {
            "Search": 0.10429090056545187,
            "Social": 0.030245335003191837,
            "Mail": 0.0041178890588041694,
            "Paid Referrals": 0.0015840071128134063,
            "Direct": 0.6771397777323854,
            "Referrals": 0.1826220905273533
        },
        "Date": "01/2015"
    }
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/traffic?UserKey=test_key")
    f = "{0}/fixtures/traffic_client_traffic_good_response.json".format(TD)
    with open(f) as data_file:
        stringified = json.dumps(json.load(data_file))
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = TrafficClient("test_key")
        result = client.traffic("example.com")

        assert result == expected