def runTagCheckDouble(api_value, web_page_data1, web_page_data2, tag): """ Using the provided web page data sources, find the content for the tag. Then compare the content values with the expected api value. Return True or False. This function expects a content value and a two web page data sources. Use runTagCheck if expecting only one content value and one web page data source. Use runTagListCheck if expecting multiple content values (in a list). Use runTagListCheckDouble if there are two web page data sources AND content values are in a list. """ # Function returns string in upper case branch_io_tag_from_html_url1 = functions.get_meta_tag_content( web_page_data1, "", tag) branch_io_tag_from_html_url2 = functions.get_meta_tag_content( web_page_data2, "", tag) # Comparison time match1 = functions.compare(api_value, branch_io_tag_from_html_url1) match2 = functions.compare(api_value, branch_io_tag_from_html_url2) if match1 == True and match2 == True: message = " TEST for %s: %s\n" % (tag, PASSED) functions.show_message(message) return True else: message = " TEST for %s: %s\n" % (tag, FAILED) functions.show_message(message) return False
def test_nmc_pid(prod_web_page_data, preprod_web_page_data, expected_pid): """ Takes prod_web_page_data, preprod_web_page_data, and an expected_pid. The function will find the nmc:pid for each of the prod and preprod web pages. Then it will compare that pid with the expected pid. This function returns two results: true/false for the prod page and true/false for the preprod page. """ # Get the pid from the page. Function returns string in upper case. pid_from_html_prod = functions.get_meta_tag_content( prod_web_page_data, "", "nmc:pid") pid_from_html_preprod = functions.get_meta_tag_content( preprod_web_page_data, "", "nmc:pid") # Compares the expected pid with the one found on the page. Response is true if it is a match; false if not. print("Checking HTML nmc:pid on PROD") isMatch1 = functions.compare(expected_pid, pid_from_html_prod) print("Checking HTML nmc:pid on PREPROD") isMatch2 = functions.compare(expected_pid, pid_from_html_preprod) return isMatch1, isMatch2
def test_nmc_pid_single(web_page_data, expected_pid): """ Takes web_page_data and an expected_pid. The function will find the nmc:pid for the web page. Then it will compare that pid with the expected pid. This function returns one result: true/false. """ # Get the pid from the page. Function returns string in upper case. pid_from_html = functions.get_meta_tag_content(web_page_data, "", "nmc:pid") # Compares the expected pid with the one found on the page. Response is true if it is a match; false if not. print("Checking HTML nmc:pid") isMatch = functions.compare(expected_pid, pid_from_html) return isMatch
def runTagCheck(api_value, web_page_data, tag): """ Using the provided web page data source, find the content for the tag. Then compare that content value with the expected api value. Return True or False. This function expects a single content value and a single web page data source. Use runTagListCheck if expecting multiple content values (in a list). """ # Function returns string in upper case branch_io_tag_from_html_url = functions.get_meta_tag_content( web_page_data, "", tag) # Comparison time match = functions.compare(api_value, branch_io_tag_from_html_url) if match == True: message = " TEST for %s: %s\n" % (tag, PASSED) else: message = " TEST for %s: %s\n" % (tag, FAILED) functions.show_message(message) return match
# Compare and print expected vs actual metaTitle match = compareAndPrint(expected_title, meta_title) # Add to the counters if there wasn't a match if match == False: clay_meta_title_failed += 1 tests_failed += 1 # --------------------------------------------------------- # TEST 2 of 3: Match HTML og:title to expected_title # --------------------------------------------------------- print(" TEST 2 of 3 : Compare og.title to expected title") # Get the og:title content value from the Listen Live web page og_title = functions.get_meta_tag_content(page_source, "og:title") # Compare and print expected vs actual og:title match = compareAndPrint(expected_title, og_title) # Add to the counters if there wasn't a match if match == False: meta_tag_og_title_failed += 1 tests_failed += 1 # -------------------------------------------------------------------- # TEST 3 of 3: Match HTML og:description to Clay API metaDescription # -------------------------------------------------------------------- print(" TEST 3 of 3 : Compare og.description to metaDescription") # Call the Clay API for the dynamic meta description data
# ------------------------------------------------------------------------ # TEST 1 of 8: Compare Expected Title with HTML Title, OG Title, and # Twitter Title # ------------------------------------------------------------------------ print(" TEST 1 of 8: Title Check") # Build the expected title if station_slogan == None or station_slogan == "": expected_title = 'sanitized' % station_name else: expected_title = 'sanitized' % (station_name, station_slogan) expected_title = expected_title.upper() # Get the actual values from the web page html_title = functions.get_title(page_data) og_title = functions.get_meta_tag_content(page_data, "og:title", "") twitter_title = functions.get_meta_tag_content(page_data, "", "twitter:title") # Comparison time - all titles should match print(" Looking for : '%s'" % expected_title) print(" Title Tag Found : '%s'" % html_title) print(" OG Found : '%s'" % og_title) print(" Twitter Found : '%s'" % twitter_title) # Print Pass/Fail - Increment counters if actual/expected values don't match if expected_title == og_title and \ expected_title == twitter_title and \ expected_title == html_title: message = " TEST: %s\n" % PASSED else:
html_url = url["html_url"] # Get the API data podcast_data_text = functions.call_url(api_url) podcast_data = json.loads(podcast_data_text) # Get the web page data page_data = functions.call_url(html_url)[:PAGE_BUFFER] # API description is the expected description for the test expected_description = podcast_data["data"]["attributes"]["description"] # If the API doesn't have a description - log it expected_description = functions.isNoneOrEmpty(expected_description, "Podcast API Description") # Get the tag content values from the HTML page description = functions.get_meta_tag_content(page_data, "", "description") og_description = functions.get_meta_tag_content(page_data, "og:description") twitter_description = functions.get_meta_tag_content(page_data, "", "twitter:description") # Set value to empty string if value is ${PARAMVALUE} og_description = functions.check_for_empty(og_description) twitter_description = functions.check_for_empty(twitter_description) description = functions.check_for_empty(description) # Print something easy to see in the console print(" Looking for : '%s'" % expected_description) print(" OG Found : '%s'" % og_description) print(" Twitter Found : '%s'" % twitter_description) print(" HTML Desc Found : '%s'" % description) # If all match, then Pass. Else fail.
# Build the url to visit the podcast web page podcast_url = "sanitized" % site_slug # Call for the podcast web page data page_data = functions.call_url(podcast_url)[:PAGE_BUFFER] # ------------------------------------------------------------------------ # TEST 1 of 3: Compare API title with HTML <title>, og:title and # twitter:title. All 4 should match. # ------------------------------------------------------------------------ print(" TEST 1 of 3: Title Check") # If None/Empty, return empty string. Else return in uppercase. api_title = functions.isNoneOrEmpty(api_title, "Podcast API Title") # Function returns string in upper case html_title = functions.get_title(page_data) og_title = functions.get_meta_tag_content(page_data, "og:title") twitter_title = functions.get_meta_tag_content(page_data, "", "twitter:title") # Comparison time - all titles should match print(" Looking for : '%s'" % api_title) print(" OG Found : '%s'" % og_title) print(" Twitter Found : '%s'" % twitter_title) print(" HTML Title Found : '%s'" % html_title) # If they all match, test passes. Else, test fails. if api_title == og_title and api_title == twitter_title and \ api_title == html_title: message = " TEST 1 of 3: %s" % PASSED tests_passed_for_this_podcast += 1 else:
# If station_slogan is None...or empty....the expected title changes if station_slogan == None or station_slogan == "": expected_title = 'sanitized' % station_name else: expected_title = 'sanitized' % (station_name, station_slogan) expected_title = expected_title.upper() # ------------------------------------------------------------------ # TEST: Compare Station API title with HTML <title>, og:title and # twitter:title. All 4 should match. # ------------------------------------------------------------------ print(" TEST: Title Comparison") # Function returns string in upper case html_title = functions.get_title(page_source) og_title = functions.get_meta_tag_content(page_source, "og:title") twitter_title = functions.get_meta_tag_content(page_source,"", "twitter:title") # Comparison time - all titles should match print(" Looking for : '%s'" % expected_title) print(" Title Tag Found: '%s'" % html_title) print(" OG Found : '%s'" % og_title) print(" Twitter Found : '%s'" % twitter_title) if expected_title == og_title and expected_title == twitter_title and \ expected_title == html_title: message = " TEST: %s\n" % PASSED else: message = " TEST: %s\n" % FAILED stations_failed += 1 functions.show_message(message)