def test_categories_share(self, categories_number, json): assert "ic8.link" in json_parse(json, ["result", "categories", categories_number, "share", "url"]) try: assert "icons8.com" in json_parse(json, ["result", "categories", categories_number, "share", "share_preview"]) assert "icons8.com" in json_parse(json, ["result", "categories", categories_number, "share", "icons_preview"]) except: pass
def test_description(self, param_test): (json) = param_test try: assert len(json_parse(json, ["result", "description"])) > 5 assert len(json_parse(json, ["result", "description"])) >= 0 except KeyError: pass
def test_var_share(self, variant, json): assert ".ic8.link" in json_parse( json, ["result", "icons", 0, "variants", variant, "share", "url"]) assert "icons" in json_parse(json, [ "result", "icons", 0, "variants", variant, "share", "png", 0, "link" ]) for share in range( 1, len( json_parse(json, [ "result", "icons", 0, "variants", variant, "share" ]))): try: assert json_parse(json, [ "result", "icons", 0, "variants", variant, "share", "png", share, "type" ]) == 'twitter' or 'social' assert "icons" in json_parse(json, [ "result", "icons", 0, "variants", variant, "png", share, "link" ]) except IndexError: pass
def test_parameters(self, param_test): (json) = param_test platform = json_parse(json, ["parameters", "platform"]) assert platform == ContextCategories3vApiJson.platform, \ '>>> %s - "platform" in response, %s - in request<<<' % (platform, ContextCategories3vApiJson.platform) language = json_parse(json, ["parameters", "language"]) assert language == None, '>>> %s - "language" in response, None- in request <<<' % language
def test_share(self, param_test): (json) = param_test assert "ic8.link" in json_parse(json, ["result", "category", "share", 'url']) assert "icons8.com/Share/category/" in json_parse( json, ["result", "category", "share", 'share_preview']) assert "icons8.com/Share/category_icons/" in json_parse( json, ["result", "category", "share", 'icons_preview'])
def test_total(self, total_numbers, json): name = json_parse(json, ["result", "total", total_numbers, "name"]) assert len(name) > 0 assert len( json_parse(json, ["result", "total", total_numbers, "api_code"])) > 0 assert json_parse(json, ["result", "total", total_numbers, "total"]) >= 0
def test_tags_object(self, param_test): (json) = param_test try: for tag in range( len(json_parse(json, ["result", "icons", 0, "tags"]))): assert len( json_parse(json, ["result", "icons", 0, "tags", tag])) > 0 except KeyError: pass
def test_subcategory(self, param_test): (json) = param_test assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'subcategory_code' ])) > 0 assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'subcategory_code' ])) > 0
def test_png_object(self, param_test): (json) = param_test png_count = json_parse(json, ["result", "icons", 0, "png"]) for png in range(len(png_count)): assert json_parse(json, ["result", "icons", 0, "png", png, "width"]) > 15 assert json_parse( json, ["result", "icons", 0, "png", png, "height"]) > 15 assert 'https://' in json_parse( json, ["result", "icons", 0, "png", png, "link"])
def test_category(self, param_test): (json) = param_test name = json_parse(json, ["result", "category", "name"]) assert name == ContextCategoryApiJson.category, \ '>>> %s - "name" in response, %s - in request <<<' % (name, ContextCategoryApiJson.category) assert json_parse(json, ["result", "category", "description"]) == '' or str assert json_parse(json, ["result", "category", "usage_story"]) == '' or str
def test_story(self, param_test): (json) = param_test assert len(json_parse(json, ["result", "category", "story", "text"])) > 15 assert len( json_parse(json, ["result", "category", "story", "author_name"])) >= 2 for story in ["author_photo", "author_link", "date"]: assert json_parse( json, ["result", "category", "story", story]) == '' or str
def test_category(self, param_test): (json) = param_test category_code = json_parse(json, ["result", "category", "category_code"]) assert category_code.lower() == ContextCategoryv3ApiJson.category.lower(), \ '>>> %s - "category_code" in response, %s - in request <<<' \ % (category_code, ContextCategoryv3ApiJson.category) category_name = json_parse(json, ["result", "category", "category_name"]) assert category_name == ContextCategoryv3ApiJson.category, \ '>>> %s "" in response, %s - in request <<<' % (category_name, ContextCategoryv3ApiJson.category)
def test_categories(self, param_test): (json) = param_test categories_count = len(json_parse(json, ["result", "categories"])) for categories_num in range(categories_count): assert len( json_parse( json, ["result", "categories", categories_num, "name"])) > 1 assert len( json_parse( json, ["result", "categories", categories_num, "api_code"])) > 1
def test_subcategory_object(self, param_test): (json) = param_test try: assert len( json_parse(json, ["result", "icons", 0, "subcategory", "name"])) > 0 assert len( json_parse( json, ["result", "icons", 0, "subcategory", "api_code"])) > 1 except KeyError: pass
def test_share_object(self, param_test): (json) = param_test assert ".ic8.link" in json_parse( json, ["result", "icons", 0, "share", "url"]) assert "icons" in json_parse( json, ["result", "icons", 0, "share", "png", 0, "link"]) for share in range( 1, len(json_parse(json, ["result", "icons", 0, "share"]))): assert json_parse( json, ["result", "icons", 0, "share", "png", share, "type" ]) == 'twitter' or 'social' assert "icons" in json_parse( json, ["result", "icons", 0, "share", "png", share, "link"])
def test_var_subcategory(self, variant, json): try: assert len( json_parse(json, [ "result", "icons", 0, "variants", variant, "subcategory", "name" ])) > 0 assert len( json_parse(json, [ "result", "icons", 0, "variants", variant, "subcategory", "api_code" ])) > 1 except KeyError: pass
def test_icons_subcategory(self, icon_number, json): try: assert len( json_parse(json, [ "result", "category", "icons", icon_number, "subcategory", "name" ])) >= 2 assert len( json_parse(json, [ "result", "category", "icons", icon_number, "subcategory", "api_code" ])) >= 2 except KeyError: pass
def test_var_tags(self, variant, json): try: for tag in range( len( json_parse(json, [ "result", "icons", 0, "variants", variant, "tags" ]))): assert len( json_parse(json, [ "result", "icons", 0, "variants", variant, "tags", tag ])) > 0 except KeyError: pass
def test_icons_png(self, icon_number, json): png_count = json_parse( json, ["result", "category", "icons", icon_number, "png"]) for png in range(len(png_count)): assert json_parse(json, [ "result", "category", "icons", icon_number, "png", png, "width" ]) > 20 assert json_parse(json, [ "result", "category", "icons", icon_number, "png", png, "height" ]) > 20 link = json_parse(json, [ "result", "category", "icons", icon_number, "png", png, "link" ]) assert link.find(ContextCategoryApiJson.category), \ '>>> %s - in response, %s - in request <<<' % (link, ContextCategoryApiJson.category)
def test_parameters(self, param_test): (json) = param_test amount = json_parse(json, ["parameters", "amount"]) assert amount == ContextLatestApiJson.amount, \ '>>> %s "amount" in response, %s - in request <<<' % (amount, ContextLatestApiJson.amount) offset = json_parse(json, ["parameters", "offset"]) assert offset == ContextLatestApiJson.offset, \ '>>> %s "offset" in response, %s - in request <<<' % (offset, ContextLatestApiJson.offset) platform = json_parse(json, ["parameters", "platform"]) assert platform == ContextLatestApiJson.platform, \ '>>> %s "platform" in response, %s - in request <<<' % (offset, ContextLatestApiJson.platform) impresser_preview = json_parse(json, ["parameters", "impresser_preview"]) assert impresser_preview == str(ContextLatestApiJson.impresser_preview), \ '>>> %s "impresser_preview" in response, %s - in request <<<' \ % (impresser_preview, ContextLatestApiJson.impresser_preview) assert json_parse(json, ["parameters", "language"]) == 'en'
class TestTotaltpiJson(ContextTotalApiJson): # Test total object def test_parameters(self, param_test): (json) = param_test assert json_parse(json, ["parameters", "since"]) == ContextTotalApiJson.since total_numbers = [] total_count = len( json_parse(ContextTotalApiJson.response_root_auth, ["result", "total"])) for total_num in range(total_count): total_numbers.append(total_num) @pytest.mark.parametrize("total_numbers", total_numbers) @pytest.mark.parametrize("json", [ ContextTotalApiJson.response_root, ContextTotalApiJson.response_root_auth ]) # Test total object def test_total(self, total_numbers, json): name = json_parse(json, ["result", "total", total_numbers, "name"]) assert len(name) > 0 assert len( json_parse(json, ["result", "total", total_numbers, "api_code"])) > 0 assert json_parse(json, ["result", "total", total_numbers, "total"]) >= 0
def test_var_png(self, variant, json): png_count = json_parse( json, ["result", "icons", 0, "variants", variant, "png"]) for png in range(len(png_count)): assert json_parse(json, [ "result", "icons", 0, "variants", variant, "png", png, "width" ]) > 15, ">>> <<<" assert json_parse(json, [ "result", "icons", 0, "variants", variant, "png", png, "height" ]) > 15, ">>> <<<" assert 'https://' in json_parse(json, [ "result", "icons", 0, "variants", variant, "png", png, "link" ])
def test_share(self, param_test): (json) = param_test response_url = json_parse(json, ["result", "category", "share", "url"]) assert 'ic8.link/%s' % ContextCategoryApiJson.category.lower( ) in response_url response_share_preview = json_parse( json, ["result", "category", "share", "share_preview"]) assert '.icons8.com/Share/category/%s.png'.lower( ) % ContextCategoryApiJson.category.lower( ) in response_share_preview.lower() response_icons_preview = json_parse( json, ["result", "category", "share", "icons_preview"]) assert response_icons_preview.find(ContextCategoryApiJson.category), \ '>>> %s - in response, %s - in request <<<' % (response_icons_preview, ContextCategoryApiJson.category)
def test_icons(self, icon_number, json): assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'id' ])) > 0 assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'name' ])) > 0 assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'platform_code' ])) > 0 assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'created' ])) > 20 assert '/icon/' in json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'url' ]) assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'common_icon_id' ])) > 1 assert len( json_parse(json, [ "result", "category", "subcategory", 0, 'icons', icon_number, 'svg' ])) > 20
def test_request_object(self, param_test): (json) = param_test try: assert len( json_parse(json, ["result", "icons", 0, "request", "text"])) > 1 assert json_parse(json, ["result", "icons", 0, "request", "link" ])[:22] == 'http://buzz.icons8.com' assert len( json_parse(json, ["result", "icons", 0, "request", "author"])) > 1 assert json_parse( json, ["result", "icons", 0, "request", "created"])[:2] == '20' assert json_parse( json, ["result", "icons", 0, "request", "competed"])[:2] == '20' except KeyError: pass
def test_latest(self, latest_numbers, json): assert json_parse(json, ["result", "latest", latest_numbers, "id"]) >= 1 assert len(json_parse(json, ["result", "latest", latest_numbers, "id"])) > 1 platform_code = json_parse(json, ["result", "latest", latest_numbers, "platform_code"]) assert platform_code == ContextLatestApiJson.platform, \ '>>> %s "platform_code" in response, %s - in request <<<' % (platform_code, ContextLatestApiJson.platform) assert json_parse(json, ["result", "latest", latest_numbers, "created"])[:2] == '20' assert len(json_parse(json, ["result", "latest", latest_numbers, "created"])) >= 25 assert '/icon/' in json_parse(json, ["result", "latest", latest_numbers, "url"]) assert len(json_parse(json, ["result", "latest", latest_numbers, "common_icon_id"])) > 0 assert len(json_parse(json, ["result", "latest", latest_numbers, "svg"])) > 20
def test_variants_icon(self, variant, json): assert len( json_parse(json, ["result", "icons", 0, "variants", variant, "name" ])) > 0, ">>> <<<" platform = json_parse( json, ["result", "icons", 0, "variants", variant, "platform"]) assert len(platform) > 0, \ ">>> %s - not know this platform <<<" % platform platform_code = json_parse( json, ["result", "icons", 0, "variants", variant, "platform_code"]) assert len(platform) > 0,\ ">>> %s - not know this platform <<<" % platform assert json_parse( json, ["result", "icons", 0, "variants", variant, "created" ])[:2] == "20" assert len( json_parse(json, [ "result", "icons", 0, "variants", variant, "created" ])) > 15 assert json_parse( json, ["result", "icons", 0, "variants", variant, "copyright" ]) == False assert json_parse( json, ["result", "icons", 0, "variants", variant, "filled" ]) == False or True assert "icons8.com/web-app/" in json_parse( json, ["result", "icons", 0, "variants", variant, "disqus_url"]) assert len( json_parse(json, [ "result", "icons", 0, "variants", variant, "category" ])) > 2 assert len( json_parse( json, ["result", "icons", 0, "variants", variant, "svg"])) > 40
def test_var_request(self, variant, json): try: assert len( json_parse(json, [ "result", "icons", 0, "variants", variant, "request", "text" ])) > 10, ">>> <<<" assert json_parse(json, [ "result", "icons", 0, "variants", variant, "request", "link" ])[:22] == 'http://buzz.icons8.com' assert len( json_parse( json, ["result", "icons", 0, "request", "author"])) > 1 assert json_parse(json, [ "result", "icons", 0, "variants", variant, "request", "created" ])[:2] == '20' assert json_parse(json, [ "result", "icons", 0, "variants", variant, "request", "competed" ])[:2] == '20' except KeyError: pass
def test_icons_share(self, icon_number, json): assert ".ic8.link" in json_parse( json, ["result", "category", "icons", icon_number, "share", "url"]) try: assert json_parse(json, [ "result", "category", "icons", icon_number, "share", "png", 1, "type" ]) == 'twitter' assert json_parse(json, [ "result", "category", "icons", icon_number, "share", "png", 2, "type" ]) == 'social' except IndexError: pass link_count = len( json_parse( json, ["result", "category", "icons", icon_number, "share", "png"])) for link in range(link_count): assert "icons8.com" in json_parse(json, [ "result", "category", "icons", icon_number, "share", "png", link, "link" ])
def test_result_icon_object(self, param_test): (json) = param_test assert len(json_parse(json, ["result", "icons", 0, "name" ])) > 1, ">>> word count of 'name' > 1 <<<" platform = json_parse(json, ["result", "icons", 0, "platform"]) assert len(platform) > 0\ , ">>> %s - not know this platform <<<" % platform platform_code = json_parse(json, ["result", "icons", 0, "platform_code"]) assert len(platform) > 0, \ ">>> %s - not know this platform_code <<<" % platform_code assert json_parse(json, ["result", "icons", 0, "created"])[:2] == "20" assert len(json_parse(json, ["result", "icons", 0, "created"])) > 15 assert json_parse(json, ["result", "icons", 0, "copyright"]) == False assert "icons8.com/web-app/" in json_parse( json, ["result", "icons", 0, "disqus_url"]) assert len(json_parse(json, ["result", "icons", 0, "category"])) > 2 assert len(json_parse(json, ["result", "icons", 0, "svg"])) > 40