diff --git a/lib/gitem/api.py b/lib/gitem/api.py index 007b5d4..1910291 100644 --- a/lib/gitem/api.py +++ b/lib/gitem/api.py @@ -169,9 +169,17 @@ def get_users_public_repositories(self, username, type=None, sort=None, directio https://developer.github.com/v3/repos/#list-user-repositories """ - assert type in ["all", "owner", "member", None] - assert sort in ["created", "updated", "pushed", "full_name", None] - assert direction in ["asc", "desc", None] + type_values = ["all", "owner", "member"] + if type not in type_values and type is not None: + raise ValueError("type must be one of {}".format(type_values)) + + sort_values = ["created", "updated", "pushed", "full_name"] + if sort not in sort_values and sort is not None: + raise ValueError("sort must be one of {}".format(sort_values)) + + direction_values = ["asc", "desc"] + if direction not in direction_values and direction is not None: + raise ValueError("direction must be one of {}".format(direction_values)) method = "GET" endpoint = "/users/{}/repos".format(username) @@ -218,7 +226,9 @@ def get_organizations_public_repositories(self, organization, type=None): https://developer.github.com/v3/repos/#list-organization-repositories """ - assert type in ["all", "public", "private", "forks", "sources", "member", None] + type_values = ["all", "public", "private", "forks", "sources", "member"] + if type not in type_values and type is not None: + raise ValueError("type must be one of {}".format(type_values)) method = "GET" endpoint = "/orgs/{}/repos".format(organization) @@ -265,7 +275,9 @@ def get_repository_contributors(self, owner, repository, anon=None): https://developer.github.com/v3/repos/#list-contributors """ - assert anon in [1, "true", None] + anon_values = [1, "true"] + if anon not in anon_values and type is not None: + raise ValueError("anon must be one of {}".format(anon_values)) method = "GET" endpoint = "/repos/{}/{}/contributors".format(owner, repository) diff --git a/tests/test_api.py b/tests/test_api.py index a5cfced..d167a66 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -202,6 +202,41 @@ def test_paged_ok(self): self.assertOk(status_code) self.assertEqual(result, expected) + def test_get_users_public_repositories_bad_type(self): + type = "" + ghapi = api.Api() + + with self.assertRaises(ValueError): + ghapi.get_users_public_repositories("UNUSED", type=type) + + def test_get_users_public_repositories_bad_sort(self): + sort = "" + ghapi = api.Api() + + with self.assertRaises(ValueError): + ghapi.get_users_public_repositories("UNUSED", sort=sort) + + def test_get_users_public_repositories_bad_direction(self): + direction = "" + ghapi = api.Api() + + with self.assertRaises(ValueError): + ghapi.get_users_public_repositories("UNUSED", direction=direction) + + def test_get_organizations_public_repositories_bad_type(self): + type = "" + ghapi = api.Api() + + with self.assertRaises(ValueError): + ghapi.get_organizations_public_repositories("UNUSED", type=type) + + def test_get_repository_contributors_bad_anon(self): + anon = "" + ghapi = api.Api() + + with self.assertRaises(ValueError): + ghapi.get_repository_contributors("UNUSED", "UNUSED", anon=anon) + if __name__ == "__main__": unittest.main()