def test_fetching_account_info_writes_to_missing_cache(self): account_info = AccountInfo.from_collected_data({ "username": "******", "total_stars": 3, "years": { 2020: { "year": 2020, "stars": 3, "days": { 1: 2, 2: 1, 3: 0, } }, }, }) with self.preparing_to_fetch_info(account_info) as controller: site_data_path = settings_proxy().site_data_path site_data_path.unlink() self.assertTrue(controller.fetch_account_info()) self.assertTrue(site_data_path.exists()) self.assertEqual(json.loads(site_data_path.read_text()), account_info.serialise()) self.assertTrue( controller.combined_info.get_part(2020, 2, 'a').has_star) self.assertFalse( controller.combined_info.get_part(2020, 3, 'a').has_star)
def test_generate_with_multiple_years_with_different_number_of_stars(self): combined_info = CombinedInfo.from_repo_and_account_infos( RepoInfo.from_roots([]), AccountInfo.from_collected_data({ "username": "******", "total_stars": 105, "years": { 2020: {"year": 2020, "stars": 50, "days": { day: 2 for day in range(1, 26) }}, 2019: {"year": 2019, "stars": 5, "days": { 1: 2, 2: 1, 3: 0, }}, 2018: {"year": 2018, "stars": 50, "days": { day: 2 for day in range(1, 26) }}, 2017: {"year": 2017, "stars": 0, "days": {}}, 2016: {"year": 2016, "stars": 1, "days": { 1: 1, }}, }, }), ) self.assertEqual(EventSummary().generate(combined_info), ( "\n\n" "| Total | 2020 | 2019 | 2018 | 2016 |\n" "| --- | --- | --- | --- | --- |\n" "| 105 :star: | 50 :star: :star: | 5 :star: | 50 :star: :star: " "| 1 :star: |\n" "\n" ))
def making_combined_info(parts_to_create_on_disk, collected_data): with creating_parts_on_disk(parts_to_create_on_disk): yield CombinedInfo \ .from_repo_and_account_infos( RepoInfo.from_roots(), AccountInfo.from_collected_data(collected_data), )
def get_combined_info(self): for part in self.parts_to_create_on_disk: settings_proxy().challenges_boilerplate.create_part(*part) return CombinedInfo\ .from_repo_and_account_infos( RepoInfo.from_roots(), AccountInfo.from_collected_data(self.collected_data), )
def test_generate_with_one_year_with_some_stars(self): combined_info = CombinedInfo.from_repo_and_account_infos( RepoInfo.from_roots([]), AccountInfo.from_collected_data({ "username": "******", "total_stars": 3, "years": { 2020: { "year": 2020, "stars": 3, "days": { 1: 2, 2: 1, 3: 0, } }, }, }), ) self.assertEqual( SubmissionsSummary().generate(combined_info), ("\n\n" "| | 2020 |\n" "| ---: | :---: |\n" "| | Code & [Challenges][ch-20] |\n" "| | 3 :star: / 0 :x: / 0 :grey_exclamation: |\n" "| 1 | Code :star: :star: [Challenge][ch-20-01] |\n" "| 2 | Code :star: [Challenge][ch-20-02] |\n" "| 3 | Code [Challenge][ch-20-03] |\n" "| 4 | Code [Challenge][ch-20-04] |\n" "| 5 | Code [Challenge][ch-20-05] |\n" "| 6 | Code [Challenge][ch-20-06] |\n" "| 7 | Code [Challenge][ch-20-07] |\n" "| 8 | Code [Challenge][ch-20-08] |\n" "| 9 | Code [Challenge][ch-20-09] |\n" "| 10 | Code [Challenge][ch-20-10] |\n" "| 11 | Code [Challenge][ch-20-11] |\n" "| 12 | Code [Challenge][ch-20-12] |\n" "| 13 | Code [Challenge][ch-20-13] |\n" "| 14 | Code [Challenge][ch-20-14] |\n" "| 15 | Code [Challenge][ch-20-15] |\n" "| 16 | Code [Challenge][ch-20-16] |\n" "| 17 | Code [Challenge][ch-20-17] |\n" "| 18 | Code [Challenge][ch-20-18] |\n" "| 19 | Code [Challenge][ch-20-19] |\n" "| 20 | Code [Challenge][ch-20-20] |\n" "| 21 | Code [Challenge][ch-20-21] |\n" "| 22 | Code [Challenge][ch-20-22] |\n" "| 23 | Code [Challenge][ch-20-23] |\n" "| 24 | Code [Challenge][ch-20-24] |\n" "| 25 | Code [Challenge][ch-20-25] |\n" + self.get_years_links([2020]) + "\n"))
def test_generate_with_no_info(self): combined_info = CombinedInfo.from_repo_and_account_infos( RepoInfo.from_roots([]), AccountInfo.from_collected_data({ "username": "******", "total_stars": 0, "years": {}, }), ) self.assertEqual(EventSummary().generate(combined_info), ( "\n\n" "| Total |\n" "| --- |\n" "| 0 :star: |\n" "\n" ))
def test_generate_with_one_year_with_no_stars(self): combined_info = CombinedInfo.from_repo_and_account_infos( RepoInfo.from_roots([]), AccountInfo.from_collected_data({ "username": "******", "total_stars": 0, "years": { 2020: { "year": 2020, "stars": 0, "days": {} }, }, }), ) self.assertEqual(SubmissionsSummary().generate(combined_info), ("\n\n" "| |\n" "| ---: |\n" "| |\n" "| |\n" "| 1 |\n" "| 2 |\n" "| 3 |\n" "| 4 |\n" "| 5 |\n" "| 6 |\n" "| 7 |\n" "| 8 |\n" "| 9 |\n" "| 10 |\n" "| 11 |\n" "| 12 |\n" "| 13 |\n" "| 14 |\n" "| 15 |\n" "| 16 |\n" "| 17 |\n" "| 18 |\n" "| 19 |\n" "| 20 |\n" "| 21 |\n" "| 22 |\n" "| 23 |\n" "| 24 |\n" "| 25 |\n" "\n" "\n" "\n"))
def fetch_account_info(self): """Refresh the stars from the AOC website""" account_info = AccountInfo.from_site() if account_info is None: click.echo(f"Could {e_error('not fetch data')}") return False if settings_proxy().site_data_path: with settings_proxy().site_data_path.open('w') as f: json.dump(account_info.serialise(), f, indent=2) self.update_combined_info(account_info=account_info) click.echo(f"Fetched data for {e_success(account_info.username)}: " f"{e_star(f'{str(account_info.total_stars)} stars')} in " f"{e_success(str(len(account_info.year_infos)))} years") return True
def test_generate_with_one_year_with_all_stars(self): combined_info = CombinedInfo.from_repo_and_account_infos( RepoInfo.from_roots([]), AccountInfo.from_collected_data({ "username": "******", "total_stars": 50, "years": { 2020: {"year": 2020, "stars": 50, "days": { day: 2 for day in range(1, 26) }}, }, }), ) self.assertEqual(EventSummary().generate(combined_info), ( "\n\n" "| Total | 2020 |\n" "| --- | --- |\n" "| 50 :star: | 50 :star: :star: |\n" "\n" ))
def reload_combined_info(self): """Reload all data from the disk""" self.update_combined_info( repo_info=RepoInfo.from_roots(), account_info=AccountInfo.from_cache(), )