def test_traffic_client_page_views_completes_full_url():
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly&start=11-2014"
                  "&end=12-2014&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_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.page_views("example.com", "monthly", "11-2014", "12-2014", False)

    assert client.full_url == target_url
def test_traffic_client_page_views_completes_full_url():
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly&start=11-2014"
                  "&end=12-2014&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_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.page_views("example.com", "monthly", "11-2014", "12-2014",
                          False)

    assert client.full_url == target_url
def test_traffic_client_page_views_response_from_empty_response():
    expected = {"Error": "Unknown Error"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_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.page_views("example.com", "monthly",
                                   "11-2014", "12-2014", False)

        assert result == expected
def test_traffic_client_page_views_response_from_bad_main_domain():
    expected = {"Error": "The value 'other' is not valid for Md."}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=other&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_main_domain_bad_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.page_views("example.com", "monthly",
                                  "11-2014", "12-2014", "other")

        assert result == expected
def test_traffic_client_page_views_response_from_empty_response():
    expected = {"Error": "Unknown Error"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_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.page_views("example.com", "monthly", "11-2014",
                                   "12-2014", False)

        assert result == expected
def test_traffic_client_page_views_response_from_good_inputs():
    expected = {"2014-11-01": 14.722378910549942,
                "2014-12-01": 14.23604875567647}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_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.page_views("example.com", "monthly",
                                   "11-2014", "12-2014", False)

        assert result == expected
def test_traffic_client_page_views_response_from_bad_main_domain():
    expected = {"Error": "The value 'other' is not valid for Md."}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=other&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_main_domain_bad_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.page_views("example.com", "monthly", "11-2014",
                                   "12-2014", "other")

        assert result == expected
def test_traffic_client_page_views_response_from_good_inputs():
    expected = {
        "2014-11-01": 14.722378910549942,
        "2014-12-01": 14.23604875567647
    }
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/pageviews?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_page_views_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.page_views("example.com", "monthly", "11-2014",
                                   "12-2014", False)

        assert result == expected