예제 #1
0
def test_content_client_category_completes_full_url():
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v2/category?UserKey=test_key")
    f = "{0}/fixtures/content_client_category_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 = ContentClient("test_key")
        client.category("example.com")

        assert client.full_url == target_url
예제 #2
0
def test_content_client_category_response_from_good_inputs():
    expected = {"Category": "Sports/Basketball"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v2/category?UserKey=test_key")
    f = "{0}/fixtures/content_client_category_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 = ContentClient("test_key")
        result = client.category("example.com")

        assert result == expected
예제 #3
0
def test_content_client_category_response_from_malformed_url_incl_http():
    expected = {"Error": "Malformed or Unknown URL"}
    target_url = ("https://api.similarweb.com/Site/"
                  "https://example.com/v2/category?UserKey=test_key")
    f = "{0}/fixtures/content_client_category_url_with_http_response.json".format(
        TD)
    with open(f) as data_file:
        stringified = data_file.read().replace("\n", "")
        httpretty.register_uri(httpretty.GET, target_url, body=stringified)
        client = ContentClient("test_key")
        result = client.category("https://example.com")

        assert result == expected
예제 #4
0
def test_content_client_category_response_from_malformed_url():
    expected = {"Error": "Malformed or Unknown URL"}
    target_url = ("https://api.similarweb.com/Site/"
                  "bad_url/v2/category?UserKey=test_key")
    f = "{0}/fixtures/content_client_category_url_malformed_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 = ContentClient("test_key")
        result = client.category("bad_url")

        assert result == expected
예제 #5
0
def test_content_client_category_response_from_invalid_api_key():
    expected = {"Error": "user_key_invalid"}
    target_url = ("https://api.similarweb.com/Site/"
                  "example.com/v2/category?UserKey=invalid_key")
    f = "{0}/fixtures/content_client_category_invalid_api_key_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 = ContentClient("invalid_key")
        result = client.category("example.com")

        assert result == expected