From 5672e2b2842ca15a985bba0785595179e28359e6 Mon Sep 17 00:00:00 2001 From: John Mertic Date: Mon, 25 Nov 2024 10:28:59 -0500 Subject: [PATCH] More test coverage (#22) Signed-off-by: John Mertic --- lfx_tac_actions/updatetacagendaitems.py | 4 +- test/test_updatetacagendaitems.py | 54 +++++++++++++++++++++---- test/test_updatetacmembers.py | 18 ++++++++- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/lfx_tac_actions/updatetacagendaitems.py b/lfx_tac_actions/updatetacagendaitems.py index 264955e..4a005b2 100755 --- a/lfx_tac_actions/updatetacagendaitems.py +++ b/lfx_tac_actions/updatetacagendaitems.py @@ -27,9 +27,9 @@ def main(): csv_rows = [] try: project_data = json.loads(json_project_data) - except: + except ValueError: print("Invalid response from gh client: '{}'".format(command.stderr)) - sys.exit(0) + return for item in project_data.get('items',[]): print("Processing {}...".format(item['content']['title'])) diff --git a/test/test_updatetacagendaitems.py b/test/test_updatetacagendaitems.py index d07969d..ff9e3ce 100644 --- a/test/test_updatetacagendaitems.py +++ b/test/test_updatetacagendaitems.py @@ -16,7 +16,7 @@ class TestUpdateTACAgendaItems(unittest.TestCase): @unittest.mock.patch.dict(os.environ, {"TAC_AGENDA_GH_PROJECT_URL": ""}, clear=True) - def testMainNoLandscapeUrl(self): + def testMainNoTACAgendaUrl(self): with tempfile.TemporaryDirectory() as tempdir: tmpfilepath = os.path.join(tempdir, 'someFileInTmpDir.csv') with unittest.mock.patch('argparse.ArgumentParser.parse_args') as mock: @@ -24,12 +24,26 @@ def testMainNoLandscapeUrl(self): main() self.assertFalse(os.path.exists(tmpfilepath), f"File '{tmpfilepath}' exists.") - @responses.activate + def testMainBrokenTACAgendaUrls(self): + brokenurls = [ + "https://google.com/d/d", + "https://github.com/orgs/openmainframeproject/settings", + ] + for brokenurl in brokenurls: + with unittest.mock.patch.dict(os.environ, {"TAC_AGENDA_GH_PROJECT_URL": brokenurl}, clear=True): + with tempfile.TemporaryDirectory() as tempdir: + tmpfilepath = os.path.join(tempdir, 'someFileInTmpDir.csv') + with unittest.mock.patch('argparse.ArgumentParser.parse_args') as mock: + mock.return_value = argparse.Namespace(output=tmpfilepath) + main() + self.assertFalse(os.path.exists(tmpfilepath), f"File '{tmpfilepath}' exists.") + @unittest.mock.patch.dict(os.environ, {"TAC_AGENDA_GH_PROJECT_URL": "https://github.com/orgs/openmainframeproject/projects/21"}, clear=True) @unittest.mock.patch('subprocess.run') - def testMain(self, mock_run): + def testMainInvalidJSONResponse(self, mock_run): mock_result = unittest.mock.Mock() - mock_result.stdout = '{"items":[{"assignees":["carolalynn"],"content":{"body":"","number":473,"repository":"AcademySoftwareFoundation/tac","title":"D&I Working Group","type":"Issue","url":"https://github.com/AcademySoftwareFoundation/tac/issues/473"},"id":"PVTI_lADOAm6tAs4AS_w4zgJSO7E","labels":["2-annual-review"],"landscape URL":"https://landscape.aswf.io/card-mode?project=working-group&selected=d-i-working-group","pCC Project ID":"a092M00001KWjDZQA1","pCC TSC Committee ID":"ac9cbe7f-0dc8-4be0-b404-cb7b9b0bb22f","repository":"https://github.com/AcademySoftwareFoundation/tac","scheduled Date":"2024-12-11","status":"Next Meeting Agenda Items","title":"D&I Working Group"}],"totalCount":32}' + mock_result.stdout = 'error 12121212' + mock_result.stderr = 'foo' mock_run.return_value = mock_result with tempfile.TemporaryDirectory() as tempdir: @@ -37,11 +51,35 @@ def testMain(self, mock_run): with unittest.mock.patch('argparse.ArgumentParser.parse_args') as mock: mock.return_value = argparse.Namespace(output=tmpfilepath) main() + self.assertFalse(os.path.exists(tmpfilepath), f"File '{tmpfilepath}' exists.") + + @unittest.mock.patch.dict(os.environ, {"TAC_AGENDA_GH_PROJECT_URL": "https://github.com/orgs/openmainframeproject/projects/21"}, clear=True) + @unittest.mock.patch('subprocess.run') + def testMain(self, mock_run): + labelList = { + '"2-annual-review"': '2-annual-review', + '"1-new-project-wg"': '1-new-project-wg', + '"2-annual-review-tac"': '2-annual-review', + '"2-annual-review-sig"': '2-annual-review-sig', + '"3-tac-meeting-long"': '3-tac-meeting-long', + '"4-tac-meeting-short"': '4-tac-meeting-short', + '"5-annual-review-sig"': '', + } + for label, output in labelList.items(): + mock_result = unittest.mock.Mock() + mock_result.stdout = '{"items":[{"assignees":["carolalynn"],"content":{"body":"","number":473,"repository":"AcademySoftwareFoundation/tac","title":"D&I Working Group","type":"Issue","url":"https://github.com/AcademySoftwareFoundation/tac/issues/473"},"id":"PVTI_lADOAm6tAs4AS_w4zgJSO7E","labels":['+label+'],"landscape URL":"https://landscape.aswf.io/card-mode?project=working-group&selected=d-i-working-group","pCC Project ID":"a092M00001KWjDZQA1","pCC TSC Committee ID":"ac9cbe7f-0dc8-4be0-b404-cb7b9b0bb22f","repository":"https://github.com/AcademySoftwareFoundation/tac","scheduled Date":"2024-12-11","status":"Next Meeting Agenda Items","title":"D&I Working Group"}],"totalCount":32}' + mock_run.return_value = mock_result + + with tempfile.TemporaryDirectory() as tempdir: + tmpfilepath = os.path.join(tempdir, 'someFileInTmpDir.csv') + with unittest.mock.patch('argparse.ArgumentParser.parse_args') as mock: + mock.return_value = argparse.Namespace(output=tmpfilepath) + main() - with open(tmpfilepath, 'r') as tmpfile: - self.maxDiff = None - self.assertEqual(tmpfile.read(),'''title,url,number,scheduled_date,status,last_review_date,meeting_label -D&I Working Group,https://github.com/AcademySoftwareFoundation/tac/issues/473,473,2024-12-11,Next Meeting Agenda Items,,2-annual-review + with open(tmpfilepath, 'r') as tmpfile: + self.maxDiff = None + self.assertEqual(tmpfile.read(),f'''title,url,number,scheduled_date,status,last_review_date,meeting_label +D&I Working Group,https://github.com/AcademySoftwareFoundation/tac/issues/473,473,2024-12-11,Next Meeting Agenda Items,,{output} ''') if __name__ == '__main__': diff --git a/test/test_updatetacmembers.py b/test/test_updatetacmembers.py index 1422dac..49f285f 100644 --- a/test/test_updatetacmembers.py +++ b/test/test_updatetacmembers.py @@ -16,7 +16,7 @@ class TestUpdateTACMembers(unittest.TestCase): @unittest.mock.patch.dict(os.environ, {"LFX_TAC_COMMITTEE_URL": ""}, clear=True) - def testMainNoLandscapeUrl(self): + def testMainNoLFXTACCommitteeURL(self): with tempfile.TemporaryDirectory() as tempdir: tmpfilepath = os.path.join(tempdir, 'someFileInTmpDir.csv') with unittest.mock.patch('argparse.ArgumentParser.parse_args') as mock: @@ -24,6 +24,22 @@ def testMainNoLandscapeUrl(self): main() self.assertFalse(os.path.exists(tmpfilepath), f"File '{tmpfilepath}' exists.") + def testMainBrokenTACCommitteeURLs(self): + brokenurls = [ + "https://projectadmin.lfx.linuxfoundation.org/dog/a0941000002wBymAAE/collaboration/committees/163b26f7-a49b-40a3-89bb-e0592296c003", + "https://projectadmin.lfx.linuxfoundation.org/project/a0941000002wBymAAE/collab/committees/163b26f7-a49b-40a3-89bb-e0592296c003", + "https://projectadmin.lfx.linuxfoundation.org/project/a0941000002wBymAAE/collaboration/committee/163b26f7-a49b-40a3-89bb-e0592296c003", + ] + for brokenurl in brokenurls: + with unittest.mock.patch.dict(os.environ, {"LFX_TAC_COMMITTEE_URL": brokenurl}, clear=True): + with tempfile.TemporaryDirectory() as tempdir: + tmpfilepath = os.path.join(tempdir, 'someFileInTmpDir.csv') + + with unittest.mock.patch('argparse.ArgumentParser.parse_args') as mock: + mock.return_value = argparse.Namespace(output=tmpfilepath) + main() + self.assertFalse(os.path.exists(tmpfilepath), f"File '{tmpfilepath}' exists.") + @responses.activate @unittest.mock.patch.dict(os.environ, {"LFX_TAC_COMMITTEE_URL": "https://projectadmin.lfx.linuxfoundation.org/project/a0941000002wBymAAE/collaboration/committees/163b26f7-a49b-40a3-89bb-e0592296c003"}, clear=True) def testMain(self):