Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: John Mertic <[email protected]>
  • Loading branch information
jmertic committed Nov 25, 2024
1 parent a416039 commit 0e4e0e6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lfx_tac_actions/updatetacagendaitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main():
project_data = json.loads(json_project_data)
except:
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']))
Expand Down
54 changes: 46 additions & 8 deletions test/test_updatetacagendaitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,70 @@
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:
mock.return_value = argparse.Namespace(output=tmpfilepath)
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:
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):
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__':
Expand Down
18 changes: 17 additions & 1 deletion test/test_updatetacmembers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@
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:
mock.return_value = argparse.Namespace(output=tmpfilepath)
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):
Expand Down

0 comments on commit 0e4e0e6

Please sign in to comment.