def test_content_client_category_rank_completes_full_url(): target_url = ("https://api.similarweb.com/Site/" "example.com/v2/categoryrank?UserKey=test_key") f = "{0}/fixtures/content_client_category_rank_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_rank("example.com") assert client.full_url == target_url
def test_content_client_category_rank_response_from_good_inputs(): expected = {"Category": "Sports/Basketball", "CategoryRank": 1} target_url = ("https://api.similarweb.com/Site/" "example.com/v2/categoryrank?UserKey=test_key") f = "{0}/fixtures/content_client_category_rank_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_rank("example.com") assert result == expected
def test_content_client_category_rank_response_from_empty_response(): expected = {"Error": "Unknown Error"} target_url = ("https://api.similarweb.com/Site/" "example.com/v2/categoryrank?UserKey=test_key") f = "{0}/fixtures/content_client_category_rank_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 = ContentClient("test_key") result = client.category_rank("example.com") assert result == expected
def test_content_client_category_rank_response_from_malformed_url_incl_http(): expected = {"Error": "Malformed or Unknown URL"} target_url = ("https://api.similarweb.com/Site/" "https://example.com/v2/categoryrank?UserKey=test_key") f = "{0}/fixtures/content_client_category_rank_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_rank("https://example.com") assert result == expected