Ejemplo n.º 1
0
def test_traffic_client_visit_duration_completes_full_url():
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/visitduration?gr=monthly&start=11-2014"
                  "&end=12-2014&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_visit_duration_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.visit_duration("example.com", "monthly",
                              "11-2014", "12-2014", False)

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

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

        assert result == expected
Ejemplo n.º 4
0
def test_traffic_client_visit_duration_response_from_good_inputs():
    expected = {"2014-11-01": 971.0572442455453,
                "2014-12-01": 961.5564560783813}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/visitduration?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_visit_duration_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.visit_duration("example.com", "monthly",
                                       "11-2014", "12-2014", False)

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

        assert result == expected
def test_traffic_client_visit_duration_response_from_good_inputs():
    expected = {
        "2014-11-01": 971.0572442455453,
        "2014-12-01": 961.5564560783813
    }
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v1/visitduration?gr=monthly"
                  "&start=11-2014&end=12-2014"
                  "&md=False&UserKey=test_key")
    f = "{0}/fixtures/traffic_client_visit_duration_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.visit_duration("example.com", "monthly", "11-2014",
                                       "12-2014", False)

        assert result == expected