def test_new_updates_only_one(): releases_info = get_info(example_file["new_releases_one_table"]) tweet_format = format_tweet.new_updates(list(releases_info), copy.deepcopy(stored_data)) assert tweet_format == example_file["new_releases_one_tweet"]
def test_get_info(): """ Tests get_info() on a big number of releases. Checks number of returned releases and if titles match. """ releases = example_file["last_one_year_table"] releases_info = get_info(releases) # check if get_info() returned the correct number of releases assert len(releases) == len(list(releases_info)) # check if titles match # useful for seeing which ones are missing if the above assert fails for i, value in enumerate(releases): title = re.findall(r"(?i)(?<=[>])[^<]+|^[^<]+", value[0])[0] # for releases like "macOS Monterey 12.0.1 (Advisory includes security content of..." title = title.split("(Advisory", 1)[0].strip() if "iOS" in title and "iPadOS" in title: # turn "iOS 15.3 and iPadOS 15.3" into shorter "iOS and iPadOS 15.3" title = title.split("and", 1)[0].strip().replace("iOS", "iOS and iPadOS") if "macOS" in title and "Update" in title: # for releases "macOS Big Sur 11.2.1, macOS Catalina 10.15.7 Supplemental Update,..." title = title.split(",", 1)[0].strip() title += " and older" assert title == releases_info[i].get_name()
def test_zero_day(): releases_info = get_info(example_file["zero_day_releases_table"]) compare(releases_info, example_file["zero_day_releases_info"]) tweet_format = format_tweet.zero_days(list(releases_info), copy.deepcopy(stored_data)) assert tweet_format == example_file["zero_day_releases_tweet"]
def test_ios_modules(): releases_info = get_info(example_file["ios_modules_table"]) compare(releases_info, example_file["ios_modules_info"]) tweet_format = format_tweet.top_ios_modules(list(releases_info), copy.deepcopy(stored_data)) assert tweet_format == example_file["ios_modules_tweet"]
def test_get_info_2(): releases_info = get_info(example_file["get_info_table"]) compare(releases_info, example_file["get_info_info"]) tweet_format = format_tweet.new_updates( list(releases_info), copy.deepcopy(example_file["stored_data"])) assert tweet_format == example_file["get_info_tweet"]
def yearly_report(release_rows: list, system: str, version: int, stored_data: dict) -> list: """ ----- iOS 15 was released today. In iOS 14 series Apple fixed in total of 346 security issues over 16 releases. 🔐 📊 COMPARED TO: - 301 fixed in iOS 13 over 18 releases - 339 fixed in iOS 12 over 33 releases - 310 fixed in iOS 11 over 17 releases ----- """ if system in stored_data["tweeted_today"]["yearly_report"]: return [] stored_data["tweeted_today"]["yearly_report"].append(system) system, versions = determine_latest_four_versions(system, version, release_rows) info = {} for ver in versions: info[ver] = {"num_of_bugs": 0, "num_of_releases": 0} for release in release_rows: if system in release[0] and str(ver) in release[0]: if "href" in release[0]: sec_content = get_info([release]) num = sec_content[0].get_num_of_bugs() if num > 0: info[ver]["num_of_bugs"] += num info[ver]["num_of_releases"] += 1 second_version = list(info.keys())[0] tweet_text = [ f"{system} {version} was released today. In {system} {second_version} series Apple fixed in total of {info[second_version]['num_of_bugs']} security issues over {info[second_version]['num_of_releases']} releases. :locked_with_key:\n\n:bar_chart: COMPARED TO:\n" ] del info[second_version] for key, value in info.items(): tweet_text.append( f"- {value['num_of_bugs']} fixed in {system} {key} over {value['num_of_releases']} releases\n" ) if system == "macOS": # for macOS create a thread with additional info in the second tweet tweet_text.append( "Numbers also contain issues from Security and Supplemental Updates." ) return tweet_text
import format_tweet from gather_info import determine_latest_versions, get_info from save_data import read_file, save_file from twitter import tweet MAIN_PAGE_HTML = ( requests.get("https://support.apple.com/en-us/HT201222").text.replace( "\n", "").replace(" ", " ")) all_releases = re.findall(r"(?<=<tr>).*?(?=<\/tr>)", MAIN_PAGE_HTML)[1:] for i, _ in enumerate(all_releases): all_releases[i] = re.findall(r"(?<=<td>).*?(?=<\/td>)", all_releases[i]) releases = all_releases[:20] releases_info = get_info(releases) stored_data, midnight = read_file() if midnight: # on midnight do checks with the previous date to not miss any # changes made between 11pm and 12pm check_date = datetime.date.today() - datetime.timedelta(1) else: check_date = datetime.date.today() date_format_one = f"{check_date.day:02d} {check_date.strftime('%b')} {check_date.year}" # Format: 08 Jan 2022 latest_versions = determine_latest_versions(releases)