id
int64
0
458k
file_name
stringlengths
4
119
file_path
stringlengths
14
227
content
stringlengths
24
9.96M
size
int64
24
9.96M
language
stringclasses
1 value
extension
stringclasses
14 values
total_lines
int64
1
219k
avg_line_length
float64
2.52
4.63M
max_line_length
int64
5
9.91M
alphanum_fraction
float64
0
1
repo_name
stringlengths
7
101
repo_stars
int64
100
139k
repo_forks
int64
0
26.4k
repo_open_issues
int64
0
2.27k
repo_license
stringclasses
12 values
repo_extraction_date
stringclasses
433 values
12,500
GistComment.py
PyGithub_PyGithub/tests/GistComment.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class GistComment(Framework.TestCase): def setUp(self): super().setUp() self.comment = self.g.get_gist("2729810").get_comment(323629) def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") self.assertEqual( self.comment.created_at, datetime(2012, 5, 19, 7, 7, 57, tzinfo=timezone.utc), ) self.assertEqual(self.comment.id, 323629) self.assertEqual( self.comment.updated_at, datetime(2012, 5, 19, 7, 7, 57, tzinfo=timezone.utc), ) self.assertEqual(self.comment.url, "https://api.github.com/gists/2729810/comments/323629") self.assertEqual(self.comment.user.login, "jacquev6") self.assertEqual( repr(self.comment), 'GistComment(user=NamedUser(login="jacquev6"), id=323629)', ) def testEdit(self): self.comment.edit("Comment edited by PyGithub") self.assertEqual(self.comment.body, "Comment edited by PyGithub") self.assertEqual( self.comment.updated_at, datetime(2012, 5, 19, 7, 12, 32, tzinfo=timezone.utc), ) def testDelete(self): self.comment.delete()
3,987
Python
.py
65
56.415385
98
0.506513
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,501
Organization.py
PyGithub_PyGithub/tests/Organization.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> # # Copyright 2018 Anton Nguyen <afnguyen85@gmail.com> # # Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> # # Copyright 2018 Jasper van Wanrooy <jasper@vanwanrooy.net> # # Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # # Copyright 2018 Shubham Singh <41840111+singh811@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Tim Boring <tboring@hearst.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Brian Choy <byceee@gmail.com> # # Copyright 2019 Geoffroy Jabouley <gjabouley@invensense.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2019 ebrown <brownierin@users.noreply.github.com> # # Copyright 2020 Geoff Low <glow@mdsol.com> # # Copyright 2020 Glenn McDonald <testworksau@users.noreply.github.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2020 latacora-daniel <71085674+latacora-daniel@users.noreply.github.com># # Copyright 2020 ton-katsu <sakamoto.yoshihisa@gmail.com> # # Copyright 2021 Marina Peresypkina <mi9onev@gmail.com> # # Copyright 2021 Tanner <51724788+lightningboltemoji@users.noreply.github.com> # # Copyright 2022 KimSia Sim <245021+simkimsia@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Felipe Peter <mr-peipei@web.de> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Jonathan Greg <31892308+jmgreg31@users.noreply.github.com> # # Copyright 2023 Mauricio Alejandro Martínez Pacheco <mauricio.martinez@premise.com># # Copyright 2023 Mauricio Alejandro Martínez Pacheco <n_othing@hotmail.com> # # Copyright 2024 Andrii Kezikov <cheshirez@gmail.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Jacky Lam <jacky.lam@r2studiohk.com> # # Copyright 2024 Mohamed Mostafa <112487260+mohy01@users.noreply.github.com> # # Copyright 2024 Oskar Jansson <56458534+janssonoskar@users.noreply.github.com># # Copyright 2024 Thomas Cooper <coopernetes@proton.me> # # Copyright 2024 Thomas Crowley <15927917+thomascrowley@users.noreply.github.com># # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from unittest import mock import github from github.OrganizationCustomProperty import CustomProperty from . import Framework class Organization(Framework.TestCase): def setUp(self): super().setUp() self.org = self.g.get_organization("BeaverSoftware") def testAttributes(self): self.assertEqual(self.org.avatar_url, "https://avatars1.githubusercontent.com/u/1?v=4") self.assertEqual(self.org.billing_email, "foo@example.com") self.assertEqual(self.org.blog, "http://www.example.com") self.assertEqual(self.org.collaborators, 9) self.assertEqual(self.org.company, None) self.assertEqual( self.org.created_at, datetime(2014, 1, 9, 16, 56, 17, tzinfo=timezone.utc), ) self.assertEqual(self.org.default_repository_permission, "none") self.assertEqual(self.org.description, "BeaverSoftware writes software.") self.assertEqual(self.org.disk_usage, 2) self.assertEqual(self.org.email, "") self.assertEqual(self.org.followers, 0) self.assertEqual(self.org.following, 0) self.assertEqual(self.org.gravatar_id, None) self.assertTrue(self.org.has_organization_projects) self.assertTrue(self.org.has_repository_projects) self.assertEqual(self.org.hooks_url, "https://api.github.com/orgs/BeaverSoftware/hooks") self.assertEqual(self.org.html_url, "https://github.com/BeaverSoftware") self.assertEqual(self.org.id, 1) self.assertEqual(self.org.issues_url, "https://api.github.com/orgs/BeaverSoftware/issues") self.assertEqual(self.org.location, "Paris, France") self.assertEqual(self.org.login, "BeaverSoftware") self.assertFalse(self.org.members_can_create_repositories) self.assertEqual(self.org.name, "BeaverSoftware") self.assertEqual(self.org.owned_private_repos, 0) self.assertEqual(self.org.plan.name, "free") self.assertEqual(self.org.plan.private_repos, 3) self.assertEqual(self.org.plan.space, 1) self.assertEqual(self.org.plan.filled_seats, 3) self.assertEqual(self.org.plan.seats, 0) self.assertEqual(self.org.private_gists, 0) self.assertEqual(self.org.public_gists, 0) self.assertEqual(self.org.public_repos, 27) self.assertEqual(self.org.total_private_repos, 7) self.assertEqual(self.org.two_factor_requirement_enabled, None) self.assertEqual(self.org.type, "Organization") self.assertEqual(self.org.url, "https://api.github.com/orgs/BeaverSoftware") self.assertEqual(repr(self.org), 'Organization(login="BeaverSoftware")') def testAddMembersDefaultRole(self): lyloa = self.g.get_user("lyloa") self.assertFalse(self.org.has_in_members(lyloa)) self.org.add_to_members(lyloa, role="member") # 'Pending' members won't be in /orgs/:org/members/:user self.assertFalse(self.org.has_in_members(lyloa)) self.org.remove_from_membership(lyloa) self.assertFalse(self.org.has_in_members(lyloa)) def testAddMembersAdminRole(self): lyloa = self.g.get_user("lyloa") self.assertFalse(self.org.has_in_members(lyloa)) self.org.add_to_members(lyloa, role="admin") # 'Pending' members won't be in /orgs/:org/members/:user self.assertFalse(self.org.has_in_members(lyloa)) self.org.remove_from_membership(lyloa) self.assertFalse(self.org.has_in_members(lyloa)) def testEditWithoutArguments(self): self.org.edit() def testEditWithAllArguments(self): self.org.edit( "BeaverSoftware2@vincent-jacques.net", "http://vincent-jacques.net", "Company edited by PyGithub", "Description edited by PyGithub", "BeaverSoftware2@vincent-jacques.net", "Location edited by PyGithub", "Name edited by PyGithub", ) self.assertEqual(self.org.billing_email, "BeaverSoftware2@vincent-jacques.net") self.assertEqual(self.org.blog, "http://vincent-jacques.net") self.assertEqual(self.org.company, "Company edited by PyGithub") self.assertEqual(self.org.description, "Description edited by PyGithub") self.assertEqual(self.org.email, "BeaverSoftware2@vincent-jacques.net") self.assertEqual(self.org.location, "Location edited by PyGithub") self.assertEqual(self.org.name, "Name edited by PyGithub") def testEditHookWithMinimalParameters(self): hook = self.org.create_hook("web", {"url": "http://foobar.com"}) hook = self.org.edit_hook(hook.id, "mobile", {"url": "http://barfoo.com"}) self.assertEqual(hook.name, "mobile") def testEditHookWithAllParameters(self): hook = self.org.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False) hook = self.org.edit_hook(hook.id, "mobile", {"url": "http://barfoo.com"}, ["spoon"], True) self.assertEqual(hook.name, "mobile") self.assertEqual(hook.events, ["spoon"]) self.assertEqual(hook.active, True) def testCreateTeam(self): team = self.org.create_team("Team created by PyGithub") self.assertEqual(team.id, 189850) def testCreateTeamWithAllArguments(self): repo = self.org.get_repo("FatherBeaver") parent_team = self.org.get_team(141496) maintainer = self.g.get_user("jacquev6") team = self.org.create_team( "Team also created by PyGithub", [repo], "push", "secret", "Description also created by PyGithub", parent_team.id, [maintainer.id], "notifications_disabled", ) self.assertEqual(team.id, 189852) self.assertEqual(team.description, "Description also created by PyGithub") self.assertEqual(team.parent, parent_team) self.assertEqual(team.notification_setting, "notifications_disabled") def testDeleteHook(self): hook = self.org.create_hook("web", {"url": "http://foobar.com"}) self.org.delete_hook(hook.id) def testPublicMembers(self): lyloa = self.g.get_user("Lyloa") self.assertFalse(self.org.has_in_public_members(lyloa)) self.org.add_to_public_members(lyloa) self.assertTrue(self.org.has_in_public_members(lyloa)) self.org.remove_from_public_members(lyloa) self.assertFalse(self.org.has_in_public_members(lyloa)) def testGetPublicMembers(self): self.assertListKeyEqual(self.org.get_public_members(), lambda u: u.login, ["jacquev6"]) def testGetHook(self): hook = self.org.get_hook(257993) self.assertEqual(hook.name, "web") def testGetHooks(self): self.assertListKeyEqual(self.org.get_hooks(), lambda h: h.id, [257993]) def testGetHookDelivery(self): delivery = self.org.get_hook_delivery(257993, 12345) self.assertEqual(delivery.id, 12345) self.assertEqual(delivery.guid, "abcde-12345") self.assertEqual( delivery.delivered_at, datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(delivery.redelivery, False) self.assertEqual(delivery.duration, 0.27) self.assertEqual(delivery.status, "OK") self.assertEqual(delivery.status_code, 200) self.assertEqual(delivery.event, "issues") self.assertEqual(delivery.action, "opened") self.assertEqual(delivery.installation_id, 123) self.assertEqual(delivery.repository_id, 456) self.assertEqual(delivery.url, "https://www.example-webhook.com") self.assertIsInstance(delivery.request, github.HookDelivery.HookDeliveryRequest) self.assertEqual(delivery.request.headers, {"content-type": "application/json"}) self.assertEqual(delivery.request.payload, {"action": "opened"}) self.assertIsInstance(delivery.response, github.HookDelivery.HookDeliveryResponse) self.assertEqual(delivery.response.headers, {"content-type": "text/html;charset=utf-8"}) self.assertEqual(delivery.response.payload, "ok") def testGetHookDeliveries(self): deliveries = list(self.org.get_hook_deliveries(257993)) self.assertEqual(len(deliveries), 1) self.assertEqual(deliveries[0].id, 12345) self.assertEqual(deliveries[0].guid, "abcde-12345") self.assertEqual( deliveries[0].delivered_at, datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(deliveries[0].redelivery, False) self.assertEqual(deliveries[0].duration, 0.27) self.assertEqual(deliveries[0].status, "OK") self.assertEqual(deliveries[0].status_code, 200) self.assertEqual(deliveries[0].event, "issues") self.assertEqual(deliveries[0].action, "opened") self.assertEqual(deliveries[0].installation_id, 123) self.assertEqual(deliveries[0].repository_id, 456) self.assertEqual(deliveries[0].url, "https://www.example-webhook.com") def testGetIssues(self): self.assertListKeyEqual(self.org.get_issues(), lambda i: i.id, []) def testGetIssuesWithAllArguments(self): requestedByUser = self.g.get_user().get_repo("PyGithub").get_label("Requested by user") issues = self.org.get_issues( "assigned", "closed", [requestedByUser], "comments", "asc", datetime(2012, 5, 28, 23, 0, 0, tzinfo=timezone.utc), ) self.assertListKeyEqual(issues, lambda i: i.id, []) def testGetMembers(self): self.assertListKeyEqual(self.org.get_members(), lambda u: u.login, ["cjuniet", "jacquev6", "Lyloa"]) def testGetOutsideCollaborators(self): self.assertListKeyEqual(self.org.get_outside_collaborators(), lambda u: u.login, ["octocat"]) def testOutsideCollaborators(self): octocat = self.g.get_user("octocat") self.org.convert_to_outside_collaborator(octocat) self.assertListKeyEqual(self.org.get_outside_collaborators(), lambda u: u.login, ["octocat"]) self.org.remove_outside_collaborator(octocat) self.assertEqual(list(self.org.get_outside_collaborators()), []) def testMembers(self): lyloa = self.g.get_user("Lyloa") self.assertTrue(self.org.has_in_members(lyloa)) self.org.remove_from_members(lyloa) self.assertFalse(self.org.has_in_members(lyloa)) def testGetRepos(self): repos = self.org.get_repos() self.assertListKeyEqual(repos, lambda r: r.name, ["FatherBeaver", "TestPyGithub"]) self.assertListKeyEqual(repos, lambda r: r.has_pages, [True, False]) self.assertListKeyEqual(repos, lambda r: r.has_wiki, [True, True]) def testGetReposSorted(self): repos = self.org.get_repos(sort="updated", direction="desc") self.assertListKeyEqual( repos, lambda r: r.name, ["TestPyGithub", "FatherBeaver"], ) self.assertListKeyEqual( repos, lambda r: r.has_pages, [False, True], ) def testGetReposWithType(self): repos = self.org.get_repos("public") self.assertListKeyEqual(repos, lambda r: r.name, ["FatherBeaver", "PyGithub"]) self.assertListKeyEqual(repos, lambda r: r.has_pages, [True, True]) def testGetEvents(self): self.assertListKeyEqual( self.org.get_events(), lambda e: e.type, [ "CreateEvent", "CreateEvent", "PushEvent", "PushEvent", "DeleteEvent", "DeleteEvent", "PushEvent", "PushEvent", "DeleteEvent", "DeleteEvent", "PushEvent", "PushEvent", "PushEvent", "CreateEvent", "CreateEvent", "CreateEvent", "CreateEvent", "CreateEvent", "PushEvent", "PushEvent", "PushEvent", "PushEvent", "PushEvent", "PushEvent", "ForkEvent", "CreateEvent", ], ) def testGetTeams(self): self.assertListKeyEqual(self.org.get_teams(), lambda t: t.name, ["Members", "Owners"]) def testGetTeamBySlug(self): team = self.org.get_team_by_slug("Members") self.assertEqual(team.id, 141496) def testCreateHookWithMinimalParameters(self): hook = self.org.create_hook("web", {"url": "http://foobar.com"}) self.assertEqual(hook.id, 257967) def testCreateHookWithAllParameters(self): hook = self.org.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False) self.assertTrue(hook.active) self.assertEqual(hook.id, 257993) def testCreateRepoWithMinimalArguments(self): repo = self.org.create_repo(name="TestPyGithub") self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub") self.assertTrue(repo.has_wiki) self.assertTrue(repo.has_pages) def testCreateRepoWithAllArguments(self): team = self.org.get_team(141496) repo = self.org.create_repo( name="TestPyGithub2", description="Repo created by PyGithub", homepage="http://foobar.com", private=False, visibility="public", has_issues=False, has_projects=False, has_wiki=False, has_downloads=False, team_id=team.id, allow_update_branch=True, allow_squash_merge=False, allow_merge_commit=False, allow_rebase_merge=True, delete_branch_on_merge=False, ) self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub2") self.assertTrue(repo.allow_update_branch) self.assertFalse(repo.has_wiki) self.assertFalse(repo.has_pages) def testCreateRepositoryWithAutoInit(self): repo = self.org.create_repo(name="TestPyGithub", auto_init=True, gitignore_template="Python") self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub") self.assertTrue(repo.has_pages) self.assertTrue(repo.has_wiki) def testCreateFork(self): pygithub = self.g.get_user("jacquev6").get_repo("PyGithub") repo = self.org.create_fork(pygithub) self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/PyGithub") self.assertFalse(repo.has_wiki) self.assertFalse(repo.has_pages) def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo) self.assertEqual( repo.url, "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new", ) self.assertFalse(repo.is_template) def testCreateRepoFromTemplateWithAllArguments(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") description = "My repo from template" private = True repo = self.org.create_repo_from_template( "hello-world-docker-action-new", template_repo, description=description, include_all_branches=True, private=private, ) self.assertEqual(repo.description, description) self.assertTrue(repo.private) @mock.patch("github.PublicKey.encrypt") def testCreateSecretSelected(self, encrypt): repos = [self.org.get_repo("TestPyGithub"), self.org.get_repo("FatherBeaver")] # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = self.org.create_secret( secret_name="secret-name", unencrypted_value="secret-value", visibility="selected", secret_type="actions", selected_repositories=repos, ) self.assertIsNotNone(secret) self.assertEqual(secret.visibility, "selected") self.assertEqual(list(secret.selected_repositories), repos) def testGetSecret(self): repos = [self.org.get_repo("TestPyGithub"), self.org.get_repo("FatherBeaver")] secret = self.org.get_secret("secret-name") self.assertEqual(secret.name, "secret-name") self.assertEqual(secret.created_at, datetime(2019, 8, 10, 14, 59, 22, tzinfo=timezone.utc)) self.assertEqual(secret.updated_at, datetime(2020, 1, 10, 14, 59, 22, tzinfo=timezone.utc)) self.assertEqual(secret.visibility, "selected") self.assertEqual(list(secret.selected_repositories), repos) self.assertEqual(secret.url, "https://api.github.com/orgs/BeaverSoftware/actions/secrets/secret-name") def testGetSecrets(self): secrets = self.org.get_secrets() self.assertEqual(len(list(secrets)), 1) def testGetDependabotSecrets(self): secrets = self.org.get_secrets(secret_type="dependabot") self.assertEqual(len(list(secrets)), 1) def testGetDependabotAlerts(self): alerts = self.org.get_dependabot_alerts() alert_list = list(alerts) self.assertEqual(len(list(alerts)), 8) self.assertEqual(alert_list[0].number, 1) self.assertEqual(alert_list[0].repository.full_name, "BeaverSoftware/PyGithub") def testGetDependabotAlertsWithAllArguments(self): alerts = self.org.get_dependabot_alerts( "open", "medium", "pip", "jinja2", "runtime", "updated", "asc", ) alert_list = list(alerts) self.assertEqual(len(list(alerts)), 1) self.assertEqual(alert_list[0].number, 1) self.assertEqual(alert_list[0].state, "open") self.assertEqual(alert_list[0].security_advisory.severity, "medium") self.assertEqual(alert_list[0].dependency.package.ecosystem, "pip") self.assertEqual(alert_list[0].dependency.package.name, "jinja2") self.assertEqual(alert_list[0].dependency.scope, "runtime") self.assertEqual(alert_list[0].repository.full_name, "BeaverSoftware/PyGithub") def testGetSecretsFail(self): with self.assertRaises(AssertionError) as raisedexp: self.org.get_secrets(secret_type="secret") self.assertEqual("secret_type should be actions or dependabot", str(raisedexp.exception)) def testInviteUserWithNeither(self): with self.assertRaises(AssertionError) as raisedexp: self.org.invite_user() self.assertEqual("specify only one of email or user", str(raisedexp.exception)) def testInviteUserWithBoth(self): jacquev6 = self.g.get_user("jacquev6") with self.assertRaises(AssertionError) as raisedexp: self.org.invite_user(email="foo", user=jacquev6) self.assertEqual("specify only one of email or user", str(raisedexp.exception)) def testInviteUserByName(self): jacquev6 = self.g.get_user("jacquev6") self.org.invite_user(user=jacquev6) def testInviteUserByEmail(self): self.org.invite_user(email="foo@example.com") def testInviteUserWithRoleAndTeam(self): team = self.org.create_team("Team created by PyGithub") self.org.invite_user(email="foo@example.com", role="billing_manager", teams=[team]) def testInviteUserAsNonOwner(self): with self.assertRaises(github.GithubException) as raisedexp: self.org.invite_user(email="bar@example.com") self.assertEqual(raisedexp.exception.status, 403) self.assertEqual( raisedexp.exception.data, { "documentation_url": "https://developer.github.com/v3/orgs/members/#create-organization-invitation", "message": "You must be an admin to create an invitation to an organization.", }, ) def testCreateMigration(self): self.org = self.g.get_organization("sample-test-organisation") self.assertTrue(isinstance(self.org.create_migration(["sample-repo"]), github.Migration.Migration)) def testGetMigrations(self): self.org = self.g.get_organization("sample-test-organisation") self.assertEqual(self.org.get_migrations().totalCount, 2) def testGetInstallations(self): installations = self.org.get_installations() self.assertEqual(installations[0].id, 123456) self.assertEqual(installations[0].app_id, 10101) self.assertEqual(installations[0].target_id, 3344556) self.assertEqual(installations[0].target_type, "User") self.assertEqual(installations.totalCount, 1) def testCreateVariable(self): variable = self.org.create_variable("variable-name", "variable-value", "all") self.assertIsNotNone(variable) def testCreateVariableSelected(self): repos = [self.org.get_repo("TestPyGithub"), self.org.get_repo("FatherBeaver")] variable = self.org.create_variable("variable-name", "variable-value", "selected", repos) self.assertIsNotNone(variable) self.assertEqual(list(variable.selected_repositories), repos) def testGetVariable(self): repos = [self.org.get_repo("TestPyGithub"), self.org.get_repo("FatherBeaver")] variable = self.org.get_variable("variable-name") self.assertEqual(variable.name, "variable-name") self.assertEqual(variable.created_at, datetime(2019, 8, 10, 14, 59, 22, tzinfo=timezone.utc)) self.assertEqual(variable.updated_at, datetime(2020, 1, 10, 14, 59, 22, tzinfo=timezone.utc)) self.assertEqual(variable.visibility, "selected") self.assertEqual(list(variable.selected_repositories), repos) self.assertEqual(variable.url, "https://api.github.com/orgs/BeaverSoftware/actions/variables/variable-name") def testGetVariables(self): variables = self.org.get_variables() self.assertEqual(len(list(variables)), 1) @mock.patch("github.PublicKey.encrypt") def testCreateActionsSecret(self, encrypt): org = self.g.get_organization("demoorg") # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = org.create_secret("secret_name", "secret-value", visibility="all") self.assertIsNotNone(secret) @mock.patch("github.PublicKey.encrypt") def testCreateDependabotSecret(self, encrypt): org = self.g.get_organization("demoorg") # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = org.create_secret("secret_name", "secret-value", secret_type="dependabot", visibility="all") self.assertIsNotNone(secret) def testOrgGetSecretAssertion(self): org = self.g.get_organization("demoorg") with self.assertRaises(AssertionError) as exc: org.get_secret(secret_name="splat", secret_type="supersecret") self.assertEqual(str(exc.exception), "secret_type should be actions or dependabot") @mock.patch("github.PublicKey.encrypt") def testCreateDependabotSecretSelected(self, encrypt): org = self.g.get_organization("demoorg") repos = [org.get_repo("demo-repo-1"), org.get_repo("demo-repo-2")] # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = org.create_secret( secret_name="SECRET_DEP_NAME", unencrypted_value="secret-value", visibility="selected", secret_type="dependabot", selected_repositories=repos, ) self.assertIsNotNone(secret) self.assertEqual(secret.visibility, "selected") self.assertEqual(list(secret.selected_repositories), repos) @mock.patch("github.PublicKey.encrypt") def testOrgSecretEdit(self, encrypt): org = self.g.get_organization("demoorg") repos = [org.get_repo("demo-repo-1"), org.get_repo("demo-repo-2")] # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = org.create_secret( secret_name="secret_act_name", unencrypted_value="secret-value", visibility="selected", secret_type="actions", selected_repositories=repos, ) with self.assertRaises(AssertionError) as exc: secret.edit(value="newvalue", secret_type="supersecret") self.assertEqual(str(exc.exception), "secret_type should be actions or dependabot") def testCreateCustomProperties(self): properties = [ CustomProperty( property_name="property_1", value_type="string", required=False, description="description", values_editable_by="org_actors", ), CustomProperty( property_name="property_2", value_type="single_select", required=True, default_value="bar", description="Lorem ipsum", allowed_values=["foo", "bar"], values_editable_by="org_and_repo_actors", ), ] properties = self.org.create_custom_properties(properties) properties_map = {p.property_name: p for p in properties} property_1 = properties_map["property_1"] self.assertEqual(property_1.value_type, "string") property_2 = properties_map["property_2"] self.assertEqual(property_2.description, "Lorem ipsum") def testCreateCustomProperty(self): custom_property = CustomProperty( property_name="property_1", value_type="string", required=True, default_value="foo", description="description", ) created_property = self.org.create_custom_property(custom_property) self.assertEqual(created_property.property_name, "property_1") self.assertEqual(created_property.value_type, "string") self.assertEqual(created_property.required, True) self.assertEqual(created_property.default_value, "foo") self.assertEqual(created_property.description, "description") self.assertEqual(created_property.values_editable_by, "org_actors") def testGetCustomProperties(self): properties = self.org.get_custom_properties() properties_map = {p.property_name: p for p in properties} self.assertIn("property_1", properties_map) self.assertIn("property_2", properties_map) def testGetCustomProperty(self): custom_property = self.org.get_custom_property("property_1") self.assertEqual(custom_property.property_name, "property_1") self.assertEqual(custom_property.value_type, "string") self.assertEqual(custom_property.required, True) self.assertEqual(custom_property.default_value, "foo") self.assertEqual(custom_property.description, "description") self.assertEqual(custom_property.values_editable_by, "org_actors") def testCreateCustomPropertyValues(self): self.org.create_custom_property_values(["TestPyGithub"], {"property_1": "bar"}) self.testListCustomPropertyValues() def testListCustomPropertyValues(self): repos = list(self.org.list_custom_property_values("repo:BeaverSoftware/TestPyGithub")) repos_map = {r.repository_name: r for r in repos} self.assertIn("TestPyGithub", repos_map) self.assertIn("property_1", repos_map["TestPyGithub"].properties) self.assertEqual(repos_map["TestPyGithub"].properties["property_1"], "bar") def testRemoveCustomProperty(self): self.org.remove_custom_property("property_1") with self.assertRaises(github.UnknownObjectException): self.org.get_custom_property("property_1")
34,039
Python
.py
628
45.275478
116
0.643344
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,502
Requester.py
PyGithub_PyGithub/tests/Requester.py
############################ Copyrights and license ############################ # # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Hemslo Wang <hemslo.wang@gmail.com> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Trim21 <trim21.me@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import contextlib from datetime import datetime, timedelta, timezone from unittest import mock import github from . import Framework from .GithubIntegration import APP_ID, PRIVATE_KEY REPO_NAME = "PyGithub/PyGithub" class Requester(Framework.TestCase): logger = None def setUp(self): super().setUp() self.logger = mock.MagicMock() github.Requester.Requester.injectLogger(self.logger) def tearDown(self): github.Requester.Requester.resetLogger() super().tearDown() def testRecreation(self): class TestAuth(github.Auth.AppAuth): pass # create a Requester with non-default arguments auth = TestAuth(123, "key") requester = github.Requester.Requester( auth=auth, base_url="https://base.url", timeout=1, user_agent="user agent", per_page=123, verify=False, retry=3, pool_size=5, seconds_between_requests=1.2, seconds_between_writes=3.4, ) kwargs = requester.kwargs # assert kwargs consists of ALL constructor arguments self.assertEqual(kwargs.keys(), github.Requester.Requester.__init__.__annotations__.keys()) self.assertEqual( kwargs, dict( auth=auth, base_url="https://base.url", timeout=1, user_agent="user agent", per_page=123, verify=False, retry=3, pool_size=5, seconds_between_requests=1.2, seconds_between_writes=3.4, ), ) # create a copy Requester, assert identity via kwargs copy = github.Requester.Requester(**kwargs) self.assertEqual(copy.kwargs, kwargs) # create Github instance, assert identity requester gh = github.Github(**kwargs) self.assertEqual(gh._Github__requester.kwargs, kwargs) # create GithubIntegration instance, assert identity requester gi = github.GithubIntegration(**kwargs) self.assertEqual(gi._GithubIntegration__requester.kwargs, kwargs) def testWithAuth(self): class TestAuth(github.Auth.AppAuth): pass # create a Requester with non-default arguments auth = TestAuth(123, "key") requester = github.Requester.Requester( auth=auth, base_url="https://base.url", timeout=1, user_agent="user agent", per_page=123, verify=False, retry=3, pool_size=5, seconds_between_requests=1.2, seconds_between_writes=3.4, ) # create a copy with different auth auth2 = TestAuth(456, "key2") copy = requester.withAuth(auth2) # assert kwargs of copy self.assertEqual( copy.kwargs, dict( auth=auth2, base_url="https://base.url", timeout=1, user_agent="user agent", per_page=123, verify=False, retry=3, pool_size=5, seconds_between_requests=1.2, seconds_between_writes=3.4, ), ) def testCloseGithub(self): mocked_connection = mock.MagicMock() mocked_custom_connection = mock.MagicMock() with github.Github() as gh: requester = gh._Github__requester requester._Requester__connection = mocked_connection requester._Requester__custom_connections.append(mocked_custom_connection) mocked_connection.close.assert_called_once_with() mocked_custom_connection.close.assert_called_once_with() self.assertIsNone(requester._Requester__connection) def testCloseGithubIntegration(self): mocked_connection = mock.MagicMock() mocked_custom_connection = mock.MagicMock() auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) with github.GithubIntegration(auth=auth) as gi: requester = gi._GithubIntegration__requester requester._Requester__connection = mocked_connection requester._Requester__custom_connections.append(mocked_custom_connection) mocked_connection.close.assert_called_once_with() mocked_custom_connection.close.assert_called_once_with() self.assertIsNone(requester._Requester__connection) def testLoggingRedirection(self): self.assertEqual(self.g.get_repo("EnricoMi/test").name, "test-renamed") self.logger.info.assert_called_once_with( "Following Github server redirection from /repos/EnricoMi/test to /repositories/638123443" ) def testBaseUrlSchemeRedirection(self): gh = github.Github(base_url="http://api.github.com") with self.assertRaises(RuntimeError) as exc: gh.get_repo("PyGithub/PyGithub") self.assertEqual( exc.exception.args, ( "Github server redirected from http protocol to https, please correct your " "Github server URL via base_url: Github(base_url=...)", ), ) def testBaseUrlHostRedirection(self): gh = github.Github(base_url="https://www.github.com") with self.assertRaises(RuntimeError) as exc: gh.get_repo("PyGithub/PyGithub") self.assertEqual( exc.exception.args, ( "Github server redirected from host www.github.com to github.com, " "please correct your Github server URL via base_url: Github(base_url=...)", ), ) def testBaseUrlPortRedirection(self): # replay data forged gh = github.Github(base_url="https://api.github.com") with self.assertRaises(RuntimeError) as exc: gh.get_repo("PyGithub/PyGithub") self.assertEqual( exc.exception.args, ( "Requested https://api.github.com/repos/PyGithub/PyGithub but server " "redirected to https://api.github.com:443/repos/PyGithub/PyGithub, " "you may need to correct your Github server URL " "via base_url: Github(base_url=...)", ), ) def testBaseUrlPrefixRedirection(self): # replay data forged gh = github.Github(base_url="https://api.github.com/api/v3") self.assertEqual(gh.get_repo("PyGithub/PyGithub").name, "PyGithub") self.logger.info.assert_called_once_with( "Following Github server redirection from /api/v3/repos/PyGithub/PyGithub to /repos/PyGithub/PyGithub" ) PrimaryRateLimitErrors = [ "API rate limit exceeded for x.x.x.x. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", ] SecondaryRateLimitErrors = [ "You have triggered an abuse detection mechanism. Please wait a few minutes before you try again.", "You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later." "You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later.", "You have exceeded a secondary rate limit. Please wait a few minutes before you try again.", "Something else here. Please wait a few minutes before you try again.", ] OtherErrors = ["User does not exist or is not a member of the organization"] def testIsRateLimitError(self): for message in self.PrimaryRateLimitErrors + self.SecondaryRateLimitErrors: self.assertTrue(github.Requester.Requester.isRateLimitError(message), message) for message in self.OtherErrors: self.assertFalse(github.Requester.Requester.isRateLimitError(message), message) def testIsPrimaryRateLimitError(self): for message in self.PrimaryRateLimitErrors: self.assertTrue(github.Requester.Requester.isPrimaryRateLimitError(message), message) for message in self.OtherErrors + self.SecondaryRateLimitErrors: self.assertFalse(github.Requester.Requester.isPrimaryRateLimitError(message), message) def testIsSecondaryRateLimitError(self): for message in self.SecondaryRateLimitErrors: self.assertTrue(github.Requester.Requester.isSecondaryRateLimitError(message), message) for message in self.OtherErrors + self.PrimaryRateLimitErrors: self.assertFalse(github.Requester.Requester.isSecondaryRateLimitError(message), message) def assertException(self, exception, exception_type, status, data, headers, string): self.assertIsInstance(exception, exception_type) self.assertEqual(exception.status, status) if data is None: self.assertIsNone(exception.data) else: self.assertEqual(exception.data, data) self.assertEqual(exception.headers, headers) self.assertEqual(str(exception), string) def testShouldCreateBadCredentialsException(self): exc = self.g._Github__requester.createException(401, {"header": "value"}, {"message": "Bad credentials"}) self.assertException( exc, github.BadCredentialsException, 401, {"message": "Bad credentials"}, {"header": "value"}, '401 {"message": "Bad credentials"}', ) def testShouldCreateTwoFactorException(self): exc = self.g._Github__requester.createException( 401, {"x-github-otp": "required; app"}, { "message": "Must specify two-factor authentication OTP code.", "documentation_url": "https://developer.github.com/v3/auth#working-with-two-factor-authentication", }, ) self.assertException( exc, github.TwoFactorException, 401, { "message": "Must specify two-factor authentication OTP code.", "documentation_url": "https://developer.github.com/v3/auth#working-with-two-factor-authentication", }, {"x-github-otp": "required; app"}, '401 {"message": "Must specify two-factor authentication OTP code.", "documentation_url": "https://developer.github.com/v3/auth#working-with-two-factor-authentication"}', ) def testShouldCreateBadUserAgentException(self): exc = self.g._Github__requester.createException( 403, {"header": "value"}, {"message": "Missing or invalid User Agent string"}, ) self.assertException( exc, github.BadUserAgentException, 403, {"message": "Missing or invalid User Agent string"}, {"header": "value"}, '403 {"message": "Missing or invalid User Agent string"}', ) def testShouldCreateRateLimitExceededException(self): for message in self.PrimaryRateLimitErrors + self.SecondaryRateLimitErrors: with self.subTest(message=message): exc = self.g._Github__requester.createException(403, {"header": "value"}, {"message": message}) self.assertException( exc, github.RateLimitExceededException, 403, {"message": message}, {"header": "value"}, f'403 {{"message": "{message}"}}', ) def testShouldCreateUnknownObjectException(self): exc = self.g._Github__requester.createException(404, {"header": "value"}, {"message": "Not Found"}) self.assertException( exc, github.UnknownObjectException, 404, {"message": "Not Found"}, {"header": "value"}, '404 {"message": "Not Found"}', ) def testShouldCreateGithubException(self): for status in range(400, 600): with self.subTest(status=status): exc = self.g._Github__requester.createException( status, {"header": "value"}, {"message": "Something unknown"} ) self.assertException( exc, github.GithubException, status, {"message": "Something unknown"}, {"header": "value"}, f'{status} {{"message": "Something unknown"}}', ) def testShouldCreateExceptionWithoutMessage(self): for status in range(400, 600): with self.subTest(status=status): exc = self.g._Github__requester.createException(status, {}, {}) self.assertException(exc, github.GithubException, status, {}, {}, f"{status} {{}}") def testShouldCreateExceptionWithoutOutput(self): for status in range(400, 600): with self.subTest(status=status): exc = self.g._Github__requester.createException(status, {}, None) self.assertException(exc, github.GithubException, status, None, {}, f"{status}") class RequesterThrottleTestCase(Framework.TestCase): per_page = 10 mock_time = [datetime.now(timezone.utc)] def sleep(self, seconds): self.mock_time[0] = self.mock_time[0] + timedelta(seconds=seconds) def now(self, tz=None): return self.mock_time[0] @contextlib.contextmanager def mock_sleep(self): with mock.patch("github.Requester.time.sleep", side_effect=self.sleep) as sleep_mock, mock.patch( "github.Requester.datetime" ) as datetime_mock: datetime_mock.now = self.now yield sleep_mock class RequesterUnThrottled(RequesterThrottleTestCase): def testShouldNotDeferRequests(self): with self.mock_sleep() as sleep_mock: # same test setup as in RequesterThrottled.testShouldDeferRequests repository = self.g.get_repo(REPO_NAME) releases = list(repository.get_releases()) self.assertEqual(len(releases), 30) sleep_mock.assert_not_called() class RequesterThrottled(RequesterThrottleTestCase): seconds_between_requests = 1.0 seconds_between_writes = 3.0 def testShouldDeferRequests(self): with self.mock_sleep() as sleep_mock: # same test setup as in RequesterUnThrottled.testShouldNotDeferRequests repository = self.g.get_repo(REPO_NAME) releases = [release for release in repository.get_releases()] self.assertEqual(len(releases), 30) self.assertEqual(sleep_mock.call_args_list, [mock.call(1), mock.call(1), mock.call(1)]) def testShouldDeferWrites(self): with self.mock_sleep() as sleep_mock: # same test setup as in AuthenticatedUser.testEmail user = self.g.get_user() emails = user.get_emails() self.assertEqual( [item.email for item in emails], ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"], ) self.assertTrue(emails[0].primary) self.assertTrue(emails[0].verified) self.assertEqual(emails[0].visibility, "private") user.add_to_emails("1@foobar.com", "2@foobar.com") self.assertEqual( [item.email for item in user.get_emails()], [ "vincent@vincent-jacques.net", "1@foobar.com", "2@foobar.com", "github.com@vincent-jacques.net", ], ) user.remove_from_emails("1@foobar.com", "2@foobar.com") self.assertEqual( [item.email for item in user.get_emails()], ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"], ) self.assertEqual( sleep_mock.call_args_list, [ # g.get_user() does not call into GitHub API # user.get_emails() is the first request so no waiting needed # user.add_to_emails is a write request, this is the first write request mock.call(1), # user.get_emails() is a read request mock.call(1), # user.remove_from_emails is a write request, it has to be 3 seconds after the last write mock.call(2), # user.get_emails() is a read request mock.call(1), ], )
18,765
Python
.py
388
37.350515
182
0.587555
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,503
IssueComment.py
PyGithub_PyGithub/tests/IssueComment.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Nicolas Agustín Torres <nicolastrres@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Huan-Cheng Chang <changhc84@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Malik Shahzad Muzaffar <shahzad.malik.muzaffar@cern.ch> # # Copyright 2024 Arash Kadkhodaei <arash77.kad@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class IssueComment(Framework.TestCase): def setUp(self): super().setUp() self.comment = self.g.get_user().get_repo("PyGithub").get_issue(28).get_comment(5808311) def testAttributes(self): self.assertEqual(self.comment.node_id, "IC_kwDOGpsAJ86Gecc_") self.assertEqual(self.comment.body, "Comment created by PyGithub") self.assertEqual( self.comment.created_at, datetime(2012, 5, 20, 11, 46, 42, tzinfo=timezone.utc), ) self.assertEqual(self.comment.id, 5808311) self.assertEqual( self.comment.updated_at, datetime(2012, 5, 20, 11, 46, 42, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/comments/5808311", ) self.assertEqual(self.comment.user.login, "jacquev6") self.assertEqual( self.comment.html_url, "https://github.com/jacquev6/PyGithub/issues/28#issuecomment-5808311", ) self.assertEqual( repr(self.comment), 'IssueComment(user=NamedUser(login="jacquev6"), id=5808311)', ) self.assertEqual( self.comment.reactions, { "+1": 1, "-1": 0, "confused": 0, "eyes": 0, "heart": 0, "hooray": 1, "laugh": 0, "rocket": 0, "total_count": 2, "url": "https://api.github.com/repos/jacquev6/PyGithub/issues/comments/5808311/reactions", }, ) def testEdit(self): self.comment.edit("Comment edited by PyGithub") self.assertEqual(self.comment.body, "Comment edited by PyGithub") self.assertEqual( self.comment.updated_at, datetime(2012, 5, 20, 11, 53, 59, tzinfo=timezone.utc), ) def testMinimize(self): self.assertTrue(self.comment.minimize()) def testUnminimize(self): self.assertTrue(self.comment.unminimize()) def testGetReactions(self): reactions = self.comment.get_reactions() self.assertEqual(reactions[0].content, "+1") def testCreateReaction(self): reaction = self.comment.create_reaction("hooray") self.assertEqual(reaction.id, 17282654) self.assertEqual(reaction.content, "hooray") def testDeleteReaction(self): self.assertTrue(self.comment.delete_reaction(85743754)) # this should be the last test as this deletes the comment used above. def testDelete(self): self.comment.delete()
5,753
Python
.py
106
47.226415
106
0.529641
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,504
Event.py
PyGithub_PyGithub/tests/Event.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Event(Framework.TestCase): def setUp(self): super().setUp() self.event = self.g.get_user("jacquev6").get_events()[0] def testAttributes(self): self.assertEqual(self.event.actor.login, "jacquev6") self.assertEqual( self.event.created_at, datetime(2012, 5, 26, 10, 1, 39, tzinfo=timezone.utc), ) self.assertEqual(self.event.id, "1556114751") self.assertEqual(self.event.org, None) self.assertEqual( self.event.payload, { "commits": [ { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/5bb654d26dd014d36794acd1e6ecf3736f12aad7", "sha": "5bb654d26dd014d36794acd1e6ecf3736f12aad7", "message": "Implement the three authentication schemes", "distinct": False, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/cb0313157bf904f2d364377d35d9397b269547a5", "sha": "cb0313157bf904f2d364377d35d9397b269547a5", "message": "Merge branch 'topic/Authentication' into develop", "distinct": False, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/0cec0d25e606c023a62a4fc7cdc815309ebf6d16", "sha": "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", "message": "Publish version 0.7", "distinct": False, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", "sha": "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", "message": "Merge branch 'develop'", "distinct": False, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/3a3bf4763192ee1234eb0557628133e06f3dfc76", "sha": "3a3bf4763192ee1234eb0557628133e06f3dfc76", "message": "Merge branch 'master' into topic/RewriteWithGeneratedCode\n\nConflicts:\n\tgithub/Github.py\n\tgithub/Requester.py", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/608f17794664f61693a3dc05e6056fea8fbef0ff", "sha": "608f17794664f61693a3dc05e6056fea8fbef0ff", "message": "Restore some form of Authorization header in replay data", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/2c04b8adbd91d38eef4f0767337ab7a12b2f684b", "sha": "2c04b8adbd91d38eef4f0767337ab7a12b2f684b", "message": "Allow test without pre-set-up Github", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/5b97389988b6fe43e15a079702f6f1671257fb28", "sha": "5b97389988b6fe43e15a079702f6f1671257fb28", "message": "Test three authentication schemes", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/12747613c5ec00deccf296b8619ad507f7050475", "sha": "12747613c5ec00deccf296b8619ad507f7050475", "message": "Test Issue.getComments", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/2982fa96c5ca75abe717d974d83f9135d664232e", "sha": "2982fa96c5ca75abe717d974d83f9135d664232e", "message": "Test the new Repository.full_name attribute", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, { "url": "https://api.github.com/repos/jacquev6/PyGithub/commits/619eae8d51c5988f0d2889fc767fa677438ba95d", "sha": "619eae8d51c5988f0d2889fc767fa677438ba95d", "message": "Improve coverage of AuthenticatedUser", "distinct": True, "author": { "name": "Vincent Jacques", "email": "vincent@vincent-jacques.net", }, }, ], "head": "619eae8d51c5988f0d2889fc767fa677438ba95d", "push_id": 80673538, "ref": "refs/heads/topic/RewriteWithGeneratedCode", "size": 11, }, ) self.assertTrue(self.event.public) self.assertEqual(self.event.repo.name, "jacquev6/PyGithub") self.assertEqual(self.event.type, "PushEvent") self.assertEqual(repr(self.event), 'Event(type="PushEvent", id="1556114751")')
9,901
Python
.py
171
39.865497
152
0.454396
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,505
PullRequest1168.py
PyGithub_PyGithub/tests/PullRequest1168.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PullRequest1168(Framework.TestCase): def setUp(self): super().setUp() self.notifications = self.g.get_repo("PyGithub/PyGithub").get_notifications(all=True) def testGetPullRequest(self): p = self.notifications[0].get_pull_request() self.assertEqual(p.id, 297582636) self.assertEqual(p.number, 1171) self.assertEqual(p.title, "Fix small issues for Python 3 compatibility.") def testGetIssue(self): i = self.notifications[0].get_issue() self.assertEqual(i.id, 297582636) self.assertEqual(i.number, 1171) self.assertEqual(i.title, "Fix small issues for Python 3 compatibility.")
3,548
Python
.py
50
67.9
93
0.505305
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,506
Issue87.py
PyGithub_PyGithub/tests/Issue87.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue87(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issues/87 def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("PyGithub") def testCreateIssueWithPercentInTitle(self): issue = self.repo.create_issue("Issue with percent % in title created by PyGithub") self.assertEqual(issue.number, 99) def testCreateIssueWithPercentInBody(self): issue = self.repo.create_issue("Issue created by PyGithub", "Percent % in body") self.assertEqual(issue.number, 98) def testCreateIssueWithEscapedPercentInTitle(self): issue = self.repo.create_issue("Issue with escaped percent %25 in title created by PyGithub") self.assertEqual(issue.number, 97) def testCreateIssueWithEscapedPercentInBody(self): issue = self.repo.create_issue("Issue created by PyGithub", "Escaped percent %25 in body") self.assertEqual(issue.number, 96)
3,579
Python
.py
49
69.857143
101
0.519728
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,507
WorkflowJob.py
PyGithub_PyGithub/tests/WorkflowJob.py
############################ Copyrights and license ############################ # # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jeppe Fihl-Pearson <tenzer@tenzer.dk> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Xavi Vega <xabi1309@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class WorkflowJob(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("PyGithub/PyGithub") self.job = self.repo.get_workflow_run(4205440316).jobs()[0] def testAttributes(self): self.assertEqual(self.job.id, 11421878319) self.assertEqual(self.job.run_id, 4205440316) self.assertEqual( self.job.run_url, "https://api.github.com/repos/PyGithub/PyGithub/actions/runs/4205440316", ) self.assertEqual(self.job.node_id, "CR_kwDOGpsAJ88AAAACqMwILw") self.assertEqual(self.job.head_sha, "06ec040b2eeef6c0316dd5abcda0608525a3f205") self.assertEqual( self.job.url, "https://api.github.com/repos/PyGithub/PyGithub/actions/jobs/11421878319", ) self.assertEqual( self.job.html_url, "https://github.com/PyGithub/PyGithub/actions/runs/4205440316/jobs/7297536068", ) self.assertEqual(self.job.status, "completed") self.assertEqual(self.job.conclusion, "success") started_at = datetime(2023, 2, 17, 16, 3, 46, tzinfo=timezone.utc) self.assertEqual(self.job.started_at, started_at) completed_at = datetime(2023, 2, 17, 16, 4, 52, tzinfo=timezone.utc) self.assertEqual(self.job.completed_at, completed_at) self.assertEqual(self.job.name, "test (Python 3.7)") self.assertEqual( self.job.check_run_url, "https://api.github.com/repos/PyGithub/PyGithub/check-runs/11421878319", ) self.assertListKeyEqual( self.job.steps, lambda s: s.name, [ "Set up job", "Run actions/checkout@v2", "Set up Python", "Install tox", "Run tests", "Upload coverage to Codecov", "Post Set up Python", "Post Run actions/checkout@v2", "Complete job", ], ) self.assertEqual( self.job.logs_url(), "https://pipelines.actions.githubusercontent.com/serviceHosts/d560a817-28d4-4544-a539-eb35c2a56899/_apis/pipelines/1/runs/5/signedlogcontent/5?urlExpires=2023-03-15T17%3A02%3A58.1305046Z&urlSigningMethod=HMACV1&urlSignature=abcdefghijklmn", ) self.assertEqual(self.job.runner_id, 2) self.assertEqual(self.job.runner_name, "GitHub Actions 2") self.assertEqual(self.job.runner_group_id, 2) self.assertEqual(self.job.runner_group_name, "GitHub Actions") created_at = datetime(2023, 2, 17, 16, 3, 38, tzinfo=timezone.utc) self.assertEqual(self.job.created_at, created_at) self.assertEqual(self.job.head_branch, "tz-aware-2") self.assertEqual(self.job.labels, ["ubuntu-latest"]) self.assertEqual(self.job.run_attempt, 1) self.assertEqual(self.job.workflow_name, "CI")
4,961
Python
.py
88
48.409091
252
0.533279
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,508
SecurityAndAnalysis.py
PyGithub_PyGithub/tests/SecurityAndAnalysis.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 karsten-wagner <39054096+karsten-wagner@users.noreply.github.com># # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Caleb McCombs <caleb@mccombalot.net> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class SecurityAndAnalysis(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("transmission-web-control/transmission-web-control") self.maxDiff = None def testRepoSecurityAndAnalysisAttributes(self): self.assertEqual(self.repo.security_and_analysis.advanced_security.status, "disabled") self.assertEqual(self.repo.security_and_analysis.dependabot_security_updates.status, "disabled") self.assertEqual(self.repo.security_and_analysis.secret_scanning.status, "disabled") self.assertEqual(self.repo.security_and_analysis.secret_scanning_push_protection.status, "disabled") self.assertEqual(self.repo.security_and_analysis.secret_scanning_non_provider_patterns.status, "disabled") self.assertEqual(self.repo.security_and_analysis.secret_scanning_validity_checks.status, "disabled") def testRepoSecurityAndAnalysisRepresentation(self): self.assertEqual( repr(self.repo.security_and_analysis), "SecurityAndAnalysis(" 'secret_scanning_validity_checks="SecurityAndAnalysisFeature(status="disabled")", ' 'secret_scanning_push_protection="SecurityAndAnalysisFeature(status="disabled")", ' 'secret_scanning_non_provider_patterns="SecurityAndAnalysisFeature(status="disabled")", ' 'secret_scanning="SecurityAndAnalysisFeature(status="disabled")", ' 'dependabot_security_updates="SecurityAndAnalysisFeature(status="disabled")", ' 'advanced_security="SecurityAndAnalysisFeature(status="disabled")")', )
4,487
Python
.py
59
71.644068
114
0.557314
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,509
GitCommit.py
PyGithub_PyGithub/tests/GitCommit.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class GitCommit(Framework.TestCase): def setUp(self): super().setUp() self.commit = self.g.get_user().get_repo("PyGithub").get_git_commit("4303c5b90e2216d927155e9609436ccb8984c495") def testAttributes(self): self.assertEqual(self.commit.author.name, "Vincent Jacques") self.assertEqual(self.commit.author.email, "vincent@vincent-jacques.net") self.assertEqual( self.commit.author.date, datetime(2012, 4, 17, 17, 55, 16, tzinfo=timezone.utc), ) self.assertEqual(self.commit.committer.name, "Vincent Jacques") self.assertEqual(self.commit.committer.email, "vincent@vincent-jacques.net") self.assertEqual( self.commit.committer.date, datetime(2012, 4, 17, 17, 55, 16, tzinfo=timezone.utc), ) self.assertEqual(self.commit.message, "Merge branch 'develop'\n") self.assertEqual(len(self.commit.parents), 2) self.assertEqual(self.commit.parents[0].sha, "936f4a97f1a86392637ec002bbf89ff036a5062d") self.assertEqual(self.commit.parents[1].sha, "2a7e80e6421c5d4d201d60619068dea6bae612cb") self.assertEqual(self.commit.sha, "4303c5b90e2216d927155e9609436ccb8984c495") self.assertEqual(self.commit.tree.sha, "f492784d8ca837779650d1fb406a1a3587a764ad") self.assertEqual( self.commit.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/4303c5b90e2216d927155e9609436ccb8984c495", ) self.assertEqual( repr(self.commit), 'GitCommit(sha="4303c5b90e2216d927155e9609436ccb8984c495")', ) self.assertEqual(repr(self.commit.author), 'GitAuthor(name="Vincent Jacques")')
4,560
Python
.py
68
61.985294
119
0.54201
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,510
GitTag.py
PyGithub_PyGithub/tests/GitTag.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class GitTag(Framework.TestCase): def setUp(self): super().setUp() self.tag = self.g.get_user().get_repo("PyGithub").get_git_tag("f5f37322407b02a80de4526ad88d5f188977bc3c") def testAttributes(self): self.assertEqual(self.tag.message, "Version 0.6\n") self.assertEqual(self.tag.object.sha, "4303c5b90e2216d927155e9609436ccb8984c495") self.assertEqual(self.tag.object.type, "commit") self.assertEqual( self.tag.object.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/4303c5b90e2216d927155e9609436ccb8984c495", ) self.assertEqual(self.tag.sha, "f5f37322407b02a80de4526ad88d5f188977bc3c") self.assertEqual(self.tag.tag, "v0.6") self.assertEqual( self.tag.tagger.date, datetime(2012, 5, 10, 18, 14, 15, tzinfo=timezone.utc), ) self.assertEqual(self.tag.tagger.email, "vincent@vincent-jacques.net") self.assertEqual(self.tag.tagger.name, "Vincent Jacques") self.assertEqual( self.tag.url, "https://api.github.com/repos/jacquev6/PyGithub/git/tags/f5f37322407b02a80de4526ad88d5f188977bc3c", ) self.assertEqual( repr(self.tag), 'GitTag(tag="v0.6", sha="f5f37322407b02a80de4526ad88d5f188977bc3c")', )
4,175
Python
.py
64
60.40625
114
0.520214
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,511
Traffic.py
PyGithub_PyGithub/tests/Traffic.py
############################ Copyrights and license ############################ # # # Copyright 2018 Justin Kufro <jkufro@andrew.cmu.edu> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Traffic(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user() self.repo = self.user.get_repo("PyGithub") def testGetReferrers(self): referrerResponse = self.repo.get_top_referrers() self.assertGreaterEqual(len(referrerResponse), 1) self.assertEqual(referrerResponse[0].uniques, 1) self.assertEqual(referrerResponse[0].referrer, "github.com") self.assertEqual(referrerResponse[0].count, 5) self.assertEqual( repr(referrerResponse[0]), 'Referrer(uniques=1, referrer="github.com", count=5)', ) def testGetPaths(self): pathsResponse = self.repo.get_top_paths() self.assertEqual(len(pathsResponse), 10) self.assertEqual(pathsResponse[0].uniques, 4) self.assertEqual(pathsResponse[0].count, 23) self.assertEqual(pathsResponse[0].path, "/jkufro/PyGithub") self.assertEqual( pathsResponse[0].title, "jkufro/PyGithub: Typed interactions with the GitHub API v3", ) self.assertEqual( repr(pathsResponse[0]), 'Path(uniques=4, title="jkufro/PyGithub: Typed interactions with the GitHub API v3", path="/jkufro/PyGithub", count=23)', ) def testGetViews(self): viewsResponse = self.repo.get_views_traffic() self.assertEqual(viewsResponse["count"], 93) self.assertEqual(viewsResponse["uniques"], 4) self.assertEqual(len(viewsResponse["views"]), 5) view_obj = viewsResponse["views"][0] self.assertEqual(view_obj.uniques, 4) self.assertEqual( view_obj.timestamp, datetime(2018, 11, 27, 0, 0, tzinfo=timezone.utc), ) self.assertEqual(view_obj.count, 56) self.assertEqual( repr(view_obj), "View(uniques=4, timestamp=2018-11-27 00:00:00+00:00, count=56)", ) def testGetClones(self): clonesResponse = self.repo.get_clones_traffic() self.assertEqual(clonesResponse["count"], 4) self.assertEqual(clonesResponse["uniques"], 4) self.assertEqual(len(clonesResponse["clones"]), 1) clone_obj = clonesResponse["clones"][0] self.assertEqual(clone_obj.uniques, 4) self.assertEqual( clone_obj.timestamp, datetime(2018, 11, 27, 0, 0, tzinfo=timezone.utc), ) self.assertEqual(clone_obj.count, 4) self.assertEqual( repr(clone_obj), "Clones(uniques=4, timestamp=2018-11-27 00:00:00+00:00, count=4)", )
4,799
Python
.py
89
47.033708
133
0.53339
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,512
Notification.py
PyGithub_PyGithub/tests/Notification.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Alice GIRARD <bouhahah@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Matthias Bilger <matthias@bilger.info> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Notification(Framework.TestCase): def setUp(self): super().setUp() self.notification = self.g.get_user().get_notifications()[0] def testMarkAsRead(self): self.notification.mark_as_read() def testMarkAsDone(self): self.notification.mark_as_done()
3,003
Python
.py
42
69.333333
85
0.467185
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,513
Issue139.py
PyGithub_PyGithub/tests/Issue139.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue139(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issues/139 def setUp(self): super().setUp() self.user = self.g.get_user().get_repo("PyGithub").get_issue(139).user def testCompletion(self): self.assertFalse(self.user._CompletableGithubObject__completed) self.assertEqual(self.user.name, "Ian Ozsvald") self.assertTrue(self.user._CompletableGithubObject__completed) self.assertEqual(self.user.plan, None)
3,031
Python
.py
41
71.463415
86
0.482251
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,514
Commit.py
PyGithub_PyGithub/tests/Commit.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Danilo Martins <mawkee@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2024 iarspider <iarspider@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Commit(Framework.TestCase): def setUp(self): super().setUp() self.commit = self.g.get_user().get_repo("PyGithub").get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a") self.commit.author.login # to force lazy completion def testAttributes(self): self.assertEqual(self.commit.author.login, "jacquev6") self.assertEqual( self.commit.commit.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", ) self.assertEqual(self.commit.committer.login, "jacquev6") self.assertEqual(len(list(self.commit.files)), 1) self.assertEqual(self.commit.files.totalCount, 1) self.assertEqual(self.commit.files[0].additions, 0) self.assertEqual( self.commit.files[0].blob_url, "https://github.com/jacquev6/PyGithub/blob/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py", ) self.assertEqual(self.commit.files[0].changes, 20) self.assertEqual(self.commit.files[0].deletions, 20) self.assertEqual(self.commit.files[0].filename, "github/GithubObjects/GitAuthor.py") self.assertTrue(isinstance(self.commit.files[0].patch, str)) self.assertEqual( self.commit.files[0].raw_url, "https://github.com/jacquev6/PyGithub/raw/1292bf0e22c796e91cc3d6e24b544aece8c21f2a/github/GithubObjects/GitAuthor.py", ) self.assertEqual(self.commit.files[0].sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") self.assertEqual(self.commit.files[0].status, "modified") self.assertEqual(len(self.commit.parents), 1) self.assertEqual(self.commit.parents[0].sha, "b46ed0dfde5ad02d3b91eb54a41c5ed960710eae") self.assertEqual(self.commit.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") self.assertEqual(self.commit.stats.deletions, 20) self.assertEqual(self.commit.stats.additions, 0) self.assertEqual(self.commit.stats.total, 20) self.assertEqual( self.commit.url, "https://api.github.com/repos/jacquev6/PyGithub/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", ) self.assertEqual(self.commit.commit.tree.sha, "4c6bd50994f0f9823f898b1c6c964ad7d4fa11ab") self.assertEqual( repr(self.commit), 'Commit(sha="1292bf0e22c796e91cc3d6e24b544aece8c21f2a")', ) def testGetComments(self): self.assertListKeyEqual( self.commit.get_comments(), lambda c: c.id, [1347033, 1347083, 1347397, 1349654], ) def testCreateComment(self): comment = self.commit.create_comment("Comment created by PyGithub") self.assertEqual(comment.id, 1361949) self.assertEqual(comment.line, None) self.assertEqual(comment.path, None) self.assertEqual(comment.position, None) def testCreateCommentOnFileLine(self): comment = self.commit.create_comment( "Comment created by PyGithub", path="codegen/templates/GithubObject.MethodBody.UseResult.py", line=26, ) self.assertEqual(comment.id, 1362000) self.assertEqual(comment.line, 26) self.assertEqual(comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py") self.assertEqual(comment.position, None) def testCreateCommentOnFilePosition(self): comment = self.commit.create_comment( "Comment also created by PyGithub", path="codegen/templates/GithubObject.MethodBody.UseResult.py", position=3, ) self.assertEqual(comment.id, 1362001) self.assertEqual(comment.line, None) self.assertEqual(comment.path, "codegen/templates/GithubObject.MethodBody.UseResult.py") self.assertEqual(comment.position, 3) def testCreateStatusWithoutOptionalParameters(self): status = self.commit.create_status("pending") self.assertEqual(status.id, 277031) self.assertEqual(status.state, "pending") self.assertEqual(status.target_url, None) self.assertEqual(status.description, None) def testCreateStatusWithAllParameters(self): status = self.commit.create_status( "success", "https://github.com/jacquev6/PyGithub/issues/67", "Status successfuly created by PyGithub", ) self.assertEqual(status.id, 277040) self.assertEqual(status.state, "success") self.assertEqual(status.target_url, "https://github.com/jacquev6/PyGithub/issues/67") self.assertEqual(status.description, "Status successfuly created by PyGithub") def testGetPulls(self): commit = self.g.get_user().get_repo("PyGithub").get_commit("e44d11d565c022496544dd6ed1f19a8d718c2b0c") self.assertListKeyEqual(commit.get_pulls(), lambda c: c.number, [1431])
7,899
Python
.py
132
52.666667
131
0.601986
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,515
Organization2072.py
PyGithub_PyGithub/tests/Organization2072.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Anuj Bansal <bansalanuj1996@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 James Simpson <jsimpso@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Organization2072(Framework.TestCase): def setUp(self): super().setUp() self.org = self.g.get_organization("TestOrganization2072") def testCancelInvitation(self): self.assertFalse(any([i for i in self.org.invitations() if i.email == "foo@bar.org"])) self.org.invite_user(email="foo@bar.org") self.assertTrue(any([i for i in self.org.invitations() if i.email == "foo@bar.org"])) invitation = [i for i in self.org.invitations() if i.email == "foo@bar.org"][0] self.assertTrue(self.org.cancel_invitation(invitation))
3,700
Python
.py
49
73
94
0.503158
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,516
Installation.py
PyGithub_PyGithub/tests/Installation.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from urllib3.exceptions import InsecureRequestWarning import github from github import Consts from github.Auth import AppAuth, AppInstallationAuth from . import Framework, GithubIntegration class Installation(Framework.BasicTestCase): def setUp(self): super().setUp() app_id = 36541767 private_key = GithubIntegration.PRIVATE_KEY self.auth = AppAuth(app_id, private_key) self.integration = github.GithubIntegration(auth=self.auth) self.installations = list(self.integration.get_installations()) def testGetRepos(self): self.assertEqual(len(self.installations), 1) installation = self.installations[0] repos = list(installation.get_repos()) self.assertEqual(len(repos), 2) self.assertListEqual([repo.full_name for repo in repos], ["EnricoMi/sandbox", "EnricoMi/python"]) def testGetGithubForInstallation(self): # with verify=False, urllib3.connectionpool rightly may issue an InsecureRequestWarning # we ignore InsecureRequestWarning from urllib3.connectionpool with self.ignoreWarning(category=InsecureRequestWarning, module="urllib3.connectionpool"): kwargs = dict( auth=AppAuth(319953, GithubIntegration.PRIVATE_KEY), # http protocol used to deviate from default base url, recording data might require https base_url="http://api.github.com", timeout=Consts.DEFAULT_TIMEOUT + 10, user_agent="PyGithub/Python-Test", per_page=Consts.DEFAULT_PER_PAGE + 10, verify=False, retry=3, pool_size=10, seconds_between_requests=100, seconds_between_writes=1000, ) # assert kwargs consists of ALL requester constructor arguments self.assertEqual(kwargs.keys(), github.Requester.Requester.__init__.__annotations__.keys()) self.integration = github.GithubIntegration(**kwargs) installations = list(self.integration.get_installations()) installation = installations[0] g = installation.get_github_for_installation() self.assertIsInstance(g._Github__requester.auth, AppInstallationAuth) actual = g._Github__requester.kwargs kwargs.update(auth=str(AppInstallationAuth)) actual.update(auth=str(type(actual["auth"]))) self.assertDictEqual(kwargs, actual) repo = g.get_repo("PyGithub/PyGithub") self.assertEqual(repo.full_name, "PyGithub/PyGithub") def testRequester(self): self.assertEqual(len(self.installations), 1) installation = self.installations[0] assert installation.requester is installation._requester
5,575
Python
.py
87
57.068966
105
0.560387
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,517
Pickle.py
PyGithub_PyGithub/tests/Pickle.py
############################ Copyrights and license ############################ # # # Copyright 2023 Andrew Dawes <53574062+AndrewJDawes@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Hemslo Wang <hemslo.wang@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import pickle import unittest import github from github.PaginatedList import PaginatedList from github.Repository import Repository REPO_NAME = "PyGithub/PyGithub" class Pickle(unittest.TestCase): def testPickleGithub(self): gh = github.Github() gh2 = pickle.loads(pickle.dumps(gh)) self.assertIsInstance(gh2, github.Github) self.assertIsNotNone(gh2._Github__requester._Requester__connection_lock) self.assertIsNone(gh2._Github__requester._Requester__connection) self.assertEqual(len(gh2._Github__requester._Requester__custom_connections), 0) def testPickleRepository(self): gh = github.Github() repo = gh.get_repo(REPO_NAME, lazy=True) repo2 = pickle.loads(pickle.dumps(repo)) self.assertIsInstance(repo2, Repository) self.assertIsNotNone(repo2._requester._Requester__connection_lock) self.assertIsNone(repo2._requester._Requester__connection) self.assertEqual(len(repo2._requester._Requester__custom_connections), 0) def testPicklePaginatedList(self): gh = github.Github() repo = gh.get_repo(REPO_NAME, lazy=True) branches = repo.get_branches() branches2 = pickle.loads(pickle.dumps(branches)) self.assertIsInstance(branches2, PaginatedList)
3,170
Python
.py
51
57.960784
87
0.525386
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,518
Team.py
PyGithub_PyGithub/tests/Team.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 mattjmorrison <mattjmorrison@mattjmorrison.com> # # Copyright 2018 Isuru Fernando <isuruf@gmail.com> # # Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> # # Copyright 2018 James D'Amato <james.j.damato@gmail.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Tim Boring <tboring@hearst.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Adrian Bridgett <58699309+tl-adrian-bridgett@users.noreply.github.com># # Copyright 2020 Andy Grunwald <andygrunwald@gmail.com> # # Copyright 2020 Gilad Shefer <giladshefer@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2020 Tal Machani <12785464+talmachani@users.noreply.github.com> # # Copyright 2021 秋葉 <ambiguous404@gmail.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2024 Andrii Kezikov <cheshirez@gmail.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import warnings from datetime import datetime, timezone from . import Framework class Team(Framework.TestCase): def setUp(self): super().setUp() self.org = self.g.get_organization("BeaverSoftware") self.team = self.org.get_team(189850) def testAttributes(self): self.assertEqual(self.team.id, 189850) self.assertEqual(self.team.members_count, 0) self.assertEqual(self.team.name, "Team created by PyGithub") self.assertEqual(self.team.permission, "pull") self.assertEqual(self.team.repos_count, 0) self.assertEqual(self.team.url, "https://api.github.com/teams/189850") self.assertEqual(self.team.organization, self.org) self.assertEqual(self.team.privacy, "closed") self.assertEqual(self.team.parent, None) self.assertEqual(repr(self.team), 'Team(name="Team created by PyGithub", id=189850)') self.assertEqual(self.team.html_url, "https://github.com/orgs/BeaverSoftware/teams/core") def testDiscussions(self): discussions = list(self.team.get_discussions()) self.assertEqual(len(discussions), 1) d = discussions[0] self.assertEqual(d.author.login, "jacquev6") self.assertEqual(d.body, "BODY") self.assertEqual(d.body_html, "<p>BODY</p>") self.assertEqual(d.body_version, "bedf0740b01d2d758cff9873c2387817") self.assertEqual(d.comments_count, 0) self.assertEqual(d.comments_url, "https://api.github.com/teams/189850/discussions/1/comments") self.assertEqual(d.created_at, datetime(2019, 10, 8, 21, 3, 36, tzinfo=timezone.utc)) self.assertEqual( d.html_url, "https://github.com/orgs/BeaverSoftware/teams/Team/discussions/1", ) self.assertEqual(d.last_edited_at, None) self.assertEqual(d.node_id, "MDE0OlRlYW1EaXNjdXNzaW9uMzA=") self.assertEqual(d.number, 1) self.assertEqual(d.pinned, True) self.assertEqual(d.private, False) self.assertEqual(d.team_url, "https://api.github.com/teams/189850") self.assertEqual(d.title, "TITLE") self.assertEqual(d.updated_at, datetime(2019, 10, 8, 21, 3, 36, tzinfo=timezone.utc)) self.assertEqual(d.url, "https://api.github.com/teams/189850/discussions/1") self.assertEqual(repr(d), 'TeamDiscussion(title="TITLE", number=1)') def testMembers(self): user = self.g.get_user("jacquev6") self.assertListKeyEqual(self.team.get_members(), None, []) self.assertFalse(self.team.has_in_members(user)) self.team.add_to_members(user) self.assertListKeyEqual(self.team.get_members(), lambda u: u.login, ["jacquev6"]) self.assertTrue(self.team.has_in_members(user)) self.team.remove_from_members(user) self.assertListKeyEqual(self.team.get_members(), None, []) self.assertFalse(self.team.has_in_members(user)) self.team.add_membership(user, "maintainer") self.assertRaises(AssertionError, self.team.add_membership, user, "admin") self.team.remove_membership(user) def testTeamMembership(self): user = self.g.get_user("jacquev6") self.assertEqual(list(self.team.get_members()), []) self.assertFalse(self.team.has_in_members(user)) self.team.add_membership(user) self.assertListKeyEqual(self.team.get_members(), lambda u: u.login, ["jacquev6"]) self.assertTrue(self.team.has_in_members(user)) membership_data = self.team.get_team_membership(user) self.assertEqual(membership_data.user.login, "jacquev6") self.assertEqual(membership_data.role, "member") self.assertEqual(membership_data.organization.login, "BeaverSoftware") def testRepoPermission(self): repo = self.org.get_repo("FatherBeaver") # Ignore the warning since this method is deprecated warnings.filterwarnings("ignore", category=DeprecationWarning) self.team.set_repo_permission(repo, "admin") warnings.resetwarnings() def testUpdateTeamRepository(self): repo = self.org.get_repo("FatherBeaver") self.assertTrue(self.team.update_team_repository(repo, "admin")) def testRepos(self): repo = self.org.get_repo("FatherBeaver") self.assertListKeyEqual(self.team.get_repos(), None, []) self.assertFalse(self.team.has_in_repos(repo)) self.assertIsNone(self.team.get_repo_permission(repo)) self.team.add_to_repos(repo) self.assertListKeyEqual(self.team.get_repos(), lambda r: r.name, ["FatherBeaver"]) self.assertTrue(self.team.has_in_repos(repo)) permissions = self.team.get_repo_permission(repo) self.assertTrue(permissions.pull) self.team.remove_from_repos(repo) self.assertListKeyEqual(self.team.get_repos(), None, []) self.assertFalse(self.team.has_in_repos(repo)) def testEditWithoutArguments(self): self.team.edit("Name edited by PyGithub") self.assertEqual(self.team.name, "Name edited by PyGithub") def testEditWithAllArguments(self): parent = self.org.get_team(141496) self.team.edit( "Name edited twice by PyGithub", "Description edited by PyGithub", "admin", "secret", parent.id, "notifications_disabled", ) self.assertEqual(self.team.name, "Name edited twice by PyGithub") self.assertEqual(self.team.description, "Description edited by PyGithub") self.assertEqual(self.team.permission, "admin") self.assertEqual(self.team.privacy, "secret") self.assertEqual(self.team.parent, parent) self.assertEqual(self.team.notification_setting, "notifications_disabled") def testGetTeams(self): nested_teams = self.team.get_teams() self.assertListKeyEqual(nested_teams, lambda t: t.name, ["DummyTeam1", "DummyTeam2", "DummyTeam3"]) parent = nested_teams[0].parent self.assertEqual(self.team.name, parent.name) self.assertEqual(self.team.id, parent.id) def testDelete(self): self.team.delete()
10,083
Python
.py
166
54.216867
107
0.60388
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,519
Search.py
PyGithub_PyGithub/tests/Search.py
############################ Copyrights and license ############################ # # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Agor Maxime <maxime.agor23@gmail.com> # # Copyright 2018 Joel Koglin <JoelKoglin@gmail.com> # # Copyright 2018 Shubham Singh <41840111+singh811@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 h.shi <10385628+AnYeMoWang@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Search(Framework.TestCase): def setUp(self): super().setUp() def testSearchUsers(self): users = self.g.search_users("vincent", sort="followers", order="desc") self.assertEqual(users.totalCount, 2781) def testPaginateSearchUsers(self): users = self.g.search_users("", location="Berlin") self.assertListKeyBegin( users, lambda u: u.login, [ "cloudhead", "felixge", "sferik", "rkh", "jezdez", "janl", "marijnh", "nikic", "igorw", "froschi", "svenfuchs", "omz", "chad", "bergie", "roidrage", "pcalcado", "durran", "hukl", "mttkay", "aFarkas", "ole", "hagenburger", "jberkel", "naderman", "joshk", "pudo", "robb", "josephwilk", "hanshuebner", "txus", "paulasmuth", "splitbrain", "langalex", "bendiken", "stefanw", ], ) self.assertEqual(users.totalCount, 6038) def testGetPageOnSearchUsers(self): users = self.g.search_users("", location="Berlin") self.assertEqual( [u.login for u in users.get_page(7)], [ "ursachec", "bitboxer", "fs111", "michenriksen", "witsch", "booo", "mortice", "r0man", "MikeBild", "mhagger", "bkw", "fwbrasil", "mschneider", "lydiapintscher", "asksven", "iamtimm", "sneak", "kr1sp1n", "Feh", "GordonLesti", "annismckenzie", "eskimoblood", "tsujigiri", "riethmayer", "lauritzthamsen", "scotchi", "peritor", "toto", "hwaxxer", "lukaszklis", ], ) def testSearchRepos(self): repos = self.g.search_repositories("github", sort="stars", order="desc", language="Python") self.assertListKeyBegin( repos, lambda r: r.full_name, [ "kennethreitz/legit", "RuudBurger/CouchPotatoV1", "gelstudios/gitfiti", "gpjt/webgl-lessons", "jacquev6/PyGithub", "aaasen/github_globe", "hmason/gitmarks", "dnerdy/factory_boy", "binaryage/drydrop", "bgreenlee/sublime-github", "karan/HackerNewsAPI", "mfenniak/pyPdf", "skazhy/github-decorator", "llvmpy/llvmpy", "lexrupy/gmate", "ask/python-github2", "audreyr/cookiecutter-pypackage", "tabo/django-treebeard", "dbr/tvdb_api", "jchris/couchapp", "joeyespo/grip", "nigelsmall/py2neo", "ask/chishop", "sigmavirus24/github3.py", "jsmits/github-cli", "lincolnloop/django-layout", "amccloud/django-project-skel", "Stiivi/brewery", "webpy/webpy.github.com", "dustin/py-github", "logsol/Github-Auto-Deploy", "cloudkick/libcloud", "berkerpeksag/github-badge", "bitprophet/ssh", "azavea/OpenTreeMap", ], ) def testSearchReposWithNoResults(self): repos = self.g.search_repositories("doesnotexist") self.assertEqual(repos.totalCount, 0) def testSearchIssues(self): issues = self.g.search_issues("compile", sort="comments", order="desc", language="C++") self.assertListKeyBegin( issues, lambda i: i.id, [ 12068673, 23250111, 14371957, 9423897, 24277400, 2408877, 11338741, 13980502, 27697165, 23102422, ], ) def testPaginateSearchCommits(self): commits = self.g.search_commits(query="hash:5b0224e868cc9242c9450ef02efbe3097abd7ba2") self.assertEqual(commits.totalCount, 3) def testSearchCommits(self): commits = self.g.search_commits( query="hash:1265747e992ba7d34a469b6b2f527809f8bf7067", sort="author-date", order="asc", merge="false", ) self.assertEqual(commits.totalCount, 2) def testSearchTopics(self): topics = self.g.search_topics("python", repositories=">950") self.assertListKeyBegin( topics, lambda r: r.name, ["python", "django", "flask", "ruby", "scikit-learn", "wagtail"], ) def testPaginateSearchTopics(self): repos = self.g.search_topics("python", repositories=">950") self.assertEqual(repos.totalCount, 6) def testSearchCode(self): files = self.g.search_code("toto", sort="indexed", order="asc", user="jacquev6") self.assertListKeyEqual( files, lambda f: f.name, [ "Commit.setUp.txt", "PullRequest.testGetFiles.txt", "NamedUser.testGetEvents.txt", "PullRequest.testCreateComment.txt", "PullRequestFile.setUp.txt", "Repository.testGetIssuesWithWildcards.txt", "Repository.testGetIssuesWithArguments.txt", "test_ebnf.cpp", "test_abnf.cpp", "PullRequestFile.py", "SystemCalls.py", "tests.py", "LexerTestCase.py", "ParserTestCase.py", ], ) self.assertEqual(files[0].repository.full_name, "jacquev6/PyGithub") content = files[0].decoded_content if isinstance(content, bytes): content = content.decode("utf-8") self.assertEqual(content[:30], "https\nGET\napi.github.com\nNone\n") def testSearchHighlightingCode(self): files = self.g.search_code("toto", sort="indexed", order="asc", user="jacquev6", highlight=True) self.assertTrue(files[0].text_matches) def testUrlquotingOfQualifiers(self): # Example taken from #236 issues = self.g.search_issues("repo:saltstack/salt-api type:Issues", updated=">2014-03-04T18:28:11Z") self.assertEqual(issues[0].id, 29138794) def testUrlquotingOfQuery(self): # Example taken from #236 issues = self.g.search_issues("repo:saltstack/salt-api type:Issues updated:>2014-03-04T18:28:11Z") self.assertEqual(issues[0].id, 29138794)
10,375
Python
.py
247
29.955466
109
0.478588
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,520
SelfHostedActionsRunner.py
PyGithub_PyGithub/tests/SelfHostedActionsRunner.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2020 Victor Zeng <zacker150@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Trim21 <trim21.me@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class SelfHostedActionsRunner(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user("ReDASers") self.repo = self.user.get_repo("Phishing-Detection") def testAttributes(self): runner = self.repo.get_self_hosted_runner(2217) self.assertEqual(2217, runner.id) self.assertEqual("linux", runner.os) self.assertEqual("4306125c7c84", runner.name) self.assertEqual("offline", runner.status) self.assertFalse(runner.busy) labels = runner.labels() self.assertEqual(3, len(labels)) self.assertEqual("self-hosted", labels[0]["name"]) self.assertEqual("X64", labels[1]["name"]) self.assertEqual("Linux", labels[2]["name"])
3,464
Python
.py
51
64.490196
85
0.490466
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,521
Authorization.py
PyGithub_PyGithub/tests/Authorization.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Authorization(Framework.TestCase): def setUp(self): super().setUp() self.authorization = self.g.get_user().get_authorization(372259) def testAttributes(self): self.assertEqual( self.authorization.app.url, "http://developer.github.com/v3/oauth/#oauth-authorizations-api", ) self.assertEqual(self.authorization.app.name, "GitHub API") self.assertEqual( self.authorization.created_at, datetime(2012, 5, 22, 18, 3, 17, tzinfo=timezone.utc), ) self.assertEqual(self.authorization.id, 372259) self.assertEqual(self.authorization.note, None) self.assertEqual(self.authorization.note_url, None) self.assertEqual(self.authorization.scopes, []) self.assertEqual(self.authorization.token, "82459c4500086f8f0cc67d2936c17d1e27ad1c33") self.assertEqual( self.authorization.updated_at, datetime(2012, 5, 22, 18, 3, 17, tzinfo=timezone.utc), ) self.assertEqual(self.authorization.url, "https://api.github.com/authorizations/372259") self.assertEqual(repr(self.authorization), "Authorization(scopes=[])") self.assertEqual(repr(self.authorization.app), 'AuthorizationApplication(name="GitHub API")') def testEdit(self): self.authorization.edit() self.assertEqual(self.authorization.scopes, []) self.authorization.edit(scopes=["user"]) self.assertEqual(self.authorization.scopes, ["user"]) self.authorization.edit(add_scopes=["repo"]) self.assertEqual(self.authorization.scopes, ["user", "repo"]) self.authorization.edit(remove_scopes=["repo"]) self.assertEqual(self.authorization.scopes, ["user"]) self.assertEqual(self.authorization.note, None) self.assertEqual(self.authorization.note_url, None) self.authorization.edit( note="Note created by PyGithub", note_url="http://vincent-jacques.net/PyGithub", ) self.assertEqual(self.authorization.note, "Note created by PyGithub") self.assertEqual(self.authorization.note_url, "http://vincent-jacques.net/PyGithub") def testDelete(self): self.authorization.delete()
4,935
Python
.py
79
56.721519
101
0.555166
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,522
Framework.py
PyGithub_PyGithub/tests/Framework.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 AKFish <akfish@gmail.com> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2015 Uriel Corfa <uriel@corfa.fr> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com> # # Copyright 2017 Hugo <hugovk@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Arda Kuyumcu <kuyumcuarda@gmail.com> # # Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> # # Copyright 2018 Laurent Mazuel <lmazuel@microsoft.com> # # Copyright 2018 Mike Miller <github@mikeage.net> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Filipe Laíns <filipe.lains@gmail.com> # # Copyright 2019 Isac Souza <isouza@daitan.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Alice GIRARD <bouhahah@gmail.com> # # Copyright 2020 Michał Górny <mgorny@gentoo.org> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Amador Pahim <apahim@redhat.com> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Denis Blanchette <dblanchette@coveo.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Jonathan Leitschuh <jonathan.leitschuh@gmail.com> # # Copyright 2023 Trim21 <trim21.me@gmail.com> # # Copyright 2023 chantra <chantra@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import contextlib import io import json import os import traceback import unittest import warnings from typing import Optional import httpretty # type: ignore from requests.structures import CaseInsensitiveDict from urllib3.util import Url # type: ignore import github from github import Consts APP_PRIVATE_KEY = """ -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQC+5ePolLv6VcWLp2f17g6r6vHl+eoLuodOOfUl8JK+MVmvXbPa xDy0SS0pQhwTOMtB0VdSt++elklDCadeokhEoGDQp411o+kiOhzLxfakp/kewf4U HJnu4M/A2nHmxXVe2lzYnZvZHX5BM4SJo5PGdr0Ue2JtSXoAtYr6qE9maQIDAQAB AoGAFhOJ7sy8jG+837Clcihso+8QuHLVYTPaD+7d7dxLbBlS8NfaQ9Nr3cGUqm/N xV9NCjiGa7d/y4w/vrPwGh6UUsA+CvndwDgBd0S3WgIdWvAvHM8wKgNh/GBLLzhT Bg9BouRUzcT1MjAnkGkWqqCAgN7WrCSUMLt57TNleNWfX90CQQDjvVKTT3pOiavD 3YcLxwkyeGd0VMvKiS4nV0XXJ97cGXs2GpOGXldstDTnF5AnB6PbukdFLHpsx4sW Hft3LRWnAkEA1pY15ke08wX6DZVXy7zuQ2izTrWSGySn7B41pn55dlKpttjHeutA 3BEQKTFvMhBCphr8qST7Wf1SR9FgO0tFbwJAEhHji2yy96hUyKW7IWQZhrem/cP8 p4Va9CQolnnDZRNgg1p4eiDiLu3dhLiJ547joXuWTBbLX/Y1Qvv+B+a74QJBAMCW O3WbMZlS6eK6//rIa4ZwN00SxDg8I8FUM45jwBsjgVGrKQz2ilV3sutlhIiH82kk m1Iq8LMJGYl/LkDJA10CQBV1C+Xu3ukknr7C4A/4lDCa6Xb27cr1HanY7i89A+Ab eatdM6f/XVqWp8uPT9RggUV9TjppJobYGT2WrWJMkYw= -----END RSA PRIVATE KEY----- """ def readLine(file_): line = file_.readline() if isinstance(line, bytes): line = line.decode("utf-8") return line.strip() class FakeHttpResponse: def __init__(self, status, headers, output): self.status = status self.__headers = headers self.__output = output def getheaders(self): return self.__headers def read(self): return self.__output def fixAuthorizationHeader(headers): if "Authorization" in headers: if headers["Authorization"].endswith("ZmFrZV9sb2dpbjpmYWtlX3Bhc3N3b3Jk"): # This special case is here to test the real Authorization header # sent by PyGithub. It would have avoided issue https://github.com/jacquev6/PyGithub/issues/153 # because we would have seen that Python 3 was not generating the same # header as Python 2 pass elif headers["Authorization"].startswith("token "): headers["Authorization"] = "token private_token_removed" elif headers["Authorization"].startswith("Basic "): headers["Authorization"] = "Basic login_and_password_removed" elif headers["Authorization"].startswith("Bearer "): headers["Authorization"] = "Bearer jwt_removed" class RecordingConnection: def __init__(self, file, protocol, host, port, *args, **kwds): # write operations make the assumption that the file is not in binary mode assert isinstance(file, io.TextIOBase) self.__file = file self.__protocol = protocol self.__host = host self.__port = port self.__cnx = self._realConnection(host, port, *args, **kwds) def request(self, verb, url, input, headers): self.__cnx.request(verb, url, input, headers) # fixAuthorizationHeader changes the parameter directly to remove Authorization token. # however, this is the real dictionary that *will be sent* by "requests", # since we are writing here *before* doing the actual request. # So we must avoid changing the real "headers" or this create this: # https://github.com/PyGithub/PyGithub/pull/664#issuecomment-389964369 # https://github.com/PyGithub/PyGithub/issues/822 # Since it's dict[str, str], a simple copy is enough. anonymous_headers = headers.copy() fixAuthorizationHeader(anonymous_headers) self.__writeLine(self.__protocol) self.__writeLine(verb) self.__writeLine(self.__host) self.__writeLine(self.__port) self.__writeLine(url) self.__writeLine(anonymous_headers) self.__writeLine(str(input).replace("\n", "").replace("\r", "")) def getresponse(self): res = self.__cnx.getresponse() status = res.status headers = res.getheaders() output = res.read() self.__writeLine(status) self.__writeLine(list(headers)) self.__writeLine(output) return FakeHttpResponse(status, headers, output) def close(self): self.__writeLine("") return self.__cnx.close() def __writeLine(self, line): self.__file.write(str(line) + "\n") class RecordingHttpConnection(RecordingConnection): _realConnection = github.Requester.HTTPRequestsConnectionClass def __init__(self, file, *args, **kwds): super().__init__(file, "http", *args, **kwds) class RecordingHttpsConnection(RecordingConnection): _realConnection = github.Requester.HTTPSRequestsConnectionClass def __init__(self, file, *args, **kwds): super().__init__(file, "https", *args, **kwds) class ReplayingConnection: def __init__(self, file, protocol, host, port, *args, **kwds): self.__file = file self.__protocol = protocol self.__host = host self.__port = port self.response_headers = CaseInsensitiveDict() self.__cnx = self._realConnection(host, port, *args, **kwds) def request(self, verb, url, input, headers): full_url = Url(scheme=self.__protocol, host=self.__host, port=self.__port, path=url) httpretty.register_uri(verb, full_url.url, body=self.__request_callback) self.__cnx.request(verb, url, input, headers) def __readNextRequest(self, verb, url, input, headers): fixAuthorizationHeader(headers) assert self.__protocol == readLine(self.__file) assert verb == readLine(self.__file) assert self.__host == readLine(self.__file) assert str(self.__port) == readLine(self.__file) assert self.__splitUrl(url) == self.__splitUrl(readLine(self.__file)) assert headers == eval(readLine(self.__file)) expectedInput = readLine(self.__file) if isinstance(input, str): trInput = input.replace("\n", "").replace("\r", "") if input.startswith("{"): assert expectedInput.startswith("{"), expectedInput assert json.loads(trInput) == json.loads(expectedInput) else: assert trInput == expectedInput else: # for non-string input (e.g. upload asset), let it pass. pass def __splitUrl(self, url): splitedUrl = url.split("?") if len(splitedUrl) == 1: return splitedUrl assert len(splitedUrl) == 2 base, qs = splitedUrl return (base, sorted(qs.split("&"))) def __request_callback(self, request, uri, response_headers): self.__readNextRequest(self.__cnx.verb, self.__cnx.url, self.__cnx.input, self.__cnx.headers) status = int(readLine(self.__file)) self.response_headers = CaseInsensitiveDict(eval(readLine(self.__file))) output = bytearray(readLine(self.__file), "utf-8") readLine(self.__file) # make a copy of the headers and remove the ones that interfere with the response handling adding_headers = CaseInsensitiveDict(self.response_headers) adding_headers.pop("content-length", None) adding_headers.pop("transfer-encoding", None) adding_headers.pop("content-encoding", None) response_headers.update(adding_headers) return [status, response_headers, output] def getresponse(self): # call original connection, this will go all the way down to the python socket and will be intercepted by httpretty response = self.__cnx.getresponse() # restore original headers to the response response.headers = self.response_headers return response def close(self): self.__cnx.close() class ReplayingHttpConnection(ReplayingConnection): _realConnection = github.Requester.HTTPRequestsConnectionClass def __init__(self, file, *args, **kwds): super().__init__(file, "http", *args, **kwds) class ReplayingHttpsConnection(ReplayingConnection): _realConnection = github.Requester.HTTPSRequestsConnectionClass def __init__(self, file, *args, **kwds): super().__init__(file, "https", *args, **kwds) class BasicTestCase(unittest.TestCase): recordMode = False tokenAuthMode = False jwtAuthMode = False per_page = Consts.DEFAULT_PER_PAGE retry = None pool_size = None seconds_between_requests: Optional[float] = None seconds_between_writes: Optional[float] = None replayDataFolder = os.path.join(os.path.dirname(__file__), "ReplayData") def setUp(self): super().setUp() self.__fileName = "" self.__file = None if ( self.recordMode ): # pragma no cover (Branch useful only when recording new tests, not used during automated tests) github.Requester.Requester.injectConnectionClasses( lambda ignored, *args, **kwds: RecordingHttpConnection(self.__openFile("w"), *args, **kwds), lambda ignored, *args, **kwds: RecordingHttpsConnection(self.__openFile("w"), *args, **kwds), ) import GithubCredentials # type: ignore self.login = ( github.Auth.Login(GithubCredentials.login, GithubCredentials.password) if GithubCredentials.login and GithubCredentials.password else None ) self.oauth_token = ( github.Auth.Token(GithubCredentials.oauth_token) if GithubCredentials.oauth_token else None ) self.jwt = github.Auth.AppAuthToken(GithubCredentials.jwt) if GithubCredentials.jwt else None self.app_auth = ( github.Auth.AppAuth(GithubCredentials.app_id, GithubCredentials.app_private_key) if GithubCredentials.app_id and GithubCredentials.app_private_key else None ) else: github.Requester.Requester.injectConnectionClasses( lambda ignored, *args, **kwds: ReplayingHttpConnection(self.__openFile("r"), *args, **kwds), lambda ignored, *args, **kwds: ReplayingHttpsConnection(self.__openFile("r"), *args, **kwds), ) self.login = github.Auth.Login("login", "password") self.oauth_token = github.Auth.Token("oauth_token") self.jwt = github.Auth.AppAuthToken("jwt") self.app_auth = github.Auth.AppAuth(123456, APP_PRIVATE_KEY) httpretty.enable(allow_net_connect=False) @property def thisTestFailed(self) -> bool: if hasattr(self._outcome, "errors"): # type: ignore # Python 3.4 - 3.10 result = self.defaultTestResult() self._feedErrorsToResult(result, self._outcome.errors) # type: ignore ok = all(test != self for test, text in result.errors + result.failures) return not ok else: # Python 3.11+ return self._outcome.result._excinfo is not None and self._outcome.result._excinfo # type: ignore def tearDown(self): super().tearDown() httpretty.disable() httpretty.reset() self.__closeReplayFileIfNeeded(silent=self.thisTestFailed) github.Requester.Requester.resetConnectionClasses() def assertWarning(self, warning, expected): self.assertWarnings(warning, expected) def assertWarnings(self, warning, *expecteds): actual = [(type(message), type(message.message), message.message.args) for message in warning.warnings] expected = [(warnings.WarningMessage, DeprecationWarning, (expected,)) for expected in expecteds] self.assertSequenceEqual(actual, expected) @contextlib.contextmanager def ignoreWarning(self, category=Warning, module=""): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=category, module=module) yield def __openFile(self, mode): for _, _, functionName, _ in traceback.extract_stack(): if functionName.startswith("test") or functionName == "setUp" or functionName == "tearDown": if functionName != "test": # because in class Hook(Framework.TestCase), method testTest calls Hook.test fileName = os.path.join( self.replayDataFolder, f"{self.__class__.__name__}.{functionName}.txt", ) if fileName != self.__fileName: self.__closeReplayFileIfNeeded() self.__fileName = fileName self.__file = open(self.__fileName, mode, encoding="utf-8") return self.__file def __closeReplayFileIfNeeded(self, silent=False): if self.__file is not None: if ( not self.recordMode and not silent ): # pragma no branch (Branch useful only when recording new tests, not used during automated tests) self.assertEqual(readLine(self.__file), "", self.__fileName) self.__file.close() def assertListKeyEqual(self, elements, key, expectedKeys): realKeys = [key(element) for element in elements] self.assertEqual(realKeys, expectedKeys) def assertListKeyBegin(self, elements, key, expectedKeys): realKeys = [key(element) for element in elements[: len(expectedKeys)]] self.assertEqual(realKeys, expectedKeys) class TestCase(BasicTestCase): def doCheckFrame(self, obj, frame): if obj._headers == {} and frame is None: return if obj._headers is None and frame == {}: return self.assertEqual(obj._headers, frame[2]) def getFrameChecker(self): return lambda requester, obj, frame: self.doCheckFrame(obj, frame) def setUp(self): super().setUp() # Set up frame debugging github.GithubObject.GithubObject.setCheckAfterInitFlag(True) github.Requester.Requester.setDebugFlag(True) github.Requester.Requester.setOnCheckMe(self.getFrameChecker()) self.g = self.get_github(self.retry, self.pool_size) def get_github(self, retry, pool_size): if self.tokenAuthMode: return github.Github( auth=self.oauth_token, per_page=self.per_page, retry=retry, pool_size=pool_size, seconds_between_requests=self.seconds_between_requests, seconds_between_writes=self.seconds_between_writes, ) elif self.jwtAuthMode: return github.Github( auth=self.jwt, per_page=self.per_page, retry=retry, pool_size=pool_size, seconds_between_requests=self.seconds_between_requests, seconds_between_writes=self.seconds_between_writes, ) else: return github.Github( auth=self.login, per_page=self.per_page, retry=retry, pool_size=pool_size, seconds_between_requests=self.seconds_between_requests, seconds_between_writes=self.seconds_between_writes, ) def activateRecordMode(): # pragma no cover (Function useful only when recording new tests, not used during automated tests) BasicTestCase.recordMode = True def activateTokenAuthMode(): # pragma no cover (Function useful only when recording new tests, not used during automated tests) BasicTestCase.tokenAuthMode = True def activateJWTAuthMode(): # pragma no cover (Function useful only when recording new tests, not used during automated tests) BasicTestCase.jwtAuthMode = True def enableRetry(retry): BasicTestCase.retry = retry def setPoolSize(pool_size): BasicTestCase.pool_size = pool_size
20,236
Python
.py
381
45.099738
128
0.621263
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,523
Enterprise.py
PyGithub_PyGithub/tests/Enterprise.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import github from . import Framework # Replay data for this test case is forged, because I don't have access to a real Github Enterprise install class Enterprise(Framework.BasicTestCase): def testHttps(self): g = github.Github(auth=self.login, base_url="https://my.enterprise.com") self.assertListKeyEqual( g.get_user().get_repos(), lambda r: r.name, [ "TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE", ], ) def testHttp(self): g = github.Github(auth=self.login, base_url="http://my.enterprise.com") self.assertListKeyEqual( g.get_user().get_repos(), lambda r: r.name, [ "TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE", ], ) def testUnknownUrlScheme(self): with self.assertRaises(AssertionError) as raisedexp: github.Github(auth=self.login, base_url="foobar://my.enterprise.com") self.assertEqual(raisedexp.exception.args[0], "Unknown URL scheme") def testLongUrl(self): g = github.Github(auth=self.login, base_url="http://my.enterprise.com/path/to/github") repos = g.get_user().get_repos() self.assertListKeyEqual( repos, lambda r: r.name, [ "TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE", ], ) self.assertEqual(repos[0].owner.name, "Vincent Jacques") def testSpecificPort(self): g = github.Github(auth=self.login, base_url="http://my.enterprise.com:8080") self.assertListKeyEqual( g.get_user().get_repos(), lambda r: r.name, [ "TestPyGithub", "django", "PyGithub", "developer.github.com", "acme-public-website", "C4Planner", "Hacking", "vincent-jacques.net", "Contests", "Candidates", "Tests", "DrawTurksHead", "DrawSyntax", "QuadProgMm", "Boost.HierarchicalEnum", "ViDE", ], )
6,234
Python
.py
139
33.892086
107
0.45474
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,524
EnterpriseAdmin.py
PyGithub_PyGithub/tests/EnterpriseAdmin.py
############################ Copyrights and license ############################ # # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 YugoHino <henom06@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class EnterpriseAdmin(Framework.TestCase): def setUp(self): super().setUp() self.enterprise = self.g.get_enterprise("beaver-group") def testAttributes(self): self.assertEqual(self.enterprise.enterprise, "beaver-group") self.assertEqual(self.enterprise.url, "/enterprises/beaver-group") self.assertEqual(repr(self.enterprise), 'Enterprise(enterprise="beaver-group")') def testGetConsumedLicenses(self): consumed_licenses = self.enterprise.get_consumed_licenses() self.assertEqual(consumed_licenses.total_seats_consumed, 102) self.assertEqual(consumed_licenses.total_seats_purchased, 103) def testGetEnterpriseUsers(self): enterprise_users = self.enterprise.get_consumed_licenses().get_users() enterprise_users_list = [ [ users.github_com_login, users.github_com_name, users.enterprise_server_user_ids, users.github_com_user, users.enterprise_server_user, users.visual_studio_subscription_user, users.license_type, users.github_com_profile, users.github_com_member_roles, users.github_com_enterprise_roles, users.github_com_verified_domain_emails, users.github_com_saml_name_id, users.github_com_orgs_with_pending_invites, users.github_com_two_factor_auth, users.enterprise_server_primary_emails, users.visual_studio_license_status, users.visual_studio_subscription_email, users.total_user_accounts, ] for users in enterprise_users ] self.assertEqual(len(enterprise_users_list), 102) self.assertEqual(enterprise_users_list[42][0], "beaver-user043")
3,704
Python
.py
62
51.467742
88
0.503989
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,525
License.py
PyGithub_PyGithub/tests/License.py
############################ Copyrights and license ############################ # # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class License(Framework.TestCase): def setUp(self): super().setUp() self.license = self.g.get_license("mit") def testAttributes(self): self.assertEqual(self.license.key, "mit") self.assertEqual(self.license.name, "MIT License") self.assertEqual( self.license.description, "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.", ) self.assertEqual(self.license.spdx_id, "MIT") self.assertEqual( self.license.body, """MIT License\n\nCopyright (c) [year] [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n""", ) self.assertEqual( self.license.permissions, ["commercial-use", "modifications", "distribution", "private-use"], ) self.assertEqual(self.license.conditions, ["include-copyright"]) self.assertEqual(self.license.limitations, ["liability", "warranty"]) self.assertEqual(self.license.url, "https://api.github.com/licenses/mit") self.assertEqual(self.license.html_url, "http://choosealicense.com/licenses/mit/") self.assertEqual( self.license.implementation, """Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders.""", ) self.assertEqual(repr(self.license), 'License(name="MIT License")')
4,931
Python
.py
57
81.087719
1,109
0.58809
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,526
PullRequest1169.py
PyGithub_PyGithub/tests/PullRequest1169.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PullRequest1169(Framework.TestCase): def setUp(self): super().setUp() ferada_repo = self.g.get_repo("coleslaw-org/coleslaw", lazy=True) self.pull = ferada_repo.get_pull(173) def testReviewApproveWithoutBody(self): r = self.pull.create_review(event="APPROVE") self.assertEqual(r.id, 261942907) self.assertEqual(r.user.login, "Ferada")
3,270
Python
.py
45
70.2
85
0.483359
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,527
Tag.py
PyGithub_PyGithub/tests/Tag.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Tag(Framework.TestCase): def setUp(self): super().setUp() self.tag = self.g.get_user().get_repo("PyGithub").get_tags()[0] def testAttributes(self): self.assertEqual(self.tag.commit.sha, "636e6112deb72277b3bffcc3303cd7e8a7431a5d") self.assertEqual(self.tag.name, "v0.3") self.assertEqual(self.tag.tarball_url, "https://github.com/jacquev6/PyGithub/tarball/v0.3") self.assertEqual(self.tag.zipball_url, "https://github.com/jacquev6/PyGithub/zipball/v0.3") self.assertEqual( repr(self.tag), 'Tag(name="v0.3", commit=Commit(sha="636e6112deb72277b3bffcc3303cd7e8a7431a5d"))', )
3,381
Python
.py
47
68.808511
99
0.492492
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,528
IssueEvent.py
PyGithub_PyGithub/tests/IssueEvent.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Aaron L. Levine <allevin@sandia.gov> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class IssueEvent(Framework.TestCase): def setUp(self): super().setUp() repo = self.g.get_repo("PyGithub/PyGithub", lazy=True) # From Issue #30 self.event_subscribed = repo.get_issues_event(16347479) self.event_assigned = repo.get_issues_event(16347480) self.event_referenced = repo.get_issues_event(16348656) self.event_closed = repo.get_issues_event(16351220) self.event_labeled = repo.get_issues_event(98136337) # From Issue 538 self.event_mentioned = repo.get_issues_event(1009034767) self.event_merged = repo.get_issues_event(1015402964) self.event_review_requested = repo.get_issues_event(1011101309) # From Issue 857 self.event_reopened = repo.get_issues_event(1782463023) self.event_unassigned = repo.get_issues_event(1782463379) self.event_unlabeled = repo.get_issues_event(1782463917) self.event_renamed = repo.get_issues_event(1782472556) self.event_base_ref_changed = repo.get_issues_event(1782915693) self.event_head_ref_deleted = repo.get_issues_event(1782917185) self.event_head_ref_restored = repo.get_issues_event(1782917299) self.event_milestoned = repo.get_issues_event(1783596418) self.event_demilestoned = repo.get_issues_event(1783596452) self.event_locked = repo.get_issues_event(1783596743) self.event_unlocked = repo.get_issues_event(1783596818) self.event_review_dismissed = repo.get_issues_event(1783605084) self.event_review_request_removed = repo.get_issues_event(1783779835) self.event_marked_as_duplicate = repo.get_issues_event(1783779725) self.event_unmarked_as_duplicate = repo.get_issues_event(1789228962) self.event_added_to_project = repo.get_issues_event(1791766828) self.event_moved_columns_in_project = repo.get_issues_event(1791767766) self.event_removed_from_project = repo.get_issues_event(1791768212) # From Issue 866 self.event_converted_note_to_issue = repo.get_issues_event(1791769149) def testEvent_subscribed_Attributes(self): self.assertEqual(self.event_subscribed.actor.login, "jacquev6") self.assertEqual(self.event_subscribed.commit_id, None) self.assertEqual( self.event_subscribed.created_at, datetime(2012, 5, 27, 5, 40, 15, tzinfo=timezone.utc), ) self.assertEqual(self.event_subscribed.event, "subscribed") self.assertEqual(self.event_subscribed.id, 16347479) self.assertEqual(self.event_subscribed.issue.number, 30) self.assertEqual( self.event_subscribed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16347479", ) self.assertEqual(self.event_subscribed.node_id, "MDE1OlN1YnNjcmliZWRFdmVudDE2MzQ3NDc5") self.assertEqual(self.event_subscribed.commit_url, None) self.assertEqual(self.event_subscribed.label, None) self.assertEqual(self.event_subscribed.assignee, None) self.assertEqual(self.event_subscribed.assigner, None) self.assertEqual(self.event_subscribed.review_requester, None) self.assertEqual(self.event_subscribed.requested_reviewer, None) self.assertEqual(self.event_subscribed.milestone, None) self.assertEqual(self.event_subscribed.rename, None) self.assertEqual(self.event_subscribed.dismissed_review, None) self.assertEqual(self.event_subscribed.lock_reason, None) self.assertEqual(repr(self.event_subscribed), "IssueEvent(id=16347479)") def testEvent_assigned_Attributes(self): self.assertEqual(self.event_assigned.actor.login, "jacquev6") self.assertEqual(self.event_assigned.commit_id, None) self.assertEqual( self.event_assigned.created_at, datetime(2012, 5, 27, 5, 40, 15, tzinfo=timezone.utc), ) self.assertEqual(self.event_assigned.event, "assigned") self.assertEqual(self.event_assigned.id, 16347480) self.assertEqual(self.event_assigned.issue.number, 30) self.assertEqual( self.event_assigned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16347480", ) self.assertEqual(self.event_assigned.node_id, "MDEzOkFzc2lnbmVkRXZlbnQxNjM0NzQ4MA==") self.assertEqual(self.event_assigned.commit_url, None) self.assertEqual(self.event_assigned.label, None) self.assertEqual(self.event_assigned.assignee.login, "jacquev6") self.assertEqual(self.event_assigned.assigner.login, "ghost") self.assertEqual(self.event_assigned.review_requester, None) self.assertEqual(self.event_assigned.requested_reviewer, None) self.assertEqual(self.event_assigned.milestone, None) self.assertEqual(self.event_assigned.rename, None) self.assertEqual(self.event_assigned.dismissed_review, None) self.assertEqual(self.event_assigned.lock_reason, None) self.assertEqual(repr(self.event_assigned), "IssueEvent(id=16347480)") def testEvent_referenced_Attributes(self): self.assertEqual(self.event_referenced.actor.login, "jacquev6") self.assertEqual(self.event_referenced.commit_id, "ed866fc43833802ab553e5ff8581c81bb00dd433") self.assertEqual( self.event_referenced.created_at, datetime(2012, 5, 27, 7, 29, 25, tzinfo=timezone.utc), ) self.assertEqual(self.event_referenced.event, "referenced") self.assertEqual(self.event_referenced.id, 16348656) self.assertEqual(self.event_referenced.issue.number, 30) self.assertEqual( self.event_referenced.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16348656", ) self.assertEqual(self.event_referenced.node_id, "MDE1OlJlZmVyZW5jZWRFdmVudDE2MzQ4NjU2") self.assertEqual( self.event_referenced.commit_url, "https://api.github.com/repos/PyGithub/PyGithub/commits/ed866fc43833802ab553e5ff8581c81bb00dd433", ) self.assertEqual(self.event_referenced.label, None) self.assertEqual(self.event_referenced.assignee, None) self.assertEqual(self.event_referenced.assigner, None) self.assertEqual(self.event_referenced.review_requester, None) self.assertEqual(self.event_referenced.requested_reviewer, None) self.assertEqual(self.event_referenced.milestone, None) self.assertEqual(self.event_referenced.rename, None) self.assertEqual(self.event_referenced.dismissed_review, None) self.assertEqual(self.event_referenced.lock_reason, None) self.assertEqual(repr(self.event_referenced), "IssueEvent(id=16348656)") def testEvent_closed_Attributes(self): self.assertEqual(self.event_closed.actor.login, "jacquev6") self.assertEqual(self.event_closed.commit_id, None) self.assertEqual( self.event_closed.created_at, datetime(2012, 5, 27, 11, 4, 25, tzinfo=timezone.utc), ) self.assertEqual(self.event_closed.event, "closed") self.assertEqual(self.event_closed.id, 16351220) self.assertEqual(self.event_closed.issue.number, 30) self.assertEqual( self.event_closed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/16351220", ) self.assertEqual(self.event_closed.node_id, "MDExOkNsb3NlZEV2ZW50MTYzNTEyMjA=") self.assertEqual(self.event_closed.commit_url, None) self.assertEqual(self.event_closed.label, None) self.assertEqual(self.event_closed.assignee, None) self.assertEqual(self.event_closed.assigner, None) self.assertEqual(self.event_closed.review_requester, None) self.assertEqual(self.event_closed.requested_reviewer, None) self.assertEqual(self.event_closed.milestone, None) self.assertEqual(self.event_closed.rename, None) self.assertEqual(self.event_closed.dismissed_review, None) self.assertEqual(self.event_closed.lock_reason, None) self.assertEqual(repr(self.event_closed), "IssueEvent(id=16351220)") def testEvent_labeled_Attributes(self): self.assertEqual(self.event_labeled.actor.login, "jacquev6") self.assertEqual(self.event_labeled.commit_id, None) self.assertEqual( self.event_labeled.created_at, datetime(2014, 3, 2, 18, 55, 10, tzinfo=timezone.utc), ) self.assertEqual(self.event_labeled.event, "labeled") self.assertEqual(self.event_labeled.id, 98136337) self.assertEqual(self.event_labeled.issue.number, 30) self.assertEqual( self.event_labeled.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/98136337", ) self.assertEqual(self.event_labeled.node_id, "MDEyOkxhYmVsZWRFdmVudDk4MTM2MzM3") self.assertEqual(self.event_labeled.commit_url, None) self.assertEqual(self.event_labeled.label.name, "v1") self.assertEqual(self.event_labeled.assignee, None) self.assertEqual(self.event_labeled.assigner, None) self.assertEqual(self.event_labeled.review_requester, None) self.assertEqual(self.event_labeled.requested_reviewer, None) self.assertEqual(self.event_labeled.milestone, None) self.assertEqual(self.event_labeled.rename, None) self.assertEqual(self.event_labeled.dismissed_review, None) self.assertEqual(self.event_labeled.lock_reason, None) self.assertEqual(repr(self.event_labeled), "IssueEvent(id=98136337)") def testEvent_mentioned_Attributes(self): self.assertEqual(self.event_mentioned.actor.login, "jzelinskie") self.assertEqual(self.event_mentioned.commit_id, None) self.assertEqual( self.event_mentioned.created_at, datetime(2017, 3, 21, 17, 30, 14, tzinfo=timezone.utc), ) self.assertEqual(self.event_mentioned.event, "mentioned") self.assertEqual(self.event_mentioned.id, 1009034767) self.assertEqual(self.event_mentioned.issue.number, 538) self.assertEqual( self.event_mentioned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1009034767", ) self.assertEqual(self.event_mentioned.node_id, "MDE0Ok1lbnRpb25lZEV2ZW50MTAwOTAzNDc2Nw==") self.assertEqual(self.event_mentioned.commit_url, None) self.assertEqual(self.event_mentioned.label, None) self.assertEqual(self.event_mentioned.assignee, None) self.assertEqual(self.event_mentioned.assigner, None) self.assertEqual(self.event_mentioned.review_requester, None) self.assertEqual(self.event_mentioned.requested_reviewer, None) self.assertEqual(self.event_mentioned.milestone, None) self.assertEqual(self.event_mentioned.rename, None) self.assertEqual(self.event_mentioned.dismissed_review, None) self.assertEqual(self.event_mentioned.lock_reason, None) self.assertEqual(repr(self.event_mentioned), "IssueEvent(id=1009034767)") def testEvent_merged_Attributes(self): self.assertEqual(self.event_merged.actor.login, "jzelinskie") self.assertEqual(self.event_merged.commit_id, "2525515b094d7425f7018eb5b66171e21c5fbc10") self.assertEqual( self.event_merged.created_at, datetime(2017, 3, 25, 16, 52, 49, tzinfo=timezone.utc), ) self.assertEqual(self.event_merged.event, "merged") self.assertEqual(self.event_merged.id, 1015402964) self.assertEqual(self.event_merged.issue.number, 538) self.assertEqual( self.event_merged.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1015402964", ) self.assertEqual(self.event_merged.node_id, "MDExOk1lcmdlZEV2ZW50MTAxNTQwMjk2NA==") self.assertEqual( self.event_merged.commit_url, "https://api.github.com/repos/PyGithub/PyGithub/commits/2525515b094d7425f7018eb5b66171e21c5fbc10", ) self.assertEqual(self.event_merged.label, None) self.assertEqual(self.event_merged.assignee, None) self.assertEqual(self.event_merged.assigner, None) self.assertEqual(self.event_merged.review_requester, None) self.assertEqual(self.event_merged.requested_reviewer, None) self.assertEqual(self.event_merged.milestone, None) self.assertEqual(self.event_merged.rename, None) self.assertEqual(self.event_merged.dismissed_review, None) self.assertEqual(self.event_merged.lock_reason, None) self.assertEqual(repr(self.event_merged), "IssueEvent(id=1015402964)") def testEvent_review_requested_Attributes(self): self.assertEqual(self.event_review_requested.actor.login, "jzelinskie") self.assertEqual(self.event_review_requested.commit_id, None) self.assertEqual( self.event_review_requested.created_at, datetime(2017, 3, 22, 19, 6, 44, tzinfo=timezone.utc), ) self.assertEqual(self.event_review_requested.event, "review_requested") self.assertEqual(self.event_review_requested.id, 1011101309) self.assertEqual(self.event_review_requested.issue.number, 538) self.assertEqual( self.event_review_requested.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1011101309", ) self.assertEqual( self.event_review_requested.node_id, "MDIwOlJldmlld1JlcXVlc3RlZEV2ZW50MTAxMTEwMTMwOQ==", ) self.assertEqual(self.event_review_requested.commit_url, None) self.assertEqual(self.event_review_requested.label, None) self.assertEqual(self.event_review_requested.assignee, None) self.assertEqual(self.event_review_requested.assigner, None) self.assertEqual(self.event_review_requested.review_requester.login, "jzelinskie") self.assertEqual(self.event_review_requested.requested_reviewer.login, "jzelinskie") self.assertEqual(self.event_review_requested.milestone, None) self.assertEqual(self.event_review_requested.rename, None) self.assertEqual(self.event_review_requested.dismissed_review, None) self.assertEqual(self.event_review_requested.lock_reason, None) self.assertEqual(repr(self.event_review_requested), "IssueEvent(id=1011101309)") def testEvent_reopened_Attributes(self): self.assertEqual(self.event_reopened.actor.login, "sfdye") self.assertEqual(self.event_reopened.commit_id, None) self.assertEqual( self.event_reopened.created_at, datetime(2018, 8, 10, 13, 10, 9, tzinfo=timezone.utc), ) self.assertEqual(self.event_reopened.event, "reopened") self.assertEqual(self.event_reopened.id, 1782463023) self.assertEqual(self.event_reopened.issue.number, 857) self.assertEqual( self.event_reopened.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463023", ) self.assertEqual(self.event_reopened.node_id, "MDEzOlJlb3BlbmVkRXZlbnQxNzgyNDYzMDIz") self.assertEqual(self.event_reopened.commit_url, None) self.assertEqual(self.event_reopened.label, None) self.assertEqual(self.event_reopened.assignee, None) self.assertEqual(self.event_reopened.assigner, None) self.assertEqual(self.event_reopened.review_requester, None) self.assertEqual(self.event_reopened.requested_reviewer, None) self.assertEqual(self.event_reopened.milestone, None) self.assertEqual(self.event_reopened.rename, None) self.assertEqual(self.event_reopened.dismissed_review, None) self.assertEqual(self.event_reopened.lock_reason, None) self.assertEqual(repr(self.event_reopened), "IssueEvent(id=1782463023)") def testEvent_unassigned_Attributes(self): self.assertEqual(self.event_unassigned.actor.login, "sfdye") self.assertEqual(self.event_unassigned.commit_id, None) self.assertEqual( self.event_unassigned.created_at, datetime(2018, 8, 10, 13, 10, 21, tzinfo=timezone.utc), ) self.assertEqual(self.event_unassigned.event, "unassigned") self.assertEqual(self.event_unassigned.id, 1782463379) self.assertEqual(self.event_unassigned.issue.number, 857) self.assertEqual( self.event_unassigned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463379", ) self.assertEqual(self.event_unassigned.node_id, "MDE1OlVuYXNzaWduZWRFdmVudDE3ODI0NjMzNzk=") self.assertEqual(self.event_unassigned.commit_url, None) self.assertEqual(self.event_unassigned.label, None) self.assertEqual(self.event_unassigned.actor.login, "sfdye") self.assertEqual(self.event_unassigned.actor.login, "sfdye") self.assertEqual(self.event_unassigned.review_requester, None) self.assertEqual(self.event_unassigned.requested_reviewer, None) self.assertEqual(self.event_unassigned.milestone, None) self.assertEqual(self.event_unassigned.rename, None) self.assertEqual(self.event_unassigned.dismissed_review, None) self.assertEqual(self.event_unassigned.lock_reason, None) self.assertEqual(repr(self.event_unassigned), "IssueEvent(id=1782463379)") def testEvent_unlabeled_Attributes(self): self.assertEqual(self.event_unlabeled.actor.login, "sfdye") self.assertEqual(self.event_unlabeled.commit_id, None) self.assertEqual( self.event_unlabeled.created_at, datetime(2018, 8, 10, 13, 10, 38, tzinfo=timezone.utc), ) self.assertEqual(self.event_unlabeled.event, "unlabeled") self.assertEqual(self.event_unlabeled.id, 1782463917) self.assertEqual(self.event_unlabeled.issue.number, 857) self.assertEqual( self.event_unlabeled.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782463917", ) self.assertEqual(self.event_unlabeled.node_id, "MDE0OlVubGFiZWxlZEV2ZW50MTc4MjQ2MzkxNw==") self.assertEqual(self.event_unlabeled.commit_url, None) self.assertEqual(self.event_unlabeled.label.name, "improvement") self.assertEqual(self.event_unlabeled.assignee, None) self.assertEqual(self.event_unlabeled.assigner, None) self.assertEqual(self.event_unlabeled.review_requester, None) self.assertEqual(self.event_unlabeled.requested_reviewer, None) self.assertEqual(self.event_unlabeled.milestone, None) self.assertEqual(self.event_unlabeled.rename, None) self.assertEqual(self.event_unlabeled.dismissed_review, None) self.assertEqual(self.event_unlabeled.lock_reason, None) self.assertEqual(repr(self.event_unlabeled), "IssueEvent(id=1782463917)") def testEvent_renamed_Attributes(self): self.assertEqual(self.event_renamed.actor.login, "sfdye") self.assertEqual(self.event_renamed.commit_id, None) self.assertEqual( self.event_renamed.created_at, datetime(2018, 8, 10, 13, 15, 18, tzinfo=timezone.utc), ) self.assertEqual(self.event_renamed.event, "renamed") self.assertEqual(self.event_renamed.id, 1782472556) self.assertEqual(self.event_renamed.issue.number, 857) self.assertEqual( self.event_renamed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782472556", ) self.assertEqual(self.event_renamed.node_id, "MDE3OlJlbmFtZWRUaXRsZUV2ZW50MTc4MjQ3MjU1Ng==") self.assertEqual(self.event_renamed.commit_url, None) self.assertEqual(self.event_renamed.label, None) self.assertEqual(self.event_renamed.assignee, None) self.assertEqual(self.event_renamed.assigner, None) self.assertEqual(self.event_renamed.review_requester, None) self.assertEqual(self.event_renamed.requested_reviewer, None) self.assertEqual(self.event_renamed.milestone, None) self.assertEqual( self.event_renamed.rename, { "to": "Adding new attributes to IssueEvent", "from": "Adding new attributes to IssueEvent Object (DO NOT MERGE - SEE NOTES)", }, ) self.assertEqual(self.event_renamed.dismissed_review, None) self.assertEqual(self.event_renamed.lock_reason, None) self.assertEqual(repr(self.event_renamed), "IssueEvent(id=1782472556)") def testEvent_base_ref_changed_Attributes(self): self.assertEqual(self.event_base_ref_changed.actor.login, "allevin") self.assertEqual(self.event_base_ref_changed.commit_id, None) self.assertEqual( self.event_base_ref_changed.created_at, datetime(2018, 8, 10, 16, 38, 22, tzinfo=timezone.utc), ) self.assertEqual(self.event_base_ref_changed.event, "base_ref_changed") self.assertEqual(self.event_base_ref_changed.id, 1782915693) self.assertEqual(self.event_base_ref_changed.issue.number, 857) self.assertEqual( self.event_base_ref_changed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782915693", ) self.assertEqual( self.event_base_ref_changed.node_id, "MDE5OkJhc2VSZWZDaGFuZ2VkRXZlbnQxNzgyOTE1Njkz", ) self.assertEqual(self.event_base_ref_changed.commit_url, None) self.assertEqual(self.event_base_ref_changed.label, None) self.assertEqual(self.event_base_ref_changed.assignee, None) self.assertEqual(self.event_base_ref_changed.assigner, None) self.assertEqual(self.event_base_ref_changed.review_requester, None) self.assertEqual(self.event_base_ref_changed.requested_reviewer, None) self.assertEqual(self.event_base_ref_changed.milestone, None) self.assertEqual(self.event_head_ref_deleted.rename, None) self.assertEqual(self.event_base_ref_changed.dismissed_review, None) self.assertEqual(self.event_base_ref_changed.lock_reason, None) self.assertEqual(repr(self.event_base_ref_changed), "IssueEvent(id=1782915693)") def testEvent_head_ref_deleted_Attributes(self): self.assertEqual(self.event_head_ref_deleted.actor.login, "allevin") self.assertEqual(self.event_head_ref_deleted.commit_id, None) self.assertEqual( self.event_head_ref_deleted.created_at, datetime(2018, 8, 10, 16, 39, 20, tzinfo=timezone.utc), ) self.assertEqual(self.event_head_ref_deleted.event, "head_ref_deleted") self.assertEqual(self.event_head_ref_deleted.id, 1782917185) self.assertEqual(self.event_head_ref_deleted.issue.number, 857) self.assertEqual( self.event_head_ref_deleted.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782917185", ) self.assertEqual( self.event_head_ref_deleted.node_id, "MDE5OkhlYWRSZWZEZWxldGVkRXZlbnQxNzgyOTE3MTg1", ) self.assertEqual(self.event_head_ref_deleted.commit_url, None) self.assertEqual(self.event_head_ref_deleted.label, None) self.assertEqual(self.event_head_ref_deleted.assignee, None) self.assertEqual(self.event_head_ref_deleted.assigner, None) self.assertEqual(self.event_head_ref_deleted.review_requester, None) self.assertEqual(self.event_head_ref_deleted.requested_reviewer, None) self.assertEqual(self.event_head_ref_deleted.milestone, None) self.assertEqual(self.event_head_ref_deleted.rename, None) self.assertEqual(self.event_head_ref_deleted.dismissed_review, None) self.assertEqual(self.event_head_ref_deleted.lock_reason, None) self.assertEqual(repr(self.event_head_ref_deleted), "IssueEvent(id=1782917185)") def testEvent_head_ref_restored_Attributes(self): self.assertEqual(self.event_head_ref_restored.actor.login, "allevin") self.assertEqual(self.event_head_ref_restored.commit_id, None) self.assertEqual( self.event_head_ref_restored.created_at, datetime(2018, 8, 10, 16, 39, 23, tzinfo=timezone.utc), ) self.assertEqual(self.event_head_ref_restored.event, "head_ref_restored") self.assertEqual(self.event_head_ref_restored.id, 1782917299) self.assertEqual(self.event_head_ref_restored.issue.number, 857) self.assertEqual( self.event_head_ref_restored.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1782917299", ) self.assertEqual( self.event_head_ref_restored.node_id, "MDIwOkhlYWRSZWZSZXN0b3JlZEV2ZW50MTc4MjkxNzI5OQ==", ) self.assertEqual(self.event_head_ref_restored.commit_url, None) self.assertEqual(self.event_head_ref_restored.label, None) self.assertEqual(self.event_head_ref_restored.assignee, None) self.assertEqual(self.event_head_ref_restored.assigner, None) self.assertEqual(self.event_head_ref_restored.review_requester, None) self.assertEqual(self.event_head_ref_restored.requested_reviewer, None) self.assertEqual(self.event_head_ref_restored.milestone, None) self.assertEqual(self.event_head_ref_deleted.rename, None) self.assertEqual(self.event_head_ref_restored.dismissed_review, None) self.assertEqual(self.event_head_ref_deleted.lock_reason, None) self.assertEqual(repr(self.event_head_ref_restored), "IssueEvent(id=1782917299)") def testEvent_milestoned_Attributes(self): self.assertEqual(self.event_milestoned.actor.login, "sfdye") self.assertEqual(self.event_milestoned.commit_id, None) self.assertEqual( self.event_milestoned.created_at, datetime(2018, 8, 11, 0, 46, 19, tzinfo=timezone.utc), ) self.assertEqual(self.event_milestoned.event, "milestoned") self.assertEqual(self.event_milestoned.id, 1783596418) self.assertEqual(self.event_milestoned.issue.number, 857) self.assertEqual( self.event_milestoned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596418", ) self.assertEqual(self.event_milestoned.node_id, "MDE1Ok1pbGVzdG9uZWRFdmVudDE3ODM1OTY0MTg=") self.assertEqual(self.event_milestoned.commit_url, None) self.assertEqual(self.event_milestoned.label, None) self.assertEqual(self.event_milestoned.assignee, None) self.assertEqual(self.event_milestoned.assigner, None) self.assertEqual(self.event_milestoned.review_requester, None) self.assertEqual(self.event_milestoned.requested_reviewer, None) self.assertEqual(self.event_milestoned.milestone.title, "Version 1.25.0") self.assertEqual(self.event_milestoned.rename, None) self.assertEqual(self.event_milestoned.dismissed_review, None) self.assertEqual(self.event_milestoned.lock_reason, None) self.assertEqual(repr(self.event_milestoned), "IssueEvent(id=1783596418)") def testEvent_demilestoned_Attributes(self): self.assertEqual(self.event_demilestoned.actor.login, "sfdye") self.assertEqual(self.event_demilestoned.commit_id, None) self.assertEqual( self.event_demilestoned.created_at, datetime(2018, 8, 11, 0, 46, 22, tzinfo=timezone.utc), ) self.assertEqual(self.event_demilestoned.event, "demilestoned") self.assertEqual(self.event_demilestoned.id, 1783596452) self.assertEqual(self.event_demilestoned.issue.number, 857) self.assertEqual( self.event_demilestoned.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596452", ) self.assertEqual( self.event_demilestoned.node_id, "MDE3OkRlbWlsZXN0b25lZEV2ZW50MTc4MzU5NjQ1Mg==", ) self.assertEqual(self.event_demilestoned.commit_url, None) self.assertEqual(self.event_demilestoned.label, None) self.assertEqual(self.event_demilestoned.assignee, None) self.assertEqual(self.event_demilestoned.assigner, None) self.assertEqual(self.event_demilestoned.review_requester, None) self.assertEqual(self.event_demilestoned.requested_reviewer, None) self.assertEqual(self.event_demilestoned.milestone.title, "Version 1.25.0") self.assertEqual(self.event_demilestoned.rename, None) self.assertEqual(self.event_demilestoned.dismissed_review, None) self.assertEqual(self.event_demilestoned.lock_reason, None) self.assertEqual(repr(self.event_demilestoned), "IssueEvent(id=1783596452)") def testEvent_locked_Attributes(self): self.assertEqual(self.event_locked.actor.login, "PyGithub") self.assertEqual(self.event_locked.commit_id, None) self.assertEqual( self.event_locked.created_at, datetime(2018, 8, 11, 0, 46, 56, tzinfo=timezone.utc), ) self.assertEqual(self.event_locked.event, "locked") self.assertEqual(self.event_locked.id, 1783596743) self.assertEqual(self.event_locked.issue.number, 857) self.assertEqual( self.event_locked.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596743", ) self.assertEqual(self.event_locked.node_id, "MDExOkxvY2tlZEV2ZW50MTc4MzU5Njc0Mw==") self.assertEqual(self.event_locked.commit_url, None) self.assertEqual(self.event_locked.label, None) self.assertEqual(self.event_locked.assignee, None) self.assertEqual(self.event_locked.assigner, None) self.assertEqual(self.event_locked.review_requester, None) self.assertEqual(self.event_locked.requested_reviewer, None) self.assertEqual(self.event_locked.milestone, None) self.assertEqual(self.event_locked.rename, None) self.assertEqual(self.event_locked.dismissed_review, None) self.assertEqual(self.event_locked.lock_reason, "too heated") self.assertEqual(repr(self.event_locked), "IssueEvent(id=1783596743)") def testEvent_unlocked_Attributes(self): self.assertEqual(self.event_unlocked.actor.login, "PyGithub") self.assertEqual(self.event_unlocked.commit_id, None) self.assertEqual( self.event_unlocked.created_at, datetime(2018, 8, 11, 0, 47, 7, tzinfo=timezone.utc), ) self.assertEqual(self.event_unlocked.event, "unlocked") self.assertEqual(self.event_unlocked.id, 1783596818) self.assertEqual(self.event_unlocked.issue.number, 857) self.assertEqual( self.event_unlocked.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783596818", ) self.assertEqual(self.event_unlocked.node_id, "MDEzOlVubG9ja2VkRXZlbnQxNzgzNTk2ODE4") self.assertEqual(self.event_unlocked.commit_url, None) self.assertEqual(self.event_unlocked.label, None) self.assertEqual(self.event_unlocked.assignee, None) self.assertEqual(self.event_unlocked.assigner, None) self.assertEqual(self.event_unlocked.review_requester, None) self.assertEqual(self.event_unlocked.requested_reviewer, None) self.assertEqual(self.event_unlocked.milestone, None) self.assertEqual(self.event_unlocked.rename, None) self.assertEqual(self.event_unlocked.dismissed_review, None) self.assertEqual(self.event_unlocked.lock_reason, None) self.assertEqual(repr(self.event_unlocked), "IssueEvent(id=1783596818)") def testEvent_review_dismissed_Attributes(self): self.assertEqual(self.event_review_dismissed.actor.login, "sfdye") self.assertEqual(self.event_review_dismissed.commit_id, None) self.assertEqual( self.event_review_dismissed.created_at, datetime(2018, 8, 11, 1, 7, 10, tzinfo=timezone.utc), ) self.assertEqual(self.event_review_dismissed.event, "review_dismissed") self.assertEqual(self.event_review_dismissed.id, 1783605084) self.assertEqual(self.event_review_dismissed.issue.number, 857) self.assertEqual( self.event_review_dismissed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783605084", ) self.assertEqual( self.event_review_dismissed.node_id, "MDIwOlJldmlld0Rpc21pc3NlZEV2ZW50MTc4MzYwNTA4NA==", ) self.assertEqual(self.event_review_dismissed.commit_url, None) self.assertEqual(self.event_review_dismissed.label, None) self.assertEqual(self.event_review_dismissed.assignee, None) self.assertEqual(self.event_review_dismissed.assigner, None) self.assertEqual(self.event_review_dismissed.review_requester, None) self.assertEqual(self.event_review_dismissed.requested_reviewer, None) self.assertEqual(self.event_review_dismissed.milestone, None) self.assertEqual(self.event_review_dismissed.rename, None) self.assertEqual( self.event_review_dismissed.dismissed_review, { "dismissal_message": "dismiss", "state": "changes_requested", "review_id": 145431295, }, ) self.assertEqual(self.event_review_dismissed.lock_reason, None) self.assertEqual(repr(self.event_review_dismissed), "IssueEvent(id=1783605084)") def testEvent_review_request_removed_Attributes(self): self.assertEqual(self.event_review_request_removed.actor.login, "sfdye") self.assertEqual(self.event_review_request_removed.commit_id, None) self.assertEqual( self.event_review_request_removed.created_at, datetime(2018, 8, 11, 12, 32, 59, tzinfo=timezone.utc), ) self.assertEqual(self.event_review_request_removed.event, "review_request_removed") self.assertEqual(self.event_review_request_removed.id, 1783779835) self.assertEqual(self.event_review_request_removed.issue.number, 857) self.assertEqual( self.event_review_request_removed.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783779835", ) self.assertEqual( self.event_review_request_removed.node_id, "MDI1OlJldmlld1JlcXVlc3RSZW1vdmVkRXZlbnQxNzgzNzc5ODM1", ) self.assertEqual(self.event_review_request_removed.commit_url, None) self.assertEqual(self.event_review_request_removed.label, None) self.assertEqual(self.event_review_request_removed.assignee, None) self.assertEqual(self.event_review_request_removed.assigner, None) self.assertEqual(self.event_review_request_removed.review_requester.login, "sfdye") self.assertEqual(self.event_review_request_removed.requested_reviewer.login, "jasonwhite") self.assertEqual(self.event_review_request_removed.milestone, None) self.assertEqual(self.event_review_request_removed.rename, None) self.assertEqual(self.event_review_request_removed.dismissed_review, None) self.assertEqual(self.event_review_request_removed.lock_reason, None) self.assertEqual(repr(self.event_review_request_removed), "IssueEvent(id=1783779835)") def testEvent_marked_as_duplicate_Attributes(self): self.assertEqual(self.event_marked_as_duplicate.actor.login, "sfdye") self.assertEqual(self.event_marked_as_duplicate.commit_id, None) self.assertEqual( self.event_marked_as_duplicate.created_at, datetime(2018, 8, 11, 12, 32, 35, tzinfo=timezone.utc), ) self.assertEqual(self.event_marked_as_duplicate.event, "marked_as_duplicate") self.assertEqual(self.event_marked_as_duplicate.id, 1783779725) self.assertEqual(self.event_marked_as_duplicate.issue.number, 857) self.assertEqual( self.event_marked_as_duplicate.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1783779725", ) self.assertEqual( self.event_marked_as_duplicate.node_id, "MDIyOk1hcmtlZEFzRHVwbGljYXRlRXZlbnQxNzgzNzc5NzI1", ) self.assertEqual(self.event_marked_as_duplicate.commit_url, None) self.assertEqual(self.event_marked_as_duplicate.label, None) self.assertEqual(self.event_marked_as_duplicate.assignee, None) self.assertEqual(self.event_marked_as_duplicate.assigner, None) self.assertEqual(self.event_marked_as_duplicate.review_requester, None) self.assertEqual(self.event_marked_as_duplicate.requested_reviewer, None) self.assertEqual(self.event_marked_as_duplicate.milestone, None) self.assertEqual(self.event_marked_as_duplicate.rename, None) self.assertEqual(self.event_marked_as_duplicate.dismissed_review, None) self.assertEqual(self.event_marked_as_duplicate.lock_reason, None) self.assertEqual(repr(self.event_marked_as_duplicate), "IssueEvent(id=1783779725)") def testEvent_unmarked_as_duplicate_Attributes(self): self.assertEqual(self.event_unmarked_as_duplicate.actor.login, "sfdye") self.assertEqual(self.event_unmarked_as_duplicate.commit_id, None) self.assertEqual( self.event_unmarked_as_duplicate.created_at, datetime(2018, 8, 15, 2, 57, 46, tzinfo=timezone.utc), ) self.assertEqual(self.event_unmarked_as_duplicate.event, "unmarked_as_duplicate") self.assertEqual(self.event_unmarked_as_duplicate.id, 1789228962) self.assertEqual(self.event_unmarked_as_duplicate.issue.number, 857) self.assertEqual( self.event_unmarked_as_duplicate.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1789228962", ) self.assertEqual( self.event_unmarked_as_duplicate.node_id, "MDI0OlVubWFya2VkQXNEdXBsaWNhdGVFdmVudDE3ODkyMjg5NjI=", ) self.assertEqual(self.event_unmarked_as_duplicate.commit_url, None) self.assertEqual(self.event_unmarked_as_duplicate.label, None) self.assertEqual(self.event_unmarked_as_duplicate.assignee, None) self.assertEqual(self.event_unmarked_as_duplicate.assigner, None) self.assertEqual(self.event_unmarked_as_duplicate.review_requester, None) self.assertEqual(self.event_unmarked_as_duplicate.requested_reviewer, None) self.assertEqual(self.event_unmarked_as_duplicate.milestone, None) self.assertEqual(self.event_unmarked_as_duplicate.rename, None) self.assertEqual(self.event_unmarked_as_duplicate.dismissed_review, None) self.assertEqual(self.event_unmarked_as_duplicate.lock_reason, None) self.assertEqual(repr(self.event_unmarked_as_duplicate), "IssueEvent(id=1789228962)") def testEvent_added_to_project_Attributes(self): self.assertEqual(self.event_added_to_project.actor.login, "sfdye") self.assertEqual(self.event_added_to_project.commit_id, None) self.assertEqual( self.event_added_to_project.created_at, datetime(2018, 8, 16, 8, 13, 24, tzinfo=timezone.utc), ) self.assertEqual(self.event_added_to_project.event, "added_to_project") self.assertEqual(self.event_added_to_project.id, 1791766828) self.assertEqual(self.event_added_to_project.issue.number, 857) self.assertEqual( self.event_added_to_project.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791766828", ) self.assertEqual( self.event_added_to_project.node_id, "MDE5OkFkZGVkVG9Qcm9qZWN0RXZlbnQxNzkxNzY2ODI4", ) self.assertEqual(self.event_added_to_project.commit_url, None) self.assertEqual(self.event_added_to_project.label, None) self.assertEqual(self.event_added_to_project.assignee, None) self.assertEqual(self.event_added_to_project.assigner, None) self.assertEqual(self.event_added_to_project.review_requester, None) self.assertEqual(self.event_added_to_project.requested_reviewer, None) self.assertEqual(self.event_added_to_project.milestone, None) self.assertEqual(self.event_added_to_project.rename, None) self.assertEqual(self.event_added_to_project.dismissed_review, None) self.assertEqual(self.event_added_to_project.lock_reason, None) self.assertEqual(repr(self.event_added_to_project), "IssueEvent(id=1791766828)") def testEvent_moved_columns_in_project_Attributes(self): self.assertEqual(self.event_moved_columns_in_project.actor.login, "sfdye") self.assertEqual(self.event_moved_columns_in_project.commit_id, None) self.assertEqual( self.event_moved_columns_in_project.created_at, datetime(2018, 8, 16, 8, 13, 55, tzinfo=timezone.utc), ) self.assertEqual(self.event_moved_columns_in_project.event, "moved_columns_in_project") self.assertEqual(self.event_moved_columns_in_project.id, 1791767766) self.assertEqual(self.event_moved_columns_in_project.issue.number, 857) self.assertEqual( self.event_moved_columns_in_project.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791767766", ) self.assertEqual( self.event_moved_columns_in_project.node_id, "MDI2Ok1vdmVkQ29sdW1uc0luUHJvamVjdEV2ZW50MTc5MTc2Nzc2Ng==", ) self.assertEqual(self.event_moved_columns_in_project.commit_url, None) self.assertEqual(self.event_moved_columns_in_project.label, None) self.assertEqual(self.event_moved_columns_in_project.assignee, None) self.assertEqual(self.event_moved_columns_in_project.assigner, None) self.assertEqual(self.event_moved_columns_in_project.review_requester, None) self.assertEqual(self.event_moved_columns_in_project.requested_reviewer, None) self.assertEqual(self.event_moved_columns_in_project.milestone, None) self.assertEqual(self.event_moved_columns_in_project.rename, None) self.assertEqual(self.event_moved_columns_in_project.dismissed_review, None) self.assertEqual(self.event_moved_columns_in_project.lock_reason, None) self.assertEqual(repr(self.event_moved_columns_in_project), "IssueEvent(id=1791767766)") def testEvent_removed_from_project_Attributes(self): self.assertEqual(self.event_removed_from_project.actor.login, "sfdye") self.assertEqual(self.event_removed_from_project.commit_id, None) self.assertEqual( self.event_removed_from_project.created_at, datetime(2018, 8, 16, 8, 14, 8, tzinfo=timezone.utc), ) self.assertEqual(self.event_removed_from_project.event, "removed_from_project") self.assertEqual(self.event_removed_from_project.id, 1791768212) self.assertEqual(self.event_removed_from_project.issue.number, 857) self.assertEqual( self.event_removed_from_project.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791768212", ) self.assertEqual( self.event_removed_from_project.node_id, "MDIzOlJlbW92ZWRGcm9tUHJvamVjdEV2ZW50MTc5MTc2ODIxMg==", ) self.assertEqual(self.event_removed_from_project.commit_url, None) self.assertEqual(self.event_removed_from_project.label, None) self.assertEqual(self.event_removed_from_project.assignee, None) self.assertEqual(self.event_removed_from_project.assigner, None) self.assertEqual(self.event_removed_from_project.review_requester, None) self.assertEqual(self.event_removed_from_project.requested_reviewer, None) self.assertEqual(self.event_removed_from_project.milestone, None) self.assertEqual(self.event_removed_from_project.rename, None) self.assertEqual(self.event_removed_from_project.dismissed_review, None) self.assertEqual(self.event_removed_from_project.lock_reason, None) self.assertEqual(repr(self.event_removed_from_project), "IssueEvent(id=1791768212)") def testEvent_converted_note_to_issue_Attributes(self): self.assertEqual(self.event_converted_note_to_issue.actor.login, "sfdye") self.assertEqual(self.event_converted_note_to_issue.commit_id, None) self.assertEqual( self.event_converted_note_to_issue.created_at, datetime(2018, 8, 16, 8, 14, 34, tzinfo=timezone.utc), ) self.assertEqual(self.event_converted_note_to_issue.event, "converted_note_to_issue") self.assertEqual(self.event_converted_note_to_issue.id, 1791769149) self.assertEqual(self.event_converted_note_to_issue.issue.number, 866) self.assertEqual( self.event_converted_note_to_issue.url, "https://api.github.com/repos/PyGithub/PyGithub/issues/events/1791769149", ) self.assertEqual( self.event_converted_note_to_issue.node_id, "MDI1OkNvbnZlcnRlZE5vdGVUb0lzc3VlRXZlbnQxNzkxNzY5MTQ5", ) self.assertEqual(self.event_converted_note_to_issue.commit_url, None) self.assertEqual(self.event_converted_note_to_issue.label, None) self.assertEqual(self.event_converted_note_to_issue.assignee, None) self.assertEqual(self.event_converted_note_to_issue.assigner, None) self.assertEqual(self.event_converted_note_to_issue.review_requester, None) self.assertEqual(self.event_converted_note_to_issue.requested_reviewer, None) self.assertEqual(self.event_converted_note_to_issue.milestone, None) self.assertEqual(self.event_converted_note_to_issue.rename, None) self.assertEqual(self.event_converted_note_to_issue.dismissed_review, None) self.assertEqual(self.event_converted_note_to_issue.lock_reason, None) self.assertEqual(repr(self.event_converted_note_to_issue), "IssueEvent(id=1791769149)")
49,500
Python
.py
833
50.151261
110
0.689423
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,529
Connection.py
PyGithub_PyGithub/tests/Connection.py
############################ Copyrights and license ############################ # # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Liuyang Wan <tsfdye@gmail.com> # # Copyright 2020 Michał Górny <mgorny@gentoo.org> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import itertools from io import StringIO from unittest.mock import Mock import httpretty # type: ignore import pytest # type: ignore from . import Framework PARAMETERS = itertools.product( [ (Framework.ReplayingHttpConnection, "http"), (Framework.ReplayingHttpsConnection, "https"), ], [ ( '{"body":"BODY TEXT"}', "\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\n{\"body\":\"BODY TEXT\"}\n\n", ), ( '{"body":"BODY\xa0TEXT"}', "\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\n{\"body\":\"BODY\xa0TEXT\"}\n\n", ), ( "BODY TEXT", "\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\nBODY TEXT\n\n", ), ( "BODY\xa0TEXT", "\nGET\napi.github.com\nNone\n/user\n{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}\nNone\n200\n[]\nBODY\xa0TEXT\n\n", ), ], ) class RecordingMockConnection(Framework.RecordingConnection): def __init__(self, file, protocol, host, port, realConnection): self._realConnection = realConnection super().__init__(file, protocol, host, port) @pytest.mark.parametrize( ("replaying_connection_class", "protocol", "response_body", "expected_recording"), list(tuple(itertools.chain(*p)) for p in PARAMETERS), ) def testRecordAndReplay(replaying_connection_class, protocol, response_body, expected_recording): file = StringIO() host = "api.github.com" verb = "GET" url = "/user" headers = {"Authorization": "Basic p4ssw0rd", "User-Agent": "PyGithub/Python"} response = Mock() response.status = 200 response.getheaders.return_value = {} response.read.return_value = response_body connection = Mock() connection.getresponse.return_value = response # write mock response to buffer recording_connection = RecordingMockConnection(file, protocol, host, None, lambda *args, **kwds: connection) recording_connection.request(verb, url, None, headers) recording_connection.getresponse() recording_connection.close() # validate contents of buffer file_value_lines = file.getvalue().split("\n") expected_recording_lines = (protocol + expected_recording).split("\n") assert file_value_lines[:5] == expected_recording_lines[:5] assert eval(file_value_lines[5]) == eval(expected_recording_lines[5]) # dict literal, so keys not in guaranteed order assert file_value_lines[6:] == expected_recording_lines[6:] # required for replay to work as expected httpretty.enable(allow_net_connect=False) # rewind buffer and attempt to replay response from it file.seek(0) replaying_connection = replaying_connection_class(file, host=host, port=None) replaying_connection.request(verb, url, None, headers) replaying_connection.getresponse() # not necessarily required for subsequent tests httpretty.disable() httpretty.reset()
5,472
Python
.py
99
50.535354
185
0.56788
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,530
Milestone.py
PyGithub_PyGithub/tests/Milestone.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Michell Stuttgart <michellstut@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import date, datetime, timezone from . import Framework class Milestone(Framework.TestCase): def setUp(self): super().setUp() self.milestone = self.g.get_user().get_repo("PyGithub").get_milestone(1) def testAttributes(self): self.assertEqual(self.milestone.closed_issues, 2) self.assertEqual( self.milestone.created_at, datetime(2012, 3, 8, 12, 22, 10, tzinfo=timezone.utc), ) self.assertEqual(self.milestone.description, "") self.assertEqual( self.milestone.due_on, datetime(2012, 3, 13, 7, 0, 0, tzinfo=timezone.utc), ) self.assertEqual(self.milestone.id, 93546) self.assertEqual(self.milestone.number, 1) self.assertEqual(self.milestone.open_issues, 0) self.assertEqual(self.milestone.state, "closed") self.assertEqual(self.milestone.title, "Version 0.4") self.assertEqual( self.milestone.url, "https://api.github.com/repos/jacquev6/PyGithub/milestones/1", ) self.assertEqual(self.milestone.creator.login, "jacquev6") self.assertEqual(repr(self.milestone), 'Milestone(title="Version 0.4", number=1)') def testEditWithMinimalParameters(self): self.milestone.edit("Title edited by PyGithub") self.assertEqual(self.milestone.title, "Title edited by PyGithub") def testEditWithAllParameters(self): self.milestone.edit( "Title edited twice by PyGithub", "closed", "Description edited by PyGithub", due_on=date(2012, 6, 16), ) self.assertEqual(self.milestone.title, "Title edited twice by PyGithub") self.assertEqual(self.milestone.state, "closed") self.assertEqual(self.milestone.description, "Description edited by PyGithub") self.assertEqual( self.milestone.due_on, datetime(2012, 6, 16, 7, 0, 0, tzinfo=timezone.utc), ) def testGetLabels(self): self.assertListKeyEqual( self.milestone.get_labels(), lambda lb: lb.name, ["Public interface", "Project management"], ) def testDelete(self): self.milestone.delete()
5,030
Python
.py
87
51.701149
90
0.535063
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,531
PublicKey.py
PyGithub_PyGithub/tests/PublicKey.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Alice GIRARD <bouhahah@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Chris Keating <christopherkeating@gmail.com> # # Copyright 2021 MeggyCal <MeggyCal@users.noreply.github.com> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PublicKey(Framework.TestCase): def testAttributes(self): self.public_key = self.g.get_user().get_repo("PyGithub").get_public_key() self.assertEqual(self.public_key.key, "u5e1Z25+z8pmgVVt5Pd8k0z/sKpVL1MXYtRAecE4vm8=") self.assertEqual(self.public_key.key_id, "568250167242549743") self.assertEqual( repr(self.public_key), 'PublicKey(key_id="568250167242549743", key="u5e1Z25+z8pmgVVt5Pd8k0z/sKpVL1MXYtRAecE4vm8=")', ) def testAttributes_with_int_key_id(self): self.public_key = self.g.get_user().get_repo("PyGithub").get_public_key() self.assertEqual(self.public_key.key, "u5e1Z25+z8pmgVVt5Pd8k0z/sKpVL1MXYtRAecE4vm8=") self.assertEqual(self.public_key.key_id, 568250167242549743) self.assertEqual( repr(self.public_key), 'PublicKey(key_id=568250167242549743, key="u5e1Z25+z8pmgVVt5Pd8k0z/sKpVL1MXYtRAecE4vm8=")', )
3,906
Python
.py
54
68.740741
105
0.518711
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,532
ConditionalRequestUpdate.py
PyGithub_PyGithub/tests/ConditionalRequestUpdate.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 AKFish <akfish@gmail.com> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2015 Uriel Corfa <uriel@corfa.fr> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class ConditionalRequestUpdate(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("akfish/PyGithub", lazy=False) def testDidNotUpdate(self): self.assertFalse(self.repo.update(), msg="The repo is not changed. But update() != False") def testDidUpdate(self): self.assertTrue( self.repo.update(), msg="The repo should be changed by now. But update() != True", ) def testUpdateObjectWithoutEtag(self): r = self.g.get_repo("jacquev6/PyGithub", lazy=False) self.assertTrue(r.update())
3,395
Python
.py
49
66.204082
98
0.482036
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,533
Issue278.py
PyGithub_PyGithub/tests/Issue278.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework # Replay data forged by adding nulls to PaginatedList.setUp.txt and PaginatedList.testIteration.txt class Issue278(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user("openframeworks").get_repo("openFrameworks") self.list = self.repo.get_issues() def testIteration(self): self.assertEqual(len(list(self.list)), 333)
2,930
Python
.py
40
71.15
99
0.474705
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,534
Deployment.py
PyGithub_PyGithub/tests/Deployment.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Nevins <nevins-b@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Deployment(Framework.TestCase): def setUp(self): super().setUp() self.deployment = self.g.get_user().get_repo("PyGithub").get_deployment(263877258) def testAttributes(self): self.assertEqual(self.deployment.id, 263877258) self.assertEqual( self.deployment.url, "https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258", ) self.assertEqual(self.deployment.ref, "743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5") self.assertEqual(self.deployment.sha, "743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5") self.assertEqual(self.deployment.task, "deploy") self.assertEqual(self.deployment.payload, {"test": True}) self.assertEqual(self.deployment.original_environment, "test") self.assertEqual(self.deployment.environment, "test") self.assertEqual(self.deployment.description, "Test deployment") self.assertEqual(self.deployment.creator.login, "jacquev6") created_at = datetime(2020, 8, 26, 11, 44, 53, tzinfo=timezone.utc) self.assertEqual(self.deployment.created_at, created_at) self.assertEqual(self.deployment.updated_at, created_at) self.assertEqual(self.deployment.transient_environment, True) self.assertEqual(self.deployment.production_environment, False) self.assertEqual( self.deployment.statuses_url, "https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses", ) self.assertEqual( self.deployment.repository_url, "https://api.github.com/repos/jacquev6/PyGithub", ) self.assertEqual( repr(self.deployment), 'Deployment(url="https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258", id=263877258)', )
4,747
Python
.py
72
60.75
115
0.549251
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,535
GithubRetry.py
PyGithub_PyGithub/tests/GithubRetry.py
############################ Copyrights and license ############################ # # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Patryk Szulczyk <therealsoulcheck@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import contextlib import logging import sys import unittest from datetime import datetime from io import BytesIO from unittest import mock import urllib3.response from urllib3 import Retry import github from github.GithubRetry import DEFAULT_SECONDARY_RATE_WAIT from . import Requester PrimaryRateLimitMessage = Requester.Requester.PrimaryRateLimitErrors[0] PrimaryRateLimitJson = ( '{"message":"' + PrimaryRateLimitMessage + '","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}' ) SecondaryRateLimitMessage = Requester.Requester.SecondaryRateLimitErrors[0] SecondaryRateLimitJson = ( '{"message":"' + SecondaryRateLimitMessage + '","documentation_url": "https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#secondary-rate-limits"}' ) class GithubRetry(unittest.TestCase): def get_test_increment_func(self, expected_rate_limit_error): is_primary = expected_rate_limit_error == PrimaryRateLimitMessage def test_increment( retry, response, expected_total=None, expected_backoff=None, expected_retry_backoff=None, expect_retry_error=False, has_reset=False, ): # fmt: off self.assertTrue( expected_total is not None and expected_backoff is not None and not expect_retry_error or # noqa: W504 expected_total is None and expected_backoff is None and expect_retry_error ) # fmt: on orig_retry = retry with mock.patch.object(retry, "_GithubRetry__log") as log: if expect_retry_error: with self.assertRaises(urllib3.exceptions.MaxRetryError): retry.increment("TEST", "URL", response) retry = None else: retry = retry.increment("TEST", "URL", response) self.assertEqual(expected_total, retry.total) self.assertEqual( expected_backoff if expected_retry_backoff is None else expected_retry_backoff, retry.get_backoff_time(), ) self.assertEqual(orig_retry.secondary_rate_wait, retry.secondary_rate_wait) # fmt: off log.assert_has_calls( [ mock.call(20, "Request TEST URL failed with 403: None"), mock.call(10, f"Response body indicates retry-able {'primary' if is_primary else 'secondary'} rate limit error: {expected_rate_limit_error}"), ] + ([ mock.call(10, "Reset occurs in 0:00:12 (1644768012 / 2022-02-13 16:00:12+00:00)") ] if has_reset else []) + ([ mock.call(10, f"Retry backoff of {expected_retry_backoff}s exceeds required rate limit backoff of {expected_backoff}s") ] if expected_retry_backoff and expected_backoff > 0 else []) + ([ mock.call(20, f"Setting next backoff to {expected_backoff if expected_retry_backoff is None else expected_retry_backoff}s") ] if not expect_retry_error else []), any_order=False, ) # fmt: on return retry return test_increment @staticmethod def response_func(content, reset=None): def response(): stream = BytesIO(content.encode("utf8")) return urllib3.response.HTTPResponse( body=stream, preload_content=False, headers={"X-RateLimit-Reset": f"{reset}"} if reset else {}, status=403, ) return response @contextlib.contextmanager def mock_retry_now(self, now): if sys.version_info[0] > 3 or sys.version_info[0] == 3 and sys.version_info[1] >= 11: attr = "github.GithubRetry.GithubRetry._GithubRetry__datetime" else: attr = "github.GithubRetry._GithubRetry__datetime" with mock.patch(attr) as dt: dt.now = lambda tz=None: datetime.fromtimestamp(now, tz=tz) dt.fromtimestamp = datetime.fromtimestamp yield def test_primary_rate_error_with_reset(self): retry = github.GithubRetry(total=3) response = self.response_func(PrimaryRateLimitJson, 1644768012) test_increment = self.get_test_increment_func(PrimaryRateLimitMessage) # test 12 seconds before reset, note backoff will be 12+1 second with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=2, expected_backoff=12 + 1, has_reset=True, ) with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=1, expected_backoff=12 + 1, has_reset=True, ) # test 2 seconds after reset, no backoff expected with self.mock_retry_now(1644768014): retry = test_increment(retry, response(), expected_total=0, expected_backoff=0) test_increment(retry, response(), expect_retry_error=True) def test_primary_rate_error_with_reset_and_exponential_backoff(self): retry = github.GithubRetry(total=3, backoff_factor=10) response = self.response_func(PrimaryRateLimitJson, 1644768012) test_increment = self.get_test_increment_func(PrimaryRateLimitMessage) # test 12 seconds before reset, note backoff will be 12+1 second with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=2, expected_backoff=12 + 1, has_reset=True, ) with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=1, expected_backoff=12 + 1, expected_retry_backoff=20, has_reset=True, ) # test 2 seconds after reset, no backoff expected with self.mock_retry_now(1644768014): retry = test_increment( retry, response(), expected_total=0, expected_backoff=-2, expected_retry_backoff=40, ) test_increment(retry, response(), expect_retry_error=True) def test_primary_rate_error_without_reset(self): retry = github.GithubRetry(total=3) response = self.response_func(PrimaryRateLimitJson, reset=None) test_increment = self.get_test_increment_func(PrimaryRateLimitMessage) # test without reset retry = test_increment(retry, response(), expected_total=2, expected_backoff=0) retry = test_increment(retry, response(), expected_total=1, expected_backoff=0) retry = test_increment(retry, response(), expected_total=0, expected_backoff=0) test_increment(retry, response(), expect_retry_error=True) def test_primary_rate_error_without_reset_with_exponential_backoff(self): retry = github.GithubRetry(total=3, backoff_factor=10) response = self.response_func(PrimaryRateLimitJson, reset=None) test_increment = self.get_test_increment_func(PrimaryRateLimitMessage) # test without reset retry = test_increment( retry, response(), expected_total=2, expected_backoff=0, expected_retry_backoff=0, ) retry = test_increment( retry, response(), expected_total=1, expected_backoff=0, expected_retry_backoff=20, ) retry = test_increment( retry, response(), expected_total=0, expected_backoff=0, expected_retry_backoff=40, ) test_increment(retry, response(), expect_retry_error=True) def test_secondary_rate_error_with_reset(self): retry = github.GithubRetry(total=3) response = self.response_func(SecondaryRateLimitJson, 1644768012) test_increment = self.get_test_increment_func(SecondaryRateLimitMessage) # test 12 seconds before reset, expect secondary wait seconds of 60 with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=2, expected_backoff=60, has_reset=False, ) with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=1, expected_backoff=60, has_reset=False, ) # test 2 seconds after reset, still expect secondary wait seconds of 60 with self.mock_retry_now(1644768014): retry = test_increment(retry, response(), expected_total=0, expected_backoff=60) test_increment(retry, response(), expect_retry_error=True) def test_secondary_rate_error_with_reset_and_exponential_backoff(self): retry = github.GithubRetry(total=3, backoff_factor=10, secondary_rate_wait=15) response = self.response_func(SecondaryRateLimitJson, 1644768012) test_increment = self.get_test_increment_func(SecondaryRateLimitMessage) # test 12 seconds before reset, expect secondary wait seconds of 15 with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=2, expected_backoff=15, has_reset=False, ) with self.mock_retry_now(1644768000): retry = test_increment( retry, response(), expected_total=1, expected_backoff=15, expected_retry_backoff=20, has_reset=False, ) # test 2 seconds after reset, exponential backoff exceeds secondary wait seconds of 15 with self.mock_retry_now(1644768014): retry = test_increment( retry, response(), expected_total=0, expected_backoff=15, expected_retry_backoff=40, ) test_increment(retry, response(), expect_retry_error=True) def test_secondary_rate_error_without_reset(self): retry = github.GithubRetry(total=3) response = self.response_func(SecondaryRateLimitJson, reset=None) test_increment = self.get_test_increment_func(SecondaryRateLimitMessage) retry = test_increment( retry, response(), expected_total=2, expected_backoff=DEFAULT_SECONDARY_RATE_WAIT, ) retry = test_increment( retry, response(), expected_total=1, expected_backoff=DEFAULT_SECONDARY_RATE_WAIT, ) retry = test_increment( retry, response(), expected_total=0, expected_backoff=DEFAULT_SECONDARY_RATE_WAIT, ) test_increment(retry, response(), expect_retry_error=True) def test_secondary_rate_error_without_reset_with_exponential_backoff(self): retry = github.GithubRetry(total=3, backoff_factor=10, secondary_rate_wait=5) response = self.response_func(SecondaryRateLimitJson, reset=None) test_increment = self.get_test_increment_func(SecondaryRateLimitMessage) retry = test_increment(retry, response(), expected_total=2, expected_backoff=5) retry = test_increment( retry, response(), expected_total=1, expected_backoff=5, expected_retry_backoff=20, ) retry = test_increment( retry, response(), expected_total=0, expected_backoff=5, expected_retry_backoff=40, ) test_increment(retry, response(), expect_retry_error=True) def do_test_default_behaviour(self, retry, response): expected = Retry(total=retry.total, backoff_factor=retry.backoff_factor) self.assertTrue(retry.total > 0) for _ in range(retry.total): retry = retry.increment("TEST", "URL", response) expected = expected.increment("TEST", "URL", response) self.assertEqual(expected.total, retry.total) self.assertEqual(expected.get_backoff_time(), retry.get_backoff_time()) with self.assertRaises(urllib3.exceptions.MaxRetryError): retry.increment("TEST", "URL", response) with self.assertRaises(urllib3.exceptions.MaxRetryError): expected.increment("TEST", "URL", response) def test_403_with_retry_after(self): retry = github.GithubRetry(total=3) response = urllib3.response.HTTPResponse(status=403, headers={"Retry-After": "123"}) self.do_test_default_behaviour(retry, response) def test_403_with_non_retryable_error(self): retry = github.GithubRetry(total=3) with self.assertRaises(github.BadUserAgentException): retry.increment( "TEST", "URL", self.response_func('{"message":"Missing or invalid User Agent string."}')(), ) def test_misc_response(self): retry = github.GithubRetry(total=3) response = urllib3.response.HTTPResponse() self.do_test_default_behaviour(retry, response) def test_misc_response_exponential_backoff(self): retry = github.GithubRetry(total=3, backoff_factor=10) response = urllib3.response.HTTPResponse() self.do_test_default_behaviour(retry, response) def test_error_in_get_content(self): retry = github.GithubRetry(total=3) response = urllib3.response.HTTPResponse(status=403, reason="NOT GOOD") with mock.patch.object(retry, "_GithubRetry__log") as log: with self.assertRaises(github.GithubException) as exp: retry.increment("TEST", "URL", response) self.assertEqual(403, exp.exception.status) self.assertEqual("NOT GOOD", exp.exception.data) self.assertEqual({}, exp.exception.headers) self.assertIsInstance(exp.exception.__cause__, RuntimeError) self.assertEqual(("Failed to inspect response message",), exp.exception.__cause__.args) self.assertIsInstance(exp.exception.__cause__.__cause__, ValueError) self.assertEqual( ("Unable to determine whether fp is closed.",), exp.exception.__cause__.__cause__.args, ) log.assert_called_once_with(logging.INFO, "Request TEST URL failed with 403: NOT GOOD")
17,127
Python
.py
359
36.303621
166
0.579272
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,536
CommitStatus.py
PyGithub_PyGithub/tests/CommitStatus.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Martijn Koster <mak-github@greenhills.co.uk> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class CommitStatus(Framework.TestCase): def setUp(self): super().setUp() self.statuses = list( self.g.get_user().get_repo("PyGithub").get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a").get_statuses() ) def testAttributes(self): self.assertEqual( self.statuses[0].created_at, datetime(2012, 9, 8, 11, 30, 56, tzinfo=timezone.utc), ) self.assertEqual( self.statuses[0].updated_at, datetime(2012, 9, 8, 11, 30, 56, tzinfo=timezone.utc), ) self.assertEqual(self.statuses[0].creator.login, "jacquev6") self.assertEqual(self.statuses[0].description, "Status successfuly created by PyGithub") self.assertEqual(self.statuses[1].description, None) self.assertEqual(self.statuses[0].id, 277040) self.assertEqual(self.statuses[0].state, "success") self.assertEqual(self.statuses[1].state, "pending") self.assertEqual(self.statuses[0].context, "build") self.assertEqual( self.statuses[0].target_url, "https://github.com/jacquev6/PyGithub/issues/67", ) self.assertEqual(self.statuses[1].target_url, None) self.assertEqual( repr(self.statuses[0]), 'CommitStatus(state="success", id=277040, context="build")', )
4,278
Python
.py
68
57.897059
120
0.510583
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,537
Issue937.py
PyGithub_PyGithub/tests/Issue937.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Vinay Hegde <hegde.vi@husky.neu.edu> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue937(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user() self.repo = self.user.get_repo("PyGithub") def testCollaboratorsAffiliation(self): collaborators = self.repo.get_collaborators(affiliation="direct") self.assertListKeyEqual(collaborators, lambda u: u.login, ["hegde5"]) with self.assertRaises(AssertionError): self.repo.get_collaborators(affiliation="invalid_option")
3,109
Python
.py
43
69.627907
85
0.480078
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,538
GitRelease.py
PyGithub_PyGithub/tests/GitRelease.py
############################ Copyrights and license ############################ # # # Copyright 2015 Ed Holland <eholland@alertlogic.com> # # Copyright 2016 Benjamin Whitney <benjamin.whitney@ironnetcybersecurity.com> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Andrew Smith <espadav8@gmail.com> # # Copyright 2018 Daniel Kesler <kesler.daniel@gmail.com> # # Copyright 2018 Ggicci <ggicci.t@gmail.com> # # Copyright 2018 Kuba <jakub.glapa@adspired.com> # # Copyright 2018 Maarten Fonville <mfonville@users.noreply.github.com> # # Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 edquist <edquist@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Jesse Li <jesse.li2002@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Sam Morgan <sama4mail@gmail.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Mikhail f. Shiryaev <mr.felixoid@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import os import zipfile from datetime import datetime, timezone from github import GithubException from . import Framework class FileLikeStub: def __init__(self): self.dat = b"I wanted to come up with some clever phrase or something here to test with but my mind is blank." self.file_length = len(self.dat) self.index = 0 def read(self, size=-1): if size < 0 or size is None: start = self.index self.index = self.file_length return self.dat[start:] else: start = self.index end = start + size self.index = end return self.dat[start:end] repo_name = "RepoTest" user = "rickrickston123" release_id = 28524234 author_id = 64711998 tag = "v1.0" create_date = datetime(2020, 7, 12, 7, 34, 42, tzinfo=timezone.utc) publish_date = datetime(2020, 7, 14, 0, 58, 20, tzinfo=timezone.utc) class GitRelease(Framework.TestCase): def setUp(self): super().setUp() self.new_tag = "v1.25.2" # Used for new releases self.content_path = "content.txt" self.artifact_path = "archive.zip" with open(self.content_path, "w") as zip_content: zip_content.write("Pedro for president.") artifact = zipfile.ZipFile(self.artifact_path, "w") artifact.write(self.content_path) artifact.close() self.repo = self.g.get_user(user).get_repo(repo_name) self.release = self.repo.get_release(release_id) def tearDown(self): if os.path.exists(self.content_path): os.remove(self.content_path) if os.path.exists(self.artifact_path): os.remove(self.artifact_path) super().tearDown() def setUpNewRelease(self): repo = self.repo commit_sha = repo.get_commits()[0].sha # Just need any commit self.new_release = repo.create_git_tag_and_release( self.new_tag, "tag message", "release title", "release message", commit_sha, "commit", ) self.new_release_id = self.new_release.id def tearDownNewRelease(self): try: new_release = self.repo.get_release(self.new_release_id) new_release.delete_release() except GithubException: pass # Already deleted def testAttributes(self): release = self.release self.assertEqual(release.id, release_id) self.assertEqual(release.tag_name, tag) self.assertEqual(release.target_commitish, "master") self.assertEqual( release.upload_url, "https://uploads.github.com/repos/{}/{}/releases/{}/assets{{?name,label}}".format( user, repo_name, release_id ), ) self.assertEqual(release.body, "Body") self.assertEqual(release.title, "Test") self.assertFalse(release.draft) self.assertFalse(release.prerelease) self.assertEqual( release.url, f"https://api.github.com/repos/{user}/{repo_name}/releases/{release_id}", ) self.assertEqual(release.author._rawData["login"], user) self.assertEqual(release.author.login, user) self.assertEqual(release.author.id, author_id) self.assertEqual(release.author.type, "User") self.assertEqual( release.html_url, f"https://github.com/{user}/{repo_name}/releases/tag/{tag}", ) self.assertEqual(release.created_at, create_date) self.assertEqual(release.published_at, publish_date) self.assertEqual( release.tarball_url, f"https://api.github.com/repos/{user}/{repo_name}/tarball/{tag}", ) self.assertEqual( release.zipball_url, f"https://api.github.com/repos/{user}/{repo_name}/zipball/{tag}", ) self.assertEqual(repr(release), 'GitRelease(title="Test")') self.assertEqual(len(release.assets), 1) self.assertEqual( repr(release.assets[0]), 'GitReleaseAsset(url="https://api.github.com/repos/' f'{user}/{repo_name}/releases/assets/{release.raw_data["assets"][0]["id"]}")', ) def testGetRelease(self): release_by_id = self.release release_by_tag = self.repo.get_release(tag) self.assertEqual(release_by_id, release_by_tag) def testGetLatestRelease(self): latest_release = self.repo.get_latest_release() self.assertEqual(latest_release.tag_name, tag) def testGetAssets(self): repo = self.repo release = self.release self.assertEqual(release.id, release_id) asset_list = [x for x in release.get_assets()] self.assertTrue(asset_list is not None) self.assertEqual(len(asset_list), 1) asset_id = asset_list[0].id asset = repo.get_release_asset(asset_id) self.assertTrue(asset is not None) self.assertEqual(asset.id, asset_id) def testDelete(self): self.setUpNewRelease() self.new_release.delete_release() self.tearDownNewRelease() def testUpdate(self): self.setUpNewRelease() release = self.new_release new_release = release.update_release("Updated Test", "Updated Body") self.assertEqual(new_release.title, "Updated Test") self.assertEqual(new_release.body, "Updated Body") self.tearDownNewRelease() def testUploadAsset(self): self.setUpNewRelease() release = self.new_release self.assertEqual(release.id, self.new_release_id) release.upload_asset(self.artifact_path, "unit test artifact", "application/zip") self.tearDownNewRelease() def testUploadAssetWithName(self): self.setUpNewRelease() release = self.new_release r = release.upload_asset(self.artifact_path, name="foobar.zip", content_type="application/zip") self.assertEqual(r.name, "foobar.zip") self.tearDownNewRelease() def testCreateGitTagAndRelease(self): self.setUpNewRelease() # Creation code already done in setup, so we'll just test what's already here. release = self.new_release self.assertEqual(release.tag_name, self.new_tag) self.assertEqual(release.body, "release message") self.assertEqual(release.title, "release title") self.assertEqual(release.author._rawData["login"], user) self.assertEqual( release.html_url, f"https://github.com/{user}/{repo_name}/releases/tag/{self.new_tag}", ) self.tearDownNewRelease() def testUploadAssetFromMemory(self): self.setUpNewRelease() release = self.new_release content_size = os.path.getsize(self.content_path) with open(self.content_path, "rb") as f: release.upload_asset_from_memory( f, content_size, name="file_name", content_type="text/plain", label="unit test artifact", ) asset_list = [x for x in release.get_assets()] self.assertTrue(asset_list is not None) self.assertEqual(len(asset_list), 1) self.tearDownNewRelease() def testUploadAssetFileLike(self): self.setUpNewRelease() file_like = FileLikeStub() release = self.new_release release.upload_asset_from_memory( file_like, file_like.file_length, name="file_like", content_type="text/plain", label="another unit test artifact", ) asset_list = [x for x in release.get_assets()] self.assertTrue(asset_list is not None) self.assertEqual(len(asset_list), 1) self.tearDownNewRelease()
11,435
Python
.py
237
40.455696
118
0.574946
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,539
Project1434.py
PyGithub_PyGithub/tests/Project1434.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Anuj Bansal <bansalanuj1996@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Project1434(Framework.TestCase): def setUp(self): super().setUp() def testDelete(self): project = self.g.get_project(4102095) project.delete() def testEditWithoutParameters(self): project = self.g.get_project(4101939) old_name = project.name project.edit() self.assertEqual(project.name, old_name) def testEditWithAllParameters(self): project = self.g.get_project(4101939) project.edit("New Name", "New Body", "open") self.assertEqual(project.name, "New Name") self.assertEqual(project.body, "New Body") self.assertEqual(project.state, "open")
3,619
Python
.py
54
63.722222
85
0.495637
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,540
Equality.py
PyGithub_PyGithub/tests/Equality.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 AKFish <akfish@gmail.com> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Equality(Framework.TestCase): def testUserEquality(self): u1 = self.g.get_user("jacquev6") u2 = self.g.get_user("jacquev6") self.assertEqual(u1, u2) self.assertEqual(hash(u1), hash(u2)) def testUserDifference(self): u1 = self.g.get_user("jacquev6") u2 = self.g.get_user("OddBloke") self.assertNotEqual(u1, u2) self.assertNotEqual(hash(u1), hash(u2)) def testBranchEquality(self): # Erf, equality of NonCompletableGithubObjects will be difficult to implement # because even their _rawData can differ. (Here, the avatar_url is not equal) # (CompletableGithubObjects are compared by their API url, which is a good key) r = self.g.get_user().get_repo("PyGithub") b1 = r.get_branch("develop") b2 = r.get_branch("develop") self.assertNotEqual(b1._rawData, b2._rawData)
3,608
Python
.py
53
64.490566
87
0.49493
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,541
Issue50.py
PyGithub_PyGithub/tests/Issue50.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue50(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issues/50 def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("PyGithub") self.issue = self.repo.get_issue(50) self.labelName = "Label with spaces and strange characters (&*#$)" def testCreateLabel(self): label = self.repo.create_label(self.labelName, "ffff00") self.assertEqual(label.name, self.labelName) def testGetLabel(self): label = self.repo.get_label(self.labelName) self.assertEqual(label.name, self.labelName) def testGetLabels(self): self.assertListKeyEqual( self.repo.get_labels(), lambda lb: lb.name, [ "Refactoring", "Public interface", "Functionalities", "Project management", "Bug", "Question", "RequestedByUser", self.labelName, ], ) def testAddLabelToIssue(self): self.issue.add_to_labels(self.repo.get_label(self.labelName)) def testRemoveLabelFromIssue(self): self.issue.remove_from_labels(self.repo.get_label(self.labelName)) def testSetIssueLabels(self): self.issue.set_labels( self.repo.get_label("Bug"), self.repo.get_label("RequestedByUser"), self.repo.get_label(self.labelName), ) def testIssueLabels(self): self.assertListKeyEqual( self.issue.labels, lambda lb: lb.name, ["Bug", self.labelName, "RequestedByUser"], ) def testIssueGetLabels(self): self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", self.labelName, "RequestedByUser"], ) def testGetIssuesWithLabel(self): self.assertListKeyEqual( self.repo.get_issues(labels=[self.repo.get_label(self.labelName)]), lambda i: i.number, [52, 50], ) def testCreateIssueWithLabel(self): issue = self.repo.create_issue( "Issue created by PyGithub to test issue #50", labels=[self.repo.get_label(self.labelName)], ) self.assertListKeyEqual(issue.labels, lambda lb: lb.name, [self.labelName]) self.assertEqual(issue.number, 52)
5,032
Python
.py
95
45.726316
85
0.517872
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,542
Gist.py
PyGithub_PyGithub/tests/Gist.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Jon Dufresne <jon.dufresne@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone import github from . import Framework class Gist(Framework.TestCase): def testAttributes(self): gist = self.g.get_gist("6296732") self.assertEqual(gist.comments, 0) self.assertEqual( gist.created_at, datetime(2013, 8, 21, 16, 28, 24, tzinfo=timezone.utc), ) self.assertEqual(gist.description, "Github API") self.assertEqual(list(gist.files.keys()), ["GithubAPI.lua"]) self.assertEqual(gist.files["GithubAPI.lua"].size, 21229) self.assertEqual(gist.files["GithubAPI.lua"].filename, "GithubAPI.lua") self.assertEqual(gist.files["GithubAPI.lua"].language, "Lua") self.assertEqual(gist.files["GithubAPI.lua"].content[:10], "-- GithubA") self.assertEqual( gist.files["GithubAPI.lua"].raw_url, "https://gist.githubusercontent.com/jacquev6/6296732/raw/88aafa25fb28e17013054a117354a37f0d78963c/GithubAPI.lua", ) self.assertEqual(gist.forks, []) self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git") self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git") self.assertEqual(len(gist.history), 1) self.assertEqual(gist.history[0].change_status.additions, 793) self.assertEqual(gist.history[0].change_status.deletions, 0) self.assertEqual(gist.history[0].change_status.total, 793) self.assertEqual( gist.history[0].committed_at, datetime(2013, 8, 21, 16, 12, 27, tzinfo=timezone.utc), ) self.assertEqual( gist.history[0].url, "https://api.github.com/gists/6296732/c464aecd7fea16684e935607eeea7ae4f8caa0e2", ) self.assertEqual(gist.history[0].user, None) self.assertEqual(gist.history[0].owner.login, "jacquev6") self.assertEqual(gist.history[0].version, "c464aecd7fea16684e935607eeea7ae4f8caa0e2") self.assertEqual(gist.html_url, "https://gist.github.com/6296732") self.assertEqual(gist.id, "6296732") self.assertTrue(gist.public) self.assertEqual( gist.updated_at, datetime(2013, 8, 21, 16, 28, 24, tzinfo=timezone.utc), ) self.assertEqual(gist.url, "https://api.github.com/gists/6296732") self.assertEqual(gist.user, None) self.assertEqual(gist.owner.login, "jacquev6") self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git") self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git") self.assertEqual(gist.html_url, "https://gist.github.com/6296732") self.assertEqual(gist.url, "https://api.github.com/gists/6296732") self.assertEqual(repr(gist), 'Gist(id="6296732")') self.assertEqual(repr(gist.files["GithubAPI.lua"]), 'GistFile(filename="GithubAPI.lua")') def testEditWithoutParameters(self): gist = self.g.get_gist("2729810") gist.edit() self.assertEqual(gist.description, "Gist created by PyGithub") self.assertEqual( gist.updated_at, datetime(2012, 5, 19, 7, 0, 58, tzinfo=timezone.utc), ) def testEditWithAllParameters(self): gist = self.g.get_gist("2729810") gist.edit( "Description edited by PyGithub", {"barbaz.txt": github.InputFileContent("File also created by PyGithub")}, ) self.assertEqual(gist.description, "Description edited by PyGithub") self.assertEqual( gist.updated_at, datetime(2012, 5, 19, 7, 6, 10, tzinfo=timezone.utc), ) self.assertEqual(set(gist.files.keys()), {"foobar.txt", "barbaz.txt"}) def testDeleteFile(self): gist = self.g.get_gist("5339374") self.assertEqual(sorted(gist.files.keys()), ["bar.txt", "foo.txt"]) gist.edit(files={"foo.txt": None}) self.assertEqual(list(gist.files.keys()), ["bar.txt"]) def testRenameFile(self): gist = self.g.get_gist("5339374") self.assertEqual(list(gist.files.keys()), ["bar.txt"]) gist.edit(files={"bar.txt": github.InputFileContent(gist.files["bar.txt"].content, new_name="baz.txt")}) self.assertEqual(list(gist.files.keys()), ["baz.txt"]) def testCreateComment(self): gist = self.g.get_gist("2729810") comment = gist.create_comment("Comment created by PyGithub") self.assertEqual(comment.id, 323629) def testGetComments(self): gist = self.g.get_gist("2729810") self.assertListKeyEqual(gist.get_comments(), lambda c: c.id, [323637]) def testStarring(self): gist = self.g.get_gist("2729810") self.assertFalse(gist.is_starred()) gist.set_starred() self.assertTrue(gist.is_starred()) gist.reset_starred() self.assertFalse(gist.is_starred()) def testFork(self): gist = self.g.get_gist("6296553") # Random gist myGist = gist.create_fork() self.assertEqual(myGist.id, "6296732") self.assertEqual(myGist.fork_of, None) # WTF sameGist = self.g.get_gist("6296732") self.assertEqual(sameGist.fork_of.id, "6296553") def testDelete(self): gist = self.g.get_gist("2729810") gist.delete()
8,092
Python
.py
143
49.447552
125
0.577946
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,543
DeploymentStatus.py
PyGithub_PyGithub/tests/DeploymentStatus.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Colby Gallup <colbygallup@gmail.com> # # Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class DeploymentStatus(Framework.TestCase): def setUp(self): super().setUp() self.deployment = self.g.get_user().get_repo("PyGithub").get_deployment(263877258) self.status = self.deployment.get_status(388454671) def testAttributes(self): self.assertEqual(self.status.id, 388454671) created_at = datetime(2020, 8, 26, 14, 32, 51, tzinfo=timezone.utc) self.assertEqual(self.status.created_at, created_at) self.assertEqual(self.status.creator.login, "jacquev6") self.assertEqual( self.status.deployment_url, "https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258", ) self.assertEqual(self.status.description, "Deployment queued") self.assertEqual(self.status.environment, "test") self.assertEqual(self.status.environment_url, "https://example.com/environment") self.assertEqual( self.status.repository_url, "https://api.github.com/repos/jacquev6/PyGithub", ) self.assertEqual(self.status.state, "queued") self.assertEqual(self.status.target_url, "https://example.com/deployment.log") self.assertEqual(self.status.updated_at, created_at) self.assertEqual( self.status.url, "https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses/388454671", ) self.assertEqual( self.status.node_id, "MDE2OkRlcGxveW1lbnRTdGF0dXMzODg0NTQ2NzE=", ) self.assertEqual( repr(self.status), 'DeploymentStatus(url="https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses/388454671", id=388454671)', ) def testCreate(self): newStatus = self.deployment.create_status( "queued", target_url="https://example.com/deployment.log", description="Deployment queued", environment="test", environment_url="https://example.com/environment", auto_inactive=True, ) self.assertEqual(newStatus.id, 388454671) self.assertEqual(newStatus.state, "queued") self.assertEqual( newStatus.repository_url, "https://api.github.com/repos/jacquev6/PyGithub", ) def testGetStatuses(self): statuses = self.deployment.get_statuses() self.assertListKeyEqual( statuses, lambda s: s.id, [388454671, 388433743, 388432880], )
5,454
Python
.py
95
50.821053
140
0.543909
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,544
Retry.py
PyGithub_PyGithub/tests/Retry.py
############################ Copyrights and license ############################ # # # Copyright 2018 Justin Kufro <jkufro@andrew.cmu.edu> # # Copyright 2019 Isac Souza <isouza@daitan.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Liuyang Wan <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Amador Pahim <apahim@redhat.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import requests import urllib3 # type: ignore from httpretty import httpretty # type: ignore import github from . import Framework REPO_NAME = "PyGithub/PyGithub" class Retry(Framework.TestCase): def setUp(self): # status codes returned on random github server errors status_forcelist = (500, 502, 504) retry = urllib3.Retry(total=3, read=3, connect=3, status_forcelist=status_forcelist) Framework.enableRetry(retry) super().setUp() def testShouldNotRetryWhenStatusNotOnList(self): with self.assertRaises(github.GithubException): self.g.get_repo(REPO_NAME) self.assertEqual(len(httpretty.latest_requests), 1) def testReturnsRepoAfter3Retries(self): repository = self.g.get_repo(REPO_NAME) self.assertEqual(len(httpretty.latest_requests), 4) for request in httpretty.latest_requests: self.assertEqual(request.path, "/repos/" + REPO_NAME) self.assertIsInstance(repository, github.Repository.Repository) self.assertEqual(repository.full_name, REPO_NAME) def testReturnsRepoAfter1Retry(self): repository = self.g.get_repo(REPO_NAME) self.assertEqual(len(httpretty.latest_requests), 2) for request in httpretty.latest_requests: self.assertEqual(request.path, "/repos/" + REPO_NAME) self.assertIsInstance(repository, github.Repository.Repository) self.assertEqual(repository.full_name, REPO_NAME) def testRaisesRetryErrorAfterMaxRetries(self): with self.assertRaises(requests.exceptions.RetryError): self.g.get_repo("PyGithub/PyGithub") self.assertEqual(len(httpretty.latest_requests), 4) for request in httpretty.latest_requests: self.assertEqual(request.path, "/repos/PyGithub/PyGithub") def testReturnsRepoAfterSettingRetryHttp(self): g = github.Github( auth=self.login, base_url="http://my.enterprise.com", retry=0, ) # http here repository = g.get_repo(REPO_NAME) self.assertIsInstance(repository, github.Repository.Repository) self.assertEqual(repository.full_name, REPO_NAME)
4,649
Python
.py
76
55.776316
92
0.556262
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,545
Issue945.py
PyGithub_PyGithub/tests/Issue945.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 netsgnut <284779+netsgnut@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue945(Framework.TestCase): # https://github.com/PyGithub/PyGithub/issues/945 def setUp(self): super().setUp() self.repo = self.g.get_user("openframeworks").get_repo("openFrameworks") self.list = self.repo.get_issues() self.list_with_headers = self.repo.get_stargazers_with_dates() def testReservedPaginatedListAttributePreservation(self): r1 = self.list.reversed self.assertEqual(self.list._PaginatedList__contentClass, r1._PaginatedList__contentClass) self.assertEqual(self.list._PaginatedList__requester, r1._PaginatedList__requester) self.assertEqual(self.list._PaginatedList__firstUrl, r1._PaginatedList__firstUrl) self.assertEqual(self.list._PaginatedList__firstParams, r1._PaginatedList__firstParams) self.assertEqual(self.list._PaginatedList__headers, r1._PaginatedList__headers) self.assertEqual(self.list._PaginatedList__list_item, r1._PaginatedList__list_item) self.assertTrue(self.list_with_headers._PaginatedList__headers is not None) r2 = self.list_with_headers.reversed self.assertEqual( self.list_with_headers._PaginatedList__contentClass, r2._PaginatedList__contentClass, ) self.assertEqual( self.list_with_headers._PaginatedList__requester, r2._PaginatedList__requester, ) self.assertEqual(self.list_with_headers._PaginatedList__firstUrl, r2._PaginatedList__firstUrl) self.assertEqual( self.list_with_headers._PaginatedList__firstParams, r2._PaginatedList__firstParams, ) self.assertEqual(self.list_with_headers._PaginatedList__headers, r2._PaginatedList__headers) self.assertEqual( self.list_with_headers._PaginatedList__list_item, r2._PaginatedList__list_item, )
4,587
Python
.py
68
62.147059
102
0.552725
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,546
Issue216.py
PyGithub_PyGithub/tests/Issue216.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework # Replay data forged by capitalizing headers from PaginatedList.setUp.txt and PaginatedList.testIteration.txt class Issue216(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user("openframeworks").get_repo("openFrameworks") self.list = self.repo.get_issues() def testIteration(self): self.assertEqual(len(list(self.list)), 333)
2,940
Python
.py
40
71.4
109
0.476519
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,547
Permissions.py
PyGithub_PyGithub/tests/Permissions.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 karsten-wagner <39054096+karsten-wagner@users.noreply.github.com># # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Permissions(Framework.TestCase): def setUp(self): super().setUp() self.userRepo = self.g.get_repo("PyGithub/PyGithub") def testUserRepoPermissionAttributes(self): self.assertFalse(self.userRepo.permissions.admin) # Attribute is not present for users (only for teams) self.assertIs(self.userRepo.permissions.maintain, None) self.assertTrue(self.userRepo.permissions.pull) self.assertFalse(self.userRepo.permissions.push) # Attribute is not present for users (only for teams) self.assertIs(self.userRepo.permissions.triage, None) def testUserRepoPermissionRepresentation(self): self.assertEqual( repr(self.userRepo.permissions), "Permissions(triage=None, push=False, pull=True, maintain=None, admin=False)", )
3,629
Python
.py
52
66.307692
90
0.514558
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,548
PullRequest1682.py
PyGithub_PyGithub/tests/PullRequest1682.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2020 Victor Zeng <zacker150@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Trim21 <trim21.me@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PullRequest1682(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("ReDASers/Phishing-Detection") def test_no_parameters(self): runs = self.repo.get_workflow_runs() self.assertEqual(313400760, runs[0].id) def test_object_parameters(self): branch = self.repo.get_branch("adversary") runs = self.repo.get_workflow_runs(branch=branch) self.assertEqual(204764033, runs[0].id) self.assertEqual(1, runs.totalCount) user = self.g.get_user("shahryarabaki") runs = self.repo.get_workflow_runs(actor=user) self.assertEqual(28372848, runs[0].id) def test_string_parameters(self): runs = self.repo.get_workflow_runs(actor="xzhou29") self.assertEqual(226142695, runs[0].id) runs = self.repo.get_workflow_runs(branch="API_Flatten") self.assertEqual(287515889, runs[0].id) runs = self.repo.get_workflow_runs(event="pull_request") self.assertEqual(298867254, runs[0].id) runs = self.repo.get_workflow_runs(status="failure") self.assertEqual(292080359, runs[0].id)
4,114
Python
.py
61
63.42623
85
0.518702
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,549
Organization1437.py
PyGithub_PyGithub/tests/Organization1437.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Anuj Bansal <bansalanuj1996@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Organization1437(Framework.TestCase): def setUp(self): super().setUp() self.org = self.g.get_organization("PyGithubSampleOrg") def testCreateProject(self): project = self.org.create_project("Project title", "This is the body") self.assertEqual(project.id, 4115694)
3,266
Python
.py
44
72.090909
85
0.481943
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,550
BadAttributes.py
PyGithub_PyGithub/tests/BadAttributes.py
############################ Copyrights and license ############################ # # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Hugo <hugovk@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Christoph Reiter <reiter.christoph@gmail.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2024 iarspider <iarspider@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone import github from . import Framework # Replay data is forged to simulate bad things returned by Github class BadAttributes(Framework.TestCase): def testBadSimpleAttribute(self): user = self.g.get_user("klmitch") self.assertEqual( user.created_at, datetime(2011, 3, 23, 15, 42, 9, tzinfo=timezone.utc), ) with self.assertRaises(github.BadAttributeException) as raisedexp: user.name self.assertEqual(raisedexp.exception.actual_value, 42) self.assertEqual(raisedexp.exception.expected_type, str) self.assertEqual(raisedexp.exception.transformation_exception, None) def testBadAttributeTransformation(self): user = self.g.get_user("klmitch") self.assertEqual(user.name, "Kevin L. Mitchell") with self.assertRaises(github.BadAttributeException) as raisedexp: user.created_at self.assertEqual(raisedexp.exception.actual_value, "foobar") self.assertEqual(raisedexp.exception.expected_type, str) self.assertEqual(raisedexp.exception.transformation_exception.__class__, ValueError) self.assertEqual( raisedexp.exception.transformation_exception.args, ("Invalid isoformat string: 'foobar'",), ) def testBadTransformedAttribute(self): user = self.g.get_user("klmitch") self.assertEqual(user.name, "Kevin L. Mitchell") with self.assertRaises(github.BadAttributeException) as raisedexp: user.updated_at self.assertEqual(raisedexp.exception.actual_value, 42) self.assertEqual(raisedexp.exception.expected_type, str) self.assertEqual(raisedexp.exception.transformation_exception, None) def testBadSimpleAttributeInList(self): hook = self.g.get_hook("activecollab") self.assertEqual(hook.name, "activecollab") with self.assertRaises(github.BadAttributeException) as raisedexp: hook.events self.assertEqual(raisedexp.exception.actual_value, ["push", 42]) self.assertEqual(raisedexp.exception.expected_type, [str]) self.assertEqual(raisedexp.exception.transformation_exception, None) def testBadAttributeInClassAttribute(self): repo = self.g.get_repo("klmitch/turnstile") owner = repo.owner self.assertEqual(owner.id, 686398) with self.assertRaises(github.BadAttributeException) as raisedexp: owner.avatar_url self.assertEqual(raisedexp.exception.actual_value, 42) def testBadTransformedAttributeInList(self): commit = self.g.get_repo("klmitch/turnstile", lazy=True).get_commit("38d9082a898d0822b5ccdfd78f3a536e2efa6c26") with self.assertRaises(github.BadAttributeException) as raisedexp: commit.parents self.assertEqual(raisedexp.exception.actual_value, [42]) self.assertEqual(raisedexp.exception.expected_type, [dict]) self.assertEqual(raisedexp.exception.transformation_exception, None) def testBadTransformedAttributeInDict(self): gist = self.g.get_gist("6437766") with self.assertRaises(github.BadAttributeException) as raisedexp: gist.files self.assertEqual(raisedexp.exception.actual_value, {"test.py": 42}) self.assertEqual(raisedexp.exception.expected_type, {str: dict}) self.assertEqual(raisedexp.exception.transformation_exception, None) def testIssue195(self): hooks = self.g.get_hooks() # We can loop on all hooks as long as we don't access circleci's events attribute self.assertListKeyEqual( hooks, lambda h: h.name, [ "activecollab", "acunote", "agilebench", "agilezen", "amazonsns", "apiary", "apoio", "appharbor", "apropos", "asana", "backlog", "bamboo", "basecamp", "bcx", "blimp", "boxcar", "buddycloud", "bugherd", "bugly", "bugzilla", "campfire", "cia", "circleci", "codeclimate", "codeportingcsharp2java", "codeship", "coffeedocinfo", "conductor", "coop", "copperegg", "cube", "depending", "deployhq", "devaria", "docker", "ducksboard", "email", "firebase", "fisheye", "flowdock", "fogbugz", "freckle", "friendfeed", "gemini", "gemnasium", "geocommit", "getlocalization", "gitlive", "grmble", "grouptalent", "grove", "habitualist", "hakiri", "hall", "harvest", "hipchat", "hostedgraphite", "hubcap", "hubci", "humbug", "icescrum", "irc", "irker", "ironmq", "ironworker", "jabber", "jaconda", "jeapie", "jenkins", "jenkinsgit", "jira", "jqueryplugins", "kanbanery", "kickoff", "leanto", "lechat", "lighthouse", "lingohub", "loggly", "mantisbt", "masterbranch", "mqttpub", "nma", "nodejitsu", "notifo", "ontime", "pachube", "packagist", "phraseapp", "pivotaltracker", "planbox", "planio", "prowl", "puppetlinter", "pushalot", "pushover", "pythonpackages", "railsbp", "railsbrakeman", "rally", "rapidpush", "rationaljazzhub", "rationalteamconcert", "rdocinfo", "readthedocs", "redmine", "rubyforge", "scrumdo", "shiningpanda", "sifter", "simperium", "slatebox", "snowyevening", "socialcast", "softlayermessaging", "sourcemint", "splendidbacon", "sprintly", "sqsqueue", "stackmob", "statusnet", "talker", "targetprocess", "tddium", "teamcity", "tender", "tenxer", "testpilot", "toggl", "trac", "trajectory", "travis", "trello", "twilio", "twitter", "unfuddle", "web", "weblate", "webtranslateit", "yammer", "youtrack", "zendesk", "zohoprojects", ], ) for hook in hooks: if hook.name != "circleci": hook.events for hook in hooks: if hook.name == "circleci": with self.assertRaises(github.BadAttributeException) as raisedexp: hook.events self.assertEqual( raisedexp.exception.actual_value, [ [ "commit_comment", "create", "delete", "download", "follow", "fork", "fork_apply", "gist", "gollum", "issue_comment", "issues", "member", "public", "pull_request", "pull_request_review_comment", "push", "status", "team_add", "watch", ] ], ) self.assertEqual(raisedexp.exception.expected_type, [str]) self.assertEqual(raisedexp.exception.transformation_exception, None)
11,721
Python
.py
286
27.884615
119
0.474551
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,551
CommitComment.py
PyGithub_PyGithub/tests/CommitComment.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Nicolas Agustín Torres <nicolastrres@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Huan-Cheng Chang <changhc84@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class CommitComment(Framework.TestCase): def setUp(self): super().setUp() self.comment = self.g.get_user().get_repo("PyGithub").get_comment(1361949) def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") self.assertEqual(self.comment.commit_id, "6945921c529be14c3a8f566dd1e483674516d46d") self.assertEqual( self.comment.created_at, datetime(2012, 5, 22, 18, 40, 18, tzinfo=timezone.utc), ) self.assertEqual( self.comment.html_url, "https://github.com/jacquev6/PyGithub/commit/6945921c529be14c3a8f566dd1e483674516d46d#commitcomment-1361949", ) self.assertEqual(self.comment.id, 1361949) self.assertEqual(self.comment.line, None) self.assertEqual(self.comment.path, None) self.assertEqual(self.comment.position, None) self.assertEqual( self.comment.updated_at, datetime(2012, 5, 22, 18, 40, 18, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, "https://api.github.com/repos/jacquev6/PyGithub/comments/1361949", ) self.assertEqual(self.comment.user.login, "jacquev6") self.assertEqual( repr(self.comment), 'CommitComment(user=NamedUser(login="jacquev6"), id=1361949)', ) def testEdit(self): self.comment.edit("Comment edited by PyGithub") def testDelete(self): self.comment.delete() def testGetReactions(self): reactions = self.comment.get_reactions() self.assertEqual(reactions[0].content, "+1") def testCreateReaction(self): reaction = self.comment.create_reaction("hooray") self.assertEqual(reaction.id, 17283092) self.assertEqual(reaction.content, "hooray") def testDeleteReaction(self): self.assertTrue(self.comment.delete_reaction(85737646))
4,874
Python
.py
82
53.865854
121
0.540682
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,552
Github_.py
PyGithub_PyGithub/tests/Github_.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Peter Golm <golm.peter@gmail.com> # # Copyright 2013 Steve Brown <steve@evolvedlight.co.uk> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Tyler Treat <ttreat31@gmail.com> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Bruce Richardson <itsbruce@workshy.org> # # Copyright 2018 Svend Sorensen <svend@svends.net> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Nikolay Edigaryev <edigaryev@gmail.com> # # Copyright 2020 Omar Brikaa <brikaaomar@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Jonathan Greg <31892308+jmgreg31@users.noreply.github.com> # # Copyright 2023 Joseph Henrich <crimsonknave@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone import github from . import Framework class Github(Framework.TestCase): def testGetGists(self): self.assertListKeyBegin( self.g.get_gists(), lambda g: g.id, [ "2729695", "2729656", "2729597", "2729584", "2729569", "2729554", "2729543", "2729537", "2729536", "2729533", "2729525", "2729522", "2729519", "2729515", "2729506", "2729487", "2729484", "2729482", "2729441", "2729432", "2729420", "2729398", "2729372", "2729371", "2729351", "2729346", "2729316", "2729304", "2729296", "2729276", "2729272", "2729265", "2729195", "2729160", "2729143", "2729127", "2729119", "2729113", "2729103", "2729069", "2729059", "2729051", "2729029", "2729027", "2729026", "2729022", "2729002", "2728985", "2728979", "2728964", "2728937", "2728933", "2728884", "2728869", "2728866", "2728855", "2728854", "2728853", "2728846", "2728825", "2728814", "2728813", "2728812", "2728805", "2728802", "2728800", "2728798", "2728797", "2728796", "2728793", "2728758", "2728754", "2728751", "2728748", "2728721", "2728716", "2728715", "2728705", "2728701", "2728699", "2728697", "2728688", "2728683", "2728677", "2728649", "2728640", "2728625", "2728620", "2728615", "2728614", "2728565", "2728564", "2728554", "2728523", "2728519", "2728511", "2728497", "2728496", "2728495", "2728487", ], ) def testGetGistsWithSince(self): self.assertListKeyBegin( self.g.get_gists(since=datetime(2018, 10, 2, 10, 38, 30, 00)), lambda g: g.id, [ "69b8a5831b74946db944c5451017fa40", "c22050a8705e93d170e0d4ca9c02e40c", "a7a95e1a194e07960364a5b32c56ac5f", "a25d9ace89b574f95bf0724f95a84fc2", "3195465", ], ) def testGetGlobalAdvisories(self): self.assertListKeyEqual( self.g.get_global_advisories(ecosystem="pub"), lambda a: a.ghsa_id, [ "GHSA-9324-jv53-9cc8", "GHSA-9f2c-xxfm-32mj", "GHSA-4xh4-v2pq-jvhm", "GHSA-jwpw-q68h-r678", "GHSA-4rgh-jx4f-qfcq", ], ) def testGetGlobalAdvisoriesByGHSA(self): self.assertListKeyEqual( self.g.get_global_advisories(ghsa_id="GHSA-9324-jv53-9cc8"), lambda a: a.ghsa_id, [ "GHSA-9324-jv53-9cc8", ], ) def testGetGlobalAdvisoriesByCVE(self): self.assertListKeyEqual( self.g.get_global_advisories(cve_id="CVE-2023-38503"), lambda a: a.ghsa_id, [ "GHSA-gggm-66rh-pp98", ], ) def testGetGlobalAdvisoriesManyFilters(self): cases = [ {"cwes": [200, 900], "affects": ["directus", "made_up"], "modified": ">2023-07-01"}, {"cwes": ["200", "900"], "affects": ["directus"], "updated": ">2023-07-01"}, {"cwes": "200,900", "affects": "directus", "published": ">2023-07-01"}, ] for case in cases: with self.subTest(**case): advisories = self.g.get_global_advisories( type="reviewed", ecosystem="npm", severity="medium", # cwes=case["cwes"], is_withdrawn=False, # affects=case["affects"], # modified=">2023-07-01", direction="desc", sort="updated", **case, ) self.assertListKeyEqual( advisories, lambda a: a.ghsa_id, [ "GHSA-gggm-66rh-pp98", ], ) def testGetHooks(self): hooks = self.g.get_hooks() hook = hooks[0] self.assertEqual(hook.name, "activecollab") self.assertEqual(hook.supported_events, ["push"]) self.assertEqual(hook.events, ["push"]) self.assertEqual( hook.schema, [ ["string", "url"], ["string", "token"], ["string", "project_id"], ["string", "milestone_id"], ["string", "category_id"], ], ) def testGetEmojis(self): emojis = self.g.get_emojis() first = emojis.get("+1") self.assertEqual(first, "https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5") def testGetHook(self): hook = self.g.get_hook("activecollab") self.assertEqual(hook.name, "activecollab") self.assertEqual(hook.supported_events, ["push"]) self.assertEqual(hook.events, ["push"]) self.assertEqual( hook.schema, [ ["string", "url"], ["string", "token"], ["string", "project_id"], ["string", "milestone_id"], ["string", "category_id"], ], ) self.assertEqual(repr(hook), 'HookDescription(name="activecollab")') def testGetHookDelivery(self): delivery = self.g.get_hook_delivery(257993, 12345) self.assertEqual(delivery.id, 12345) self.assertEqual(delivery.guid, "abcde-12345") self.assertEqual( delivery.delivered_at, datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(delivery.redelivery, False) self.assertEqual(delivery.duration, 0.27) self.assertEqual(delivery.status, "OK") self.assertEqual(delivery.status_code, 200) self.assertEqual(delivery.event, "issues") self.assertEqual(delivery.action, "opened") self.assertEqual(delivery.installation_id, 123) self.assertEqual(delivery.repository_id, 456) self.assertEqual(delivery.url, "https://www.example-webhook.com") self.assertIsInstance(delivery.request, github.HookDelivery.HookDeliveryRequest) self.assertEqual(delivery.request.headers, {"content-type": "application/json"}) self.assertEqual(delivery.request.payload, {"action": "opened"}) self.assertIsInstance(delivery.response, github.HookDelivery.HookDeliveryResponse) self.assertEqual(delivery.response.headers, {"content-type": "text/html;charset=utf-8"}) self.assertEqual(delivery.response.payload, "ok") def testGetHookDeliveries(self): deliveries = list(self.g.get_hook_deliveries(257993)) self.assertEqual(len(deliveries), 1) self.assertEqual(deliveries[0].id, 12345) self.assertEqual(deliveries[0].guid, "abcde-12345") self.assertEqual( deliveries[0].delivered_at, datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(deliveries[0].redelivery, False) self.assertEqual(deliveries[0].duration, 0.27) self.assertEqual(deliveries[0].status, "OK") self.assertEqual(deliveries[0].status_code, 200) self.assertEqual(deliveries[0].event, "issues") self.assertEqual(deliveries[0].action, "opened") self.assertEqual(deliveries[0].installation_id, 123) self.assertEqual(deliveries[0].repository_id, 456) self.assertEqual(deliveries[0].url, "https://www.example-webhook.com") def testGetRepoFromFullName(self): self.assertEqual( self.g.get_repo("jacquev6/PyGithub").description, "Python library implementing the full Github API v3", ) def testGetRepoFromId(self): self.assertEqual( self.g.get_repo(3544490).description, "Python library implementing the full Github API v3", ) def testGetGitignoreTemplates(self): self.assertEqual( self.g.get_gitignore_templates(), [ "Actionscript", "Android", "AppceleratorTitanium", "Autotools", "Bancha", "C", "C++", "CFWheels", "CMake", "CSharp", "CakePHP", "Clojure", "CodeIgniter", "Compass", "Concrete5", "Coq", "Delphi", "Django", "Drupal", "Erlang", "ExpressionEngine", "Finale", "ForceDotCom", "FuelPHP", "GWT", "Go", "Grails", "Haskell", "Java", "Jboss", "Jekyll", "Joomla", "Jython", "Kohana", "LaTeX", "Leiningen", "LemonStand", "Lilypond", "Lithium", "Magento", "Maven", "Node", "OCaml", "Objective-C", "Opa", "OracleForms", "Perl", "PlayFramework", "Python", "Qooxdoo", "Qt", "R", "Rails", "RhodesRhomobile", "Ruby", "Scala", "Sdcc", "SeamGen", "SketchUp", "SugarCRM", "Symfony", "Symfony2", "SymphonyCMS", "Target3001", "Tasm", "Textpattern", "TurboGears2", "Unity", "VB.Net", "Waf", "Wordpress", "Yii", "ZendFramework", "gcov", "nanoc", "opencart", ], ) def testGetGitignoreTemplate(self): t = self.g.get_gitignore_template("Python") self.assertEqual(t.name, "Python") self.assertEqual( t.source, "*.py[cod]\n\n# C extensions\n*.so\n\n# Packages\n*.egg\n*.egg-info\ndist\nbuild\neggs\nparts\nbin\nvar\nsdist\ndevelop-eggs\n.installed.cfg\nlib\nlib64\n\n# Installer logs\npip-log.txt\n\n# Unit test / coverage reports\n.coverage\n.tox\nnosetests.xml\n\n# Translations\n*.mo\n\n# Mr Developer\n.mr.developer.cfg\n.project\n.pydevproject\n", ) self.assertEqual(repr(t), 'GitignoreTemplate(name="Python")') t = self.g.get_gitignore_template("C++") self.assertEqual(t.name, "C++") self.assertEqual( t.source, "# Compiled Object files\n*.slo\n*.lo\n*.o\n\n# Compiled Dynamic libraries\n*.so\n*.dylib\n\n# Compiled Static libraries\n*.lai\n*.la\n*.a\n", ) def testStringOfNotSet(self): self.assertEqual(str(github.GithubObject.NotSet), "NotSet") def testGetUserById(self): self.assertEqual(self.g.get_user_by_id(583231).login, "octocat") def testGetUsers(self): self.assertListKeyBegin( self.g.get_users(), lambda u: u.login, [ "mojombo", "defunkt", "pjhyett", "wycats", "ezmobius", "ivey", "evanphx", "vanpelt", "wayneeseguin", "brynary", "kevinclark", "technoweenie", "macournoyer", "takeo", "Caged", "topfunky", "anotherjesse", "roland", "lukas", "fanvsfan", "tomtt", "railsjitsu", "nitay", "kevwil", "KirinDave", "jamesgolick", "atmos", "errfree", "mojodna", "bmizerany", "jnewland", "joshknowles", "hornbeck", "jwhitmire", "elbowdonkey", "reinh", "timocratic", "bs", "rsanheim", "schacon", "uggedal", "bruce", "sam", "mmower", "abhay", "rabble", "benburkert", "indirect", "fearoffish", "ry", "engineyard", "jsierles", "tweibley", "peimei", "brixen", "tmornini", "outerim", "daksis", "sr", "lifo", "rsl", "imownbey", "dylanegan", "jm", "willcodeforfoo", "jvantuyl", "BrianTheCoder", "freeformz", "hassox", "automatthew", "queso", "lancecarlson", "drnic", "lukesutton", "danwrong", "hcatlin", "jfrost", "mattetti", "ctennis", "lawrencepit", "marcjeanson", "grempe", "peterc", "ministrycentered", "afarnham", "up_the_irons", "evilchelu", "heavysixer", "brosner", "danielmorrison", "danielharan", "kvnsmth", "collectiveidea", "canadaduane", "nate", "dstrelau", "sunny", "dkubb", "jnicklas", "richcollins", "simonjefford", ], ) def testGetUsersSince(self): self.assertListKeyBegin(self.g.get_users(since=1000), lambda u: u.login, ["sbecker"]) def testGetOrganizations(self): self.assertListKeyBegin( self.g.get_organizations(), lambda u: u.login, [ "errfree", "engineyard", "ministrycentered", "collectiveidea", "ogc", "sevenwire", "entryway", ], ) def testGetOrganizationsSince(self): self.assertListKeyBegin( self.g.get_organizations(since=1000), lambda u: u.login, [ "railslove", "railsdog", "netguru", "webhostio", "animikii", "sauspiel", "wherecloud", "triveos", ], ) def testGetRepos(self): self.assertListKeyBegin( self.g.get_repos(), lambda r: r.name, [ "grit", "merb-core", "rubinius", "god", "jsawesome", "jspec", "exception_logger", "ambition", ], ) def testGetReposSince(self): self.assertListKeyBegin( self.g.get_repos(since=1000), lambda r: r.name, [ "jquery-humanize-messages-plugin", "4slicer", "fixture-scenarios", "mongrel_proctitle", "rails-plugins", ], ) def testGetLicenses(self): self.assertListKeyBegin( self.g.get_licenses(), lambda r: r.name, [ "GNU General Public License v3.0", 'BSD 2-Clause "Simplified" License', "MIT License", "GNU Lesser General Public License v2.1", "GNU General Public License v2.0", "GNU Lesser General Public License v3.0", "Mozilla Public License 2.0", 'BSD 3-Clause "New" or "Revised" License', ], ) def testGetLicense(self): self.assertEqual( self.g.get_license("mit").description, "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.", ) def testGetEvents(self): self.assertListKeyBegin( self.g.get_events(), lambda e: e.type, ["PushEvent", "WatchEvent", "PushEvent", "CommitCommentEvent"], ) def testRequester(self): assert self.g.requester is self.g.__requester
22,062
Python
.py
601
23.136439
353
0.445004
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,553
RateLimiting.py
PyGithub_PyGithub/tests/RateLimiting.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Ed Jackson <ed.jackson@gmail.com> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Nikolay Yurin <yurinnick93@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class RateLimiting(Framework.TestCase): def testRateLimiting(self): self.assertEqual(self.g.rate_limiting, (4904, 5000)) self.g.get_user("yurinnick") self.assertEqual(self.g.rate_limiting, (4903, 5000)) self.assertEqual(self.g.rate_limiting_resettime, 1684195041) def testResetTime(self): self.assertEqual(self.g.rate_limiting_resettime, 1684195041) def testGetRateLimit(self): rateLimit = self.g.get_rate_limit() self.assertEqual( repr(rateLimit), "RateLimit(core=Rate(reset=2023-05-15 23:57:21+00:00, remaining=4904, limit=5000))", ) self.assertEqual( repr(rateLimit.core), "Rate(reset=2023-05-15 23:57:21+00:00, remaining=4904, limit=5000)", ) self.assertEqual(rateLimit.core.limit, 5000) self.assertEqual(rateLimit.core.remaining, 4904) self.assertEqual(rateLimit.core.used, 96) self.assertEqual(rateLimit.core.reset, datetime(2023, 5, 15, 23, 57, 21, tzinfo=timezone.utc))
3,960
Python
.py
59
63.101695
102
0.512452
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,554
Issue134.py
PyGithub_PyGithub/tests/Issue134.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import github from . import Framework class Issue134(Framework.BasicTestCase): # https://github.com/jacquev6/PyGithub/pull/134 def testGetAuthorizationsFailsWhenAutenticatedThroughOAuth(self): g = github.Github(auth=self.oauth_token) with self.assertRaises(github.GithubException) as raisedexp: list(g.get_user().get_authorizations()) self.assertEqual(raisedexp.exception.status, 404) def testGetAuthorizationsSucceedsWhenAutenticatedThroughLoginPassword(self): g = github.Github(auth=self.login) self.assertListKeyEqual( g.get_user().get_authorizations(), lambda a: a.note, [None, None, "cligh", None, None, "GitHub Android App"], ) def testGetOAuthScopesFromHeader(self): g = github.Github(auth=self.oauth_token) self.assertEqual(g.oauth_scopes, None) g.get_user().name self.assertEqual(g.oauth_scopes, ["repo", "user", "gist"])
3,737
Python
.py
54
65.5
89
0.51183
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,555
GithubApp.py
PyGithub_PyGithub/tests/GithubApp.py
############################ Copyrights and license ############################ # # # Copyright 2020 Mahesh Raju <coder@mahesh.net> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 chantra <chantra@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone import github from . import Framework from .GithubIntegration import APP_ID, PRIVATE_KEY class GithubApp(Framework.TestCase): def setUp(self): super().setUp() self.app_slug = "github-actions" def testGetPublicApp(self): app = self.g.get_app(slug=self.app_slug) self.assertEqual(app.created_at, datetime(2018, 7, 30, 9, 30, 17, tzinfo=timezone.utc)) self.assertEqual(app.description, "Automate your workflow from idea to production") self.assertListEqual( app.events, [ "check_run", "check_suite", "create", "delete", "deployment", "deployment_status", "fork", "gollum", "issues", "issue_comment", "label", "milestone", "page_build", "project", "project_card", "project_column", "public", "pull_request", "pull_request_review", "pull_request_review_comment", "push", "registry_package", "release", "repository", "repository_dispatch", "status", "watch", "workflow_dispatch", "workflow_run", ], ) self.assertEqual(app.external_url, "https://help.github.com/en/actions") self.assertEqual(app.html_url, "https://github.com/apps/github-actions") self.assertEqual(app.id, 15368) self.assertEqual(app.name, "GitHub Actions") self.assertEqual(app.owner.login, "github") self.assertDictEqual( app.permissions, { "actions": "write", "checks": "write", "contents": "write", "deployments": "write", "issues": "write", "metadata": "read", "packages": "write", "pages": "write", "pull_requests": "write", "repository_hooks": "write", "repository_projects": "write", "security_events": "write", "statuses": "write", "vulnerability_alerts": "read", }, ) self.assertEqual(app.slug, "github-actions") self.assertEqual(app.updated_at, datetime(2019, 12, 10, 19, 4, 12, tzinfo=timezone.utc)) self.assertEqual(app.url, "/apps/github-actions") def testGetAuthenticatedApp(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) g = github.Github(auth=auth) with self.assertWarns(DeprecationWarning) as warning: # httpretty has some deprecation warnings in Python 3.12 with self.ignoreWarning(category=DeprecationWarning, module="httpretty"): app = g.get_app() self.assertWarning( warning, "Argument slug is mandatory, calling this method without the slug argument is deprecated, " "please use github.GithubIntegration(auth=github.Auth.AppAuth(...)).get_app() instead", ) self.assertEqual(app.created_at, datetime(2020, 8, 1, 17, 23, 46, tzinfo=timezone.utc)) self.assertEqual(app.description, "Sample App to test PyGithub") self.assertListEqual( app.events, ["check_run", "check_suite", "label", "member", "public"], ) self.assertEqual(app.external_url, "https://pygithub.readthedocs.io") self.assertEqual(app.html_url, "https://github.com/apps/pygithubtest") self.assertEqual(app.id, 75269) self.assertEqual(app.name, "PyGithubTest") self.assertEqual(app.owner.login, "wrecker") self.assertDictEqual( app.permissions, { "actions": "write", "checks": "write", "keys": "read", "members": "read", "metadata": "read", "packages": "read", "pages": "read", "repository_hooks": "write", "vulnerability_alerts": "read", "workflows": "write", }, ) self.assertEqual(app.slug, "pygithubtest") self.assertEqual(app.updated_at, datetime(2020, 8, 1, 17, 44, 31, tzinfo=timezone.utc)) self.assertEqual(app.url, "/apps/pygithubtest")
6,647
Python
.py
139
36.848921
107
0.487996
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,556
NamedUser1430.py
PyGithub_PyGithub/tests/NamedUser1430.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Anuj Bansal <bansalanuj1996@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class NamedUser1430(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user("ahhda") def testGetProjects(self): self.assertListKeyBegin( self.user.get_projects(state="all"), lambda e: e.id, [4083095], )
3,260
Python
.py
47
66.531915
85
0.470496
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,557
PullRequestReview1856.py
PyGithub_PyGithub/tests/PullRequestReview1856.py
############################ Copyrights and license ############################ # # # Copyright 2021 Claire Johns <42869556+johnsc1@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PullRequestReview1856(Framework.TestCase): def setUp(self): super().setUp() pumpkin_repo = self.g.get_repo("CS481-Team-Pumpkin/PyGithub", lazy=True) self.pumpkin_pull = pumpkin_repo.get_pull(4) self.pullreview = self.pumpkin_pull.get_review(631460061) def testDelete(self): self.pullreview.delete() reviews = self.pumpkin_pull.get_reviews() self.assertEqual(list(reviews), [])
2,257
Python
.py
33
65.333333
80
0.443694
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,558
Issue54.py
PyGithub_PyGithub/tests/Issue54.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Issue54(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("TestRepo") def testConversion(self): commit = self.repo.get_git_commit("73f320ae06cd565cf38faca34b6a482addfc721b") self.assertEqual( commit.message, "Test commit created around Fri, 13 Jul 2012 18:43:21 GMT, that is vendredi 13 juillet 2012 20:43:21 GMT+2\n", ) self.assertEqual( commit.author.date, datetime(2012, 7, 13, 18, 47, 10, tzinfo=timezone.utc), )
3,163
Python
.py
47
63.808511
122
0.477981
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,559
Repository.py
PyGithub_PyGithub/tests/Repository.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2015 Christopher Wilcox <git@crwilcox.com> # # Copyright 2015 Dan Vanderkam <danvdk@gmail.com> # # Copyright 2015 Enix Yu <enix223@163.com> # # Copyright 2015 Kyle Hornberg <khornberg@users.noreply.github.com> # # Copyright 2015 Uriel Corfa <uriel@corfa.fr> # # Copyright 2016 @tmshn <tmshn@r.recruit.co.jp> # # Copyright 2016 Enix Yu <enix223@163.com> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Jimmy Zelinskie <jimmyzelinskie@gmail.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 AetherDeity <aetherdeity+github@gmail.com> # # Copyright 2018 Alice GIRARD <bouhahah@gmail.com> # # Copyright 2018 Benoit Latinier <benoit@latinier.fr> # # Copyright 2018 Hayden Fuss <wifu1234@gmail.com> # # Copyright 2018 Iraquitan Cordeiro Filho <iraquitanfilho@gmail.com> # # Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> # # Copyright 2018 Maarten Fonville <mfonville@users.noreply.github.com> # # Copyright 2018 Mateusz Loskot <mateusz@loskot.net> # # Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # # Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Victor Granic <vmg@boreal321.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 Will Yardley <wyardley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Tim Gates <tim.gates@iress.com> # # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2019 Will Li <cuichen.li94@gmail.com> # # Copyright 2020 Chris de Graaf <chrisadegraaf@gmail.com> # # Copyright 2020 Florent Clarret <florent.clarret@gmail.com> # # Copyright 2020 Glenn McDonald <testworksau@users.noreply.github.com> # # Copyright 2020 Huw Jones <huwcbjones@outlook.com> # # Copyright 2020 Pascal Hofmann <mail@pascalhofmann.de> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2020 ton-katsu <sakamoto.yoshihisa@gmail.com> # # Copyright 2021 Chris Keating <christopherkeating@gmail.com> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 karsten-wagner <39054096+karsten-wagner@users.noreply.github.com># # Copyright 2021 xmo-odoo <xmo@odoo.com> # # Copyright 2022 Eric Nieuwland <eric.nieuwland@gmail.com> # # Copyright 2022 Ibrahim Hussaini <ibrahimhussainialias@outlook.com> # # Copyright 2022 KimSia Sim <245021+simkimsia@users.noreply.github.com> # # Copyright 2022 Marco Köpcke <hello@parakoopa.de> # # Copyright 2023 Andrew Dawes <53574062+AndrewJDawes@users.noreply.github.com> # # Copyright 2023 Armen Martirosyan <armartirosyan@gmail.com> # # Copyright 2023 BradChengIRESS <49461141+BradChengIRESS@users.noreply.github.com># # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Felipe Peter <mr-peipei@web.de> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Jonathan Greg <31892308+jmgreg31@users.noreply.github.com> # # Copyright 2023 Mauricio Alejandro Martínez Pacheco <mauricio.martinez@premise.com># # Copyright 2023 Mauricio Alejandro Martínez Pacheco <n_othing@hotmail.com> # # Copyright 2023 Max Mehl <6170081+mxmehl@users.noreply.github.com> # # Copyright 2023 Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com># # Copyright 2023 Trim21 <trim21.me@gmail.com> # # Copyright 2023 Wojciech Barczyński <104033489+WojciechBarczynski@users.noreply.github.com># # Copyright 2024 Benjamin K <53038537+treee111@users.noreply.github.com> # # Copyright 2024 Chris Wells <ping@cwlls.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Heitor Polidoro <heitor.polidoro@gmail.com> # # Copyright 2024 Heitor de Bittencourt <heitorpbittencourt@gmail.com> # # Copyright 2024 Jacky Lam <jacky.lam@r2studiohk.com> # # Copyright 2024 Thomas Crowley <15927917+thomascrowley@users.noreply.github.com># # Copyright 2024 jodelasur <34933233+jodelasur@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import date, datetime, timezone from unittest import mock import github from . import Framework class Repository(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user() self.repo = self.user.get_repo("PyGithub") def testAttributes(self): self.assertEqual(self.repo.clone_url, "https://github.com/jacquev6/PyGithub.git") self.assertEqual( self.repo.created_at, datetime(2012, 2, 25, 12, 53, 47, tzinfo=timezone.utc), ) self.assertEqual(self.repo.description, "Python library implementing the full Github API v3") self.assertFalse(self.repo.fork) self.assertEqual(self.repo.forks, 3) self.assertEqual(self.repo.full_name, "jacquev6/PyGithub") self.assertEqual(self.repo.git_url, "git://github.com/jacquev6/PyGithub.git") self.assertTrue(self.repo.has_downloads) self.assertTrue(self.repo.has_issues) self.assertEqual( self.repo.deployments_url, "https://api.github.com/repos/jacquev6/PyGithub/deployments", ) self.assertFalse(self.repo.has_pages) self.assertEqual( self.repo.releases_url, "https://api.github.com/repos/jacquev6/PyGithub/releases{/id}", ) self.assertFalse(self.repo.has_wiki) self.assertFalse(self.repo.has_discussions) self.assertEqual(self.repo.homepage, "http://vincent-jacques.net/PyGithub") self.assertEqual(self.repo.html_url, "https://github.com/jacquev6/PyGithub") self.assertEqual(self.repo.id, 3544490) self.assertIs(self.repo.is_template, None) self.assertEqual(self.repo.language, "Python") self.assertEqual(self.repo.license.spdx_id, "LGPL-3.0") self.assertEqual(self.repo.master_branch, None) self.assertEqual(self.repo.name, "PyGithub") self.assertEqual(self.repo.open_issues, 16) self.assertEqual(self.repo.organization, None) self.assertEqual(self.repo.owner.login, "jacquev6") self.assertEqual(self.repo.parent, None) self.assertTrue(self.repo.permissions.admin) self.assertTrue(self.repo.permissions.pull) self.assertTrue(self.repo.permissions.push) self.assertFalse(self.repo.private) self.assertEqual( self.repo.pushed_at, datetime(2012, 5, 27, 6, 0, 28, tzinfo=timezone.utc), ) self.assertEqual(self.repo.size, 308) self.assertEqual(self.repo.source, None) self.assertEqual(self.repo.ssh_url, "git@github.com:jacquev6/PyGithub.git") self.assertEqual(self.repo.svn_url, "https://github.com/jacquev6/PyGithub") self.assertEqual( self.repo.updated_at, datetime(2012, 5, 27, 6, 55, 28, tzinfo=timezone.utc), ) self.assertEqual(self.repo.url, "https://api.github.com/repos/jacquev6/PyGithub") self.assertEqual(self.repo.watchers, 15) self.assertEqual(repr(self.repo), 'Repository(full_name="jacquev6/PyGithub")') self.assertTrue(self.repo.permissions.admin) self.assertTrue(self.repo.permissions.push) self.assertTrue(self.repo.permissions.pull) # Allow None or any boolean value for backwards compatibility self.assertIn(self.repo.permissions.maintain, [None, False, True]) self.assertIn(self.repo.permissions.triage, [None, False, True]) self.assertTrue(self.repo.use_squash_pr_title_as_default) self.assertEqual(self.repo.squash_merge_commit_title, "PR_TITLE") self.assertEqual(self.repo.squash_merge_commit_message, "COMMIT_MESSAGES") self.assertEqual(self.repo.merge_commit_title, "PR_TITLE") self.assertEqual(self.repo.merge_commit_message, "PR_BODY") self.assertTrue(self.repo.web_commit_signoff_required) self.assertEqual(self.repo.custom_properties, {"foo": "bar"}) def testEditWithoutArguments(self): self.repo.edit("PyGithub") def testEditWithAllArguments(self): self.repo.edit( "PyGithub", "Description edited by PyGithub", "http://vincent-jacques.net/PyGithub", private=True, has_issues=True, has_projects=False, has_wiki=False, has_discussions=False, allow_auto_merge=True, allow_forking=True, allow_update_branch=True, allow_squash_merge=True, allow_merge_commit=True, allow_rebase_merge=True, delete_branch_on_merge=True, use_squash_pr_title_as_default=True, is_template=True, squash_merge_commit_title="PR_TITLE", squash_merge_commit_message="COMMIT_MESSAGES", merge_commit_title="PR_TITLE", merge_commit_message="PR_BODY", web_commit_signoff_required=True, ) self.assertEqual(self.repo.description, "Description edited by PyGithub") self.repo.edit("PyGithub", "Python library implementing the full Github API v3") self.assertEqual(self.repo.description, "Python library implementing the full Github API v3") self.assertFalse(self.repo.archived) self.assertTrue(self.repo.allow_update_branch) self.assertTrue(self.repo.has_issues) self.assertFalse(self.repo.has_projects) self.assertFalse(self.repo.has_wiki) self.assertFalse(self.repo.has_discussions) self.assertTrue(self.repo.allow_auto_merge) self.assertTrue(self.repo.allow_forking) self.assertTrue(self.repo.allow_squash_merge) self.assertTrue(self.repo.allow_merge_commit) self.assertTrue(self.repo.allow_rebase_merge) self.assertTrue(self.repo.delete_branch_on_merge) self.assertTrue(self.repo.use_squash_pr_title_as_default) self.assertEqual(self.repo.squash_merge_commit_title, "PR_TITLE") self.assertEqual(self.repo.squash_merge_commit_message, "COMMIT_MESSAGES") self.assertEqual(self.repo.merge_commit_title, "PR_TITLE") self.assertEqual(self.repo.merge_commit_message, "PR_BODY") self.assertTrue(self.repo.web_commit_signoff_required) def testEditWithDefaultBranch(self): self.assertEqual(self.repo.master_branch, None) self.repo.edit("PyGithub", default_branch="master") self.assertEqual(self.repo.master_branch, "master") def testDelete(self): repo = self.g.get_user().get_repo("TestPyGithub") repo.delete() def testGetContributors(self): self.assertListKeyEqual( self.repo.get_contributors(), lambda c: (c.login, c.contributions), [("jacquev6", 355)], ) def testCreateMilestone(self): milestone = self.repo.create_milestone( "Milestone created by PyGithub", state="open", description="Description created by PyGithub", due_on=date(2012, 6, 15), ) self.assertEqual(milestone.number, 5) def testCreateMilestoneWithMinimalArguments(self): milestone = self.repo.create_milestone("Milestone also created by PyGithub") self.assertEqual(milestone.number, 6) def testCreateIssue(self): issue = self.repo.create_issue("Issue created by PyGithub") self.assertEqual(issue.number, 28) def testCreateIssueWithAllArguments(self): user = self.g.get_user("jacquev6") milestone = self.repo.get_milestone(2) question = self.repo.get_label("Question") issue = self.repo.create_issue( "Issue also created by PyGithub", "Body created by PyGithub", user, milestone, [question], ["jacquev6", "stuglaser"], ) self.assertEqual(issue.number, 30) def testCreateIssueWithAllArgumentsStringLabel(self): user = self.g.get_user("jacquev6") milestone = self.repo.get_milestone(2) issue = self.repo.create_issue( "Issue also created by PyGithub", "Body created by PyGithub", user, milestone, ["Question"], ["jacquev6", "stuglaser"], ) self.assertEqual(issue.number, 30) def testCreateLabel(self): label = self.repo.create_label( "Label with silly name % * + created by PyGithub", "00ff00", "Description of label with silly name", ) self.assertEqual(label.color, "00ff00") self.assertEqual(label.description, "Description of label with silly name") self.assertEqual(label.name, "Label with silly name % * + created by PyGithub") self.assertEqual( label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub", ) def testGetLabel(self): label = self.repo.get_label("Label with silly name % * + created by PyGithub") self.assertEqual(label.color, "00ff00") self.assertEqual(label.name, "Label with silly name % * + created by PyGithub") self.assertEqual( label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub", ) def testCreateHookWithMinimalParameters(self): hook = self.repo.create_hook("web", {"url": "http://foobar.com"}) self.assertEqual(hook.id, 257967) def testCreateHookWithAllParameters(self): hook = self.repo.create_hook("web", {"url": "http://foobar.com"}, ["fork"], False) self.assertTrue(hook.active) # WTF self.assertEqual(hook.id, 257993) def testCreateGitRef(self): ref = self.repo.create_git_ref( "refs/heads/BranchCreatedByPyGithub", "4303c5b90e2216d927155e9609436ccb8984c495", ) self.assertEqual( ref.url, "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub", ) def testCreateAutolink(self): key = self.repo.create_autolink("DUMMY-", "https://github.com/PyGithub/PyGithub/issues/<num>") self.assertEqual(key.id, 209614) def testCreateGitBlob(self): blob = self.repo.create_git_blob("Blob created by PyGithub", "latin1") self.assertEqual(blob.sha, "5dd930f591cd5188e9ea7200e308ad355182a1d8") def testCreateGitTree(self): tree = self.repo.create_git_tree( [github.InputGitTreeElement("Foobar.txt", "100644", "blob", content="File created by PyGithub")] ) self.assertEqual(tree.sha, "41cf8c178c636a018d537cb20daae09391efd70b") def testCreateGitTreeWithBaseTree(self): base_tree = self.repo.get_git_tree("41cf8c178c636a018d537cb20daae09391efd70b", recursive=False) tree = self.repo.create_git_tree( [ github.InputGitTreeElement( "Barbaz.txt", "100644", "blob", content="File also created by PyGithub", ) ], base_tree, ) self.assertEqual(tree.sha, "107139a922f33bab6fbeb9f9eb8787e7f19e0528") def testCreateGitTreeWithSha(self): tree = self.repo.create_git_tree( [ github.InputGitTreeElement( "Barbaz.txt", "100644", "blob", sha="5dd930f591cd5188e9ea7200e308ad355182a1d8", ) ] ) self.assertEqual(tree.sha, "fae707821159639589bf94f3fb0a7154ec5d441b") def testCreateGitTreeWithNullSha(self): tree = self.repo.create_git_tree( [ github.InputGitTreeElement( "Baz.bar", "100644", "blob", sha=None, ) ] ) self.assertEqual(tree.sha, "9b8166fc80d0f0fe9192d4bf1dbaa87f194e012f") def testCreateGitCommit(self): tree = self.repo.get_git_tree("107139a922f33bab6fbeb9f9eb8787e7f19e0528") commit = self.repo.create_git_commit("Commit created by PyGithub", tree, []) self.assertEqual(commit.sha, "0b820628236ab8bab3890860fc414fa757ca15f4") def testCreateGitCommitWithParents(self): parents = [ self.repo.get_git_commit("7248e66831d4ffe09ef1f30a1df59ec0a9331ece"), self.repo.get_git_commit("12d427464f8d91c8e981043a86ba8a2a9e7319ea"), ] tree = self.repo.get_git_tree("fae707821159639589bf94f3fb0a7154ec5d441b") commit = self.repo.create_git_commit("Commit created by PyGithub", tree, parents) self.assertEqual(commit.sha, "6adf9ea25ff8a8f2a42bcb1c09e42526339037cd") def testCreateGitCommitWithAllArguments(self): tree = self.repo.get_git_tree("107139a922f33bab6fbeb9f9eb8787e7f19e0528") commit = self.repo.create_git_commit( "Commit created by PyGithub", tree, [], github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"), github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"), ) self.assertEqual(commit.sha, "526946197ae9da59c6507cacd13ad6f1cfb686ea") def testCreateGitRelease(self): release = self.repo.create_git_release( "vX.Y.Z-by-PyGithub-acctest", "vX.Y.Z: PyGithub acctest", "This release is created by PyGithub", ) self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest") self.assertEqual(release.title, "vX.Y.Z: PyGithub acctest") self.assertEqual(release.body, "This release is created by PyGithub") self.assertEqual(release.draft, False) self.assertEqual(release.prerelease, False) def testCreateGitReleaseGenerateReleaseNotes(self): release = self.repo.create_git_release("vX.Y.Z-by-PyGithub-acctest-release-notes", generate_release_notes=True) self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest-release-notes") self.assertEqual(release.draft, False) self.assertEqual(release.prerelease, False) def testCreateGitReleaseWithAllArguments(self): release = self.repo.create_git_release( "vX.Y.Z-by-PyGithub-acctest2", "vX.Y.Z: PyGithub acctest2", "This release is also created by PyGithub", False, True, False, "da9a285fd8b782461e56cba39ae8d2fa41ca7cdc", ) self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest2") self.assertEqual(release.title, "vX.Y.Z: PyGithub acctest2") self.assertEqual(release.body, "This release is also created by PyGithub") self.assertEqual(release.draft, False) self.assertEqual(release.prerelease, True) tag = [tag for tag in self.repo.get_tags() if tag.name == "vX.Y.Z-by-PyGithub-acctest2"].pop() self.assertEqual(tag.commit.sha, "da9a285fd8b782461e56cba39ae8d2fa41ca7cdc") def testCreateGitTag(self): tag = self.repo.create_git_tag( "TaggedByPyGithub", "Tag created by PyGithub", "0b820628236ab8bab3890860fc414fa757ca15f4", "commit", ) self.assertEqual(tag.sha, "5ba561eaa2b7ca9015662510157b15d8f3b0232a") def testCreateGitTagWithAllArguments(self): tag = self.repo.create_git_tag( "TaggedByPyGithub2", "Tag also created by PyGithub", "526946197ae9da59c6507cacd13ad6f1cfb686ea", "commit", github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"), ) self.assertEqual(tag.sha, "f0e99a8335fbc84c53366c4a681118468f266625") def testCreateKey(self): key = self.repo.create_key( "Key added through PyGithub", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE", ) self.assertEqual(key.id, 2626761) def testCreateSourceImport(self): import_repo = self.g.get_user("brix4dayz").get_repo("source-import-test") source_import = import_repo.create_source_import("mercurial", "https://bitbucket.org/hfuss/source-import-test") self.assertEqual(source_import.authors_count, 0) self.assertEqual( source_import.authors_url, "https://api.github.com/repos/brix4dayz/source-import-test/import/authors", ) self.assertEqual( source_import.html_url, "https://github.com/brix4dayz/source-import-test/import", ) self.assertEqual( source_import.repository_url, "https://api.github.com/repos/brix4dayz/source-import-test", ) self.assertEqual(source_import.status, "importing") self.assertEqual(source_import.status_text, "Importing...") self.assertEqual( source_import.url, "https://api.github.com/repos/brix4dayz/source-import-test/import", ) self.assertEqual(source_import.vcs, "mercurial") self.assertEqual(source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test") def testCreateRepositoryDispatch(self): with_payload = self.repo.create_repository_dispatch("type", {"foo": "bar"}) self.assertTrue(with_payload) without_payload = self.repo.create_repository_dispatch("type") self.assertTrue(without_payload) @mock.patch("github.PublicKey.encrypt") def testRepoSecrets(self, encrypt): # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" # GitHub will always capitalize the secret name secrets = (("SECRET_NAME_ONE", "secret-value-one"), ("SECRET_NAME_TWO", "secret-value-two")) repo = self.g.get_repo("AndrewJDawes/PyGithub") for matched_repo_secret in secrets: repo.create_secret(matched_repo_secret[0], matched_repo_secret[1]) repo.update() repo_secrets = repo.get_secrets() matched_repo_secrets = [] for matched_repo_secret in secrets: for repo_secret in repo_secrets: # GitHub will always capitalize the secret name, may be best to uppercase test data for comparison if repo_secret.name == matched_repo_secret[0].upper(): matched_repo_secrets.append(repo_secret) break self.assertEqual(len(matched_repo_secrets), len(secrets)) for matched_repo_secret in matched_repo_secrets: matched_repo_secret.delete() def testCodeScanAlerts(self): codescan_alerts = self.repo.get_codescan_alerts() self.assertListKeyEqual( codescan_alerts, lambda c: c.number, [ 6, ], ) codescan_alert = codescan_alerts[0] self.assertEqual(repr(codescan_alert), "CodeScanAlert(number=6)") self.assertEqual(codescan_alert.state, "open") self.assertEqual( codescan_alert.url, "https://api.github.com/repos/jacquev6/PyGithub/code-scanning/alerts/6", ) self.assertEqual( codescan_alert.created_at, datetime(2021, 6, 29, 12, 28, 30, tzinfo=timezone.utc), ) self.assertEqual( codescan_alert.dismissed_at, datetime(2021, 6, 30, 5, 5, 5, tzinfo=timezone.utc), ) self.assertEqual(codescan_alert.dismissed_reason, "Won't tell") dismissed_by = codescan_alert.dismissed_by self.assertEqual(dismissed_by.login, "dismisser.login") instance = codescan_alert.most_recent_instance self.assertEqual( repr(instance), "CodeScanAlertInstance(" 'ref="refs/heads/master", ' 'analysis_key=".github/workflows/codeql-analysis.yml:analyze"' ")", ) self.assertEqual(instance.ref, "refs/heads/master") self.assertEqual(instance.analysis_key, ".github/workflows/codeql-analysis.yml:analyze") self.assertEqual(instance.environment, "{language:python}") self.assertEqual(instance.state, "open") self.assertListEqual(instance.classifications, ["stupid typo"]) self.assertDictEqual(instance.message, {"text": "Awful stuff might happen."}) self.assertEqual(instance.commit_sha, "deadbeef") location = instance.location self.assertEqual( str(location), "tests/ReplayData/Repository.testCodeScanAlerts.txt @ l10:c2-l10:c48", ) self.assertEqual( repr(location), "CodeScanAlertInstanceLocation(" "start_line=10, start_column=2, " 'path="tests/ReplayData/Repository.testCodeScanAlerts.txt", ' "end_line=10, end_column=48" ")", ) self.assertEqual(location.path, "tests/ReplayData/Repository.testCodeScanAlerts.txt") self.assertEqual(location.start_line, 10) self.assertEqual(location.start_column, 2) self.assertEqual(location.end_line, 10) self.assertEqual(location.end_column, 48) rule = codescan_alert.rule self.assertEqual(repr(rule), 'CodeScanRule(name="py/rule-name", id="py/rule-id")') self.assertEqual(rule.id, "py/rule-id") self.assertEqual(rule.name, "py/rule-name") self.assertEqual(rule.security_severity_level, "high") self.assertEqual(rule.severity, "warning") self.assertEqual(rule.description, "Bad practice") tool = codescan_alert.tool self.assertEqual(repr(tool), 'CodeScanTool(version="2.5.7", name="CodeQL", guid=None)') self.assertEqual(tool.guid, None) self.assertEqual(tool.name, "CodeQL") self.assertEqual(tool.version, "2.5.7") instances = list(codescan_alert.get_instances()) self.assertEqual(len(instances), 2) # instance = instances[0] self.assertEqual(instance.ref, "instances[0].ref") self.assertEqual(instance.analysis_key, "instances[0].analysis_key") self.assertEqual(instance.environment, "instances[0].environment") self.assertEqual(instance.state, "instances[0].state") self.assertListEqual(instance.classifications, ["instances[0].classifications"]) self.assertDictEqual(instance.message, {"text": "instances[0].message"}) self.assertEqual(instance.commit_sha, "instances[0].commit_sha") location = instance.location self.assertEqual(location.path, "tests/ReplayData/Repository.testCodeScanAlerts.txt") self.assertEqual(location.start_line, 10) self.assertEqual(location.start_column, 2) self.assertEqual(location.end_line, 10) self.assertEqual(location.end_column, 48) # instance = instances[1] self.assertEqual(instance.ref, "instances[1].ref") self.assertEqual(instance.analysis_key, "instances[1].analysis_key") self.assertEqual(instance.environment, "instances[1].environment") self.assertEqual(instance.state, "instances[1].state") self.assertListEqual(instance.classifications, ["instances[1].classifications"]) self.assertDictEqual(instance.message, {"text": "instances[1].message"}) self.assertEqual(instance.commit_sha, "instances[1].commit_sha") location = instance.location self.assertEqual(location.path, "tests/ReplayData/Repository.testCodeScanAlerts.txt") self.assertEqual(location.start_line, 20) self.assertEqual(location.start_column, 17) self.assertEqual(location.end_line, 20) self.assertEqual(location.end_column, 42) def testCollaborators(self): lyloa = self.g.get_user("Lyloa") self.assertFalse(self.repo.has_in_collaborators(lyloa)) self.repo.add_to_collaborators(lyloa) self.assertTrue(self.repo.has_in_collaborators(lyloa)) collaborators = self.repo.get_collaborators() self.assertListKeyEqual(collaborators, lambda u: u.login, ["jacquev6", "Lyloa"]) jacquev6 = [u for u in collaborators if u.login == "jacquev6"][0] self.assertTrue(jacquev6.permissions.admin, True) self.assertTrue(jacquev6.permissions.pull, True) self.assertTrue(jacquev6.permissions.push, True) self.assertFalse(jacquev6.site_admin) self.repo.remove_from_collaborators(lyloa) self.assertFalse(self.repo.has_in_collaborators(lyloa)) def testCollaboratorPermission(self): self.assertEqual(self.repo.get_collaborator_permission("jacquev6"), "admin") def testAddToCollaboratorsCustomRole(self): lyloa = self.g.get_user("Lyloa") self.repo.add_to_collaborators(lyloa, "custom_role") def testGetPendingInvitations(self): lyloa = self.g.get_user("Lyloa") self.repo.add_to_collaborators(lyloa) invitations = self.repo.get_pending_invitations() self.assertListKeyEqual(invitations, lambda u: u.invitee.login, ["Lyloa"]) def testRemoveInvitation(self): self.repo.remove_invitation(17285388) def testRemoveAutolink(self): self.repo.remove_autolink(209611) def testCollaboratorPermissionNoPushAccess(self): with self.assertRaises(github.GithubException) as raisedexp: self.repo.get_collaborator_permission("lyloa") self.assertEqual(raisedexp.exception.status, 403) self.assertEqual( raisedexp.exception.data, { "documentation_url": "https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level", "message": "Must have push access to view collaborator permission.", }, ) def testCompare(self): comparison = self.repo.compare("v0.6", "v0.7") self.assertEqual(comparison.status, "ahead") self.assertEqual(comparison.ahead_by, 4) self.assertEqual(comparison.behind_by, 0) self.assertEqual( comparison.diff_url, "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.diff", ) self.assertEqual( comparison.html_url, "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7", ) self.assertEqual( comparison.url, "https://api.github.com/repos/jacquev6/PyGithub/compare/v0.6...v0.7", ) self.assertEqual( comparison.patch_url, "https://github.com/jacquev6/PyGithub/compare/v0.6...v0.7.patch", ) self.assertEqual( comparison.permalink_url, "https://github.com/jacquev6/PyGithub/compare/jacquev6:4303c5b...jacquev6:ecda065", ) self.assertEqual(comparison.total_commits, 4) self.assertListKeyEqual( comparison.files, lambda f: f.filename, [ "ReferenceOfClasses.md", "github/Github.py", "github/Requester.py", "setup.py", ], ) self.assertEqual(comparison.base_commit.sha, "4303c5b90e2216d927155e9609436ccb8984c495") self.assertListKeyEqual( comparison.commits, lambda c: c.sha, [ "5bb654d26dd014d36794acd1e6ecf3736f12aad7", "cb0313157bf904f2d364377d35d9397b269547a5", "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", ], ) def testCompareCommitPagination(self): gh = github.Github( auth=self.oauth_token, per_page=4, retry=self.retry, pool_size=self.pool_size, seconds_between_requests=self.seconds_between_requests, seconds_between_writes=self.seconds_between_writes, ) repo = gh.get_repo("PyGithub/PyGithub") comparison = repo.compare("v1.54", "v1.54.1") self.assertEqual(comparison.status, "ahead") self.assertEqual(comparison.ahead_by, 10) self.assertEqual(comparison.behind_by, 0) self.assertEqual(comparison.total_commits, 10) self.assertEqual(len(comparison.files), 228) self.assertEqual(comparison.commits.totalCount, 10) self.assertListKeyEqual( comparison.commits, lambda c: c.sha, [ "fab682a5ccfc275c31ec37f1f541254c7bd780f3", "9ee3afb1716c559a0b3b44e097c05f4b14ae2ab8", "a806b5233f6423e0f8dacc4d04b6d81a72689bed", "63e4fae997a9a5dc8c2b56907c87c565537bb28f", "82c349ce3e1c556531110753831b3133334c19b7", "2432cffd3b2f1a8e0b6b96d69b3dd4ded148a9f7", "e113e37de1ec687c68337d777f3629251b35ab28", "f299699ccd75910593d5ddf7cc6212f70c5c28b1", "31a1c007808a4205bdae691385d2627c561e69ed", "34d097ce473601624722b90fc5d0396011dd3acb", ], ) def testGetComments(self): self.assertListKeyEqual( self.repo.get_comments(), lambda c: c.body, [ "probably a noob question: does this completion refer to autocompletion in IDE's/editors? \nI have observed that this is pretty erratic sometimes. I'm using PyDev+Eclipse.\nFor example, in the tutorial from the readme, `g.get_u` gets autocompleted correctly, but `g.get_user().get_r` (or any method or attribute applicable to NamedUsers/AuthenticatedUser, really) does not show autocompletion to `g.get_user().get_repo()`. Is that by design? It makes exploring the library/API a bit cumbersome. ", "No, it has nothing to do with auto-completion in IDEs :D\n\nGithub API v3 sends only the main part of objects in reply to some requests. So, if the user wants an attribute that has not been received yet, I have to do another request to complete the object.\n\nYet, in version 1.0 (see the milesone), my library will be much more readable for IDEs and their auto-completion mechanisms, because I am giving up the meta-description that I used until 0.6, and I'm now generating much more traditional code, that you will be able to explore as if it was written manually.\n\nIf you want to take the time to open an issue about auto-completion in IDEs, I'll deal with it in milestone 1.0.\n\nThanks !", "Ah, thanks for the clarification. :blush:\n\nI made issue #27 for the autocompletion. I already suspected something like this meta-description magic, since I tried to read some of the code and it was pretty arcane. I attributed that to my pythonic noobness, though. Thank you. ", "Comment created by PyGithub", ], ) def testGetCommits(self): self.assertListKeyBegin( self.repo.get_commits(), lambda c: c.sha, [ "ecda065e01876209d2bdf5fe4e91cee8ffaa9ff7", "0cec0d25e606c023a62a4fc7cdc815309ebf6d16", "cb0313157bf904f2d364377d35d9397b269547a5", "5bb654d26dd014d36794acd1e6ecf3736f12aad7", "4303c5b90e2216d927155e9609436ccb8984c495", "2a7e80e6421c5d4d201d60619068dea6bae612cb", "0af24499a98e85f8ab2191898e8b809e5cebd4c5", "e5ae923a68a9ae295ce5aa20b1227253de60e918", "2f64b625f7e2afc9bef61d0decb459e2ef65c550", "590798d349cba7de6e83b43aa5d4f8b0a38e685d", "e7dca9143a23b8e2045a4a910a4a329007b10086", "ab3f9b422cb3043d35cf6002fc9c042f8ead8c2a", "632d8b63c32a2b79e87eb3b93e1ad228724de4bd", "64c6a1e975e61b9c1449bed016cd19f33ee4b1c5", "99963536fc81db3b9986c761b9dd08de22089aa2", "8d57522bbd15d1fb6b616fae795cd8721deb1c4d", "1140a91f3e45d09bc15463724f178a7ebf8e3149", "936f4a97f1a86392637ec002bbf89ff036a5062d", "e10470481795506e2c232720e2a9ecf588c8b567", "e456549e5265406f8090ae5145255c8ca9ea5e4e", "a91131be42eb328ae030f584af500f56aa08424b", "2469c6e1aeb7919126a8271f6980b555b167e8b0", "a655d0424135befd3a0d53f3f7eff2d1c754854f", "ce62e91268aa34dad0ba0dbee4769933e3a71e50", "1c88ee221b7f995855a1fdfac7d0ba19db918739", "bd1a5dff3c547c634b2d89f5847218820e343883", "b226b5b4e2f44107dde674e7a5d3e88d4e3518df", "25dbd4053e982402c7d92139f167dbe46008c932", "a0cc821c1beada4aa9ca0d5218664c5372720936", "c1440bdf20bfeb62684c6d1779448719dce9d2df", "1095d304b7fab3818dcb4c42093c8c56d3ac05e4", "bd39726f7cf86ea7ffb33b5718241fdab5fc8f53", "1d2b27824d20612066d84be42d6691c66bb18ef4", "6af2bfd0d46bc0eeb8c37b85c7b3003e0e4ae297", "a475d685d8ae709095d09094ea0962ac182d33f0", "a85de99ea5b5e7b38bd68e076d09c49207b8687e", "d24cf209ddd1758188c5f35344f76df818d09a46", "0909fec395bb1f97e2580d6a029cfc64b352aff9", "6e421e9e85e12008758870bc046bc2c6120af72a", "32ed0ebc377efbed5b482b3d49ff54bf1715d55a", "8213df1d744f251aa8e52229643a9f6ce352f3c0", "69cc298fd159f19eb204dd09f17d31dc4abc3d41", "85eef756353e13efcb24c726320cd2617c2a7bd8", "50ac55b25ceba555b84709839f80447552450697", "767d75a580279e457f9bc52bc308a17ff8ea0509", "75e72ffa3066693291f7da03070666e8f885097a", "504047e218e6b34a3828ccc408431634f17b9504", "960db1d5c9853e9f5fbbc9237c2c166ceef1f080", "877dde23e140bbf038f9a2d8f0f07b4e3a965c61", "1c95ddfa09ec0aa1f07ee9ad50a77be1dd74b55e", "99564c1cab139d1e4678f5f83f60d26f1210db7e", "231926207709ceaa61e87b64e34e17d85adecd9c", "fb722625dddb9a32f75190723f7da12683b7c4b2", "cab9d71603e127bdd1f600a759dccea1781fa1ab", "e648e5aeb5edc1fbf83e9d37d2a3cb57c005019a", "4a5cf98e7f959f1b5d9af484760c25cd27d9180d", "5d1add448e0b0b1dadb8c6094a9e5e19b255f67e", "0d9fc99a4b5d1ec6473c9c81c888917c132ffa65", "b56aa09011378b014221f86dffb8304957a9e6bd", "3e8169c0a98ce1e2c6a32ae1256ae0f735065df5", "378558f6cac6183b4a7100c0ce5eaad1cfff6717", "58b4396aa0e7cb72911b75cb035798143a06e0ee", "a3be28756101370fbc689eec3a7825c4c385a6c9", "3d6bd49ce229243fea4bb46a937622d0ec7d4d1c", "58cb0dbdef9765e0e913c726f923a47315aaf80e", "7b7ac20c6fa27f72a24483c73ab1bf4deffc89f0", "97f308e67383368a2d15788cac28e126c8528bb2", "fc33a6de4f0e08d7ff2de05935517ec3932d212e", "cc6d0fc044eadf2e6fde5da699f61654c1e691f3", "2dd71f3777b87f2ba61cb20d2c67f10401e3eb2c", "366ca58ca004b9129f9d435db8204ce0f5bc57c3", "0d3b3ffd1e5c143af8725fdee808101f626f683d", "157f9c13275738b6b39b8d7a874f5f0aee47cb18", ], ) def testGetCommitsWithArguments(self): self.assertListKeyEqual( self.repo.get_commits("topic/RewriteWithGeneratedCode", "codegen/GenerateCode.py"), lambda c: c.sha, [ "de386d5dc9cf103c90c4128eeca0e6abdd382065", "5b44982f6111bff2454243869df2e1c3086ccbba", "d6835ff949141957a733c8ddfa147026515ae493", "075d3d961d4614a2a0835d5583248adfc0687a7d", "8956796e7f462a49f499eac52fab901cdb59abdb", "283da5e7de6a4a3b6aaae7045909d70b643ad380", "d631e83b7901b0a0b6061b361130700a79505319", ], ) def testGetCommitsWithSinceUntil(self): self.assertListKeyEqual( self.repo.get_commits( since=datetime(2013, 3, 1), until=datetime(2013, 3, 31), ), lambda c: c.sha, [ "db5560bd658b5d8057a864f7037ace4d5f618f1b", "f266fed520fea4f683caabe0b38e1f758cfc5cff", "dff094650011398fd8f0a57bf2668a066fb2cbcb", "c1d747a9133a1c6cae1f0e11105a5f490f65fda6", "0bc368973acfb50a531329b6c196ba92e0a81890", "7b3e4c15ed6182963d66ffa9f0522acd0765275c", "4df3a7eb47888f38c4c6dae50573f030a0a3f1e1", "e0db8cad4ec01c65e5e0eb50e11765e425e88ef9", "1c47be4e895b823baf907b25c647e43ab63c16dd", "8a9afbb1aa36c6ba04142c6e6c1cfbd7de982a6a", "1c67359a318f05e50bf457818e1983ce95aa5946", "1d18bd66f3a4a4225435bd38df04b8a227b5e821", "b9d71fa787a2ffb99b6631e4bd6df932a4d4adbb", "f5d8e221d116b74a200d87afca32247f01204ba1", "dc96fef052f2b5c6adb34da65169e8df3f35f611", "c85af79db11ed1d2f93261ea4069a23ff1709125", "0dd1adb4f06f45d554d12083b312fcdb6f6be8d1", "b7e4000450e89b8c6e947e3a1e52fb06da7c9621", "1d9ad14fa918866c418067e774f65cede8e38682", "1bb05fef01d0a040cb2b931a4d44392784a2f0c1", "d9b29851ddccc907f71f1ae662e57f2cd7c7dc71", "f962bc71fee609cd54fe69c956c8b81703d2c19a", "7a9c0b916c632be8d6a65bc1b6f558508f04bb22", "82ce7b1ee30d308b48bdac6d8737dbca70500462", "1e99e7d5b21c71bf68cc5cc21faec30ee603b8b8", "a397fac6db9f87a903ec3ede9643cb2b4224ed82", "109495175e926731703a55cafd8b542a07366513", "da6bbdb69485fc3256030d8296589d4c2fb5df21", "34c18342dcce9697abc6f522c3506485202e6e7e", "ee29deddd27480401db484733ecde9e7b1df5eda", "0901df1a2bed3f993cfe6e0d4cff5923bbf6ce32", "edcf40bc7f25d1aff5c404406fbb37ad1bcf691e", "f25c54e1d4eefb11c18f3de85270a4b19edea3ce", "23d668f11bdd806a871e0979bf5295d001f66ef2", "50a243671f1fa139cb1186c4a44c1e96b8cd5749", "6a3a384fd0decac1203db6c2bddc58039b0390bc", "82f5b4c61f86ae8c7cc85a31cb1a31180eeae32f", "6ac783974d3985dd0c162c1e8d1150615cc0082e", "0f9bb5d9fd2dcfbf03f094362e86323c9ef915e6", "e25a6a49d1ab1a10c84db9b6722a6186ff6dfcbd", "4f1780f427eba400cbc06897e69eda0ecdecd887", "28648a51a15e430b85d6fe8f2514e1cb06bc76b8", "a39f421ca24bd7aae984f8703159c7e30798a121", "86fe370b97b62548317cb35bc02ece3fabb7fa03", "03a256a4052cacea998d8205a83d5b5465f31e18", "9e6b086c2db5e4884484a04934f6f2e53e3f441b", "0ddb34d987b5a03813fdfa2fac13c933834a4804", ], ) def testGetCommitsWithAuthor(self): self.g.per_page = 5 akfish = self.g.get_user("AKFish") self.assertListKeyBegin( self.repo.get_commits(author=self.user), lambda c: c.sha, ["54f718a15770579a37ffbe7ae94ad30003407786"], ) self.assertListKeyBegin( self.repo.get_commits(author=akfish), lambda c: c.sha, ["38b137fb37c0fdc74f8802a4184518e105db9121"], ) self.assertListKeyBegin( self.repo.get_commits(author="m.ki2@laposte.net"), lambda c: c.sha, ["ab674dfcbc86c70bc32d9ecbe171b48a5694c337"], ) def testGetDownloads(self): self.assertListKeyEqual(self.repo.get_downloads(), lambda d: d.id, [245143]) def testGetEvents(self): self.assertListKeyBegin( self.repo.get_events(), lambda e: e.type, [ "DownloadEvent", "DownloadEvent", "PushEvent", "IssuesEvent", "MemberEvent", "MemberEvent", ], ) def testGetForks(self): self.assertListKeyEqual(self.repo.get_forks(), lambda r: r.owner.login, ["abersager"]) def testCreateFork(self): self.assertEqual(self.repo.create_fork("prtg-dev").full_name, "prtg-dev/PyGithub") def testCreateForkOrg(self): c = self.g.get_organization("prtg-dev") self.assertEqual(self.repo.create_fork(c).full_name, "prtg-dev/PyGithub") def testGetGitRefs(self): self.assertListKeyEqual( self.repo.get_git_refs(), lambda r: r.ref, [ "refs/heads/develop", "refs/heads/master", "refs/heads/topic/DependencyGraph", "refs/heads/topic/RewriteWithGeneratedCode", "refs/tags/v0.1", "refs/tags/v0.2", "refs/tags/v0.3", "refs/tags/v0.4", "refs/tags/v0.5", "refs/tags/v0.6", "refs/tags/v0.7", ], ) def testGetGitRef(self): self.assertTrue(self.g.FIX_REPO_GET_GIT_REF) self.assertEqual( self.repo.get_git_ref("heads/master").object.sha, "31110327ec45f3138e58ed247b2cf420fee481ec", ) def testGetGitRefWithIssue102Reverted(self): self.g.FIX_REPO_GET_GIT_REF = False self.assertFalse(self.g.FIX_REPO_GET_GIT_REF) self.assertEqual( self.repo.get_git_ref("refs/heads/master").object.sha, "31110327ec45f3138e58ed247b2cf420fee481ec", ) self.g.FIX_REPO_GET_GIT_REF = True self.assertTrue(self.g.FIX_REPO_GET_GIT_REF) def testGetGitTreeWithRecursive(self): tree = self.repo.get_git_tree("f492784d8ca837779650d1fb406a1a3587a764ad", True) self.assertEqual(len(tree.tree), 90) self.assertEqual(tree.tree[50].path, "github/GithubObjects/Gist.py") def testGetHooks(self): self.assertListKeyEqual(self.repo.get_hooks(), lambda h: h.id, [257993]) def testGetHookDelivery(self): delivery = self.repo.get_hook_delivery(257993, 12345) self.assertEqual(delivery.id, 12345) self.assertEqual(delivery.guid, "abcde-12345") self.assertEqual( delivery.delivered_at, datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(delivery.redelivery, False) self.assertEqual(delivery.duration, 0.27) self.assertEqual(delivery.status, "OK") self.assertEqual(delivery.status_code, 200) self.assertEqual(delivery.event, "issues") self.assertEqual(delivery.action, "opened") self.assertEqual(delivery.installation_id, 123) self.assertEqual(delivery.repository_id, 456) self.assertEqual(delivery.url, "https://www.example-webhook.com") self.assertIsInstance(delivery.request, github.HookDelivery.HookDeliveryRequest) self.assertEqual(delivery.request.headers, {"content-type": "application/json"}) self.assertEqual(delivery.request.payload, {"action": "opened"}) self.assertIsInstance(delivery.response, github.HookDelivery.HookDeliveryResponse) self.assertEqual(delivery.response.headers, {"content-type": "text/html;charset=utf-8"}) self.assertEqual(delivery.response.payload, "ok") def testGetHookDeliveries(self): deliveries = list(self.repo.get_hook_deliveries(257993)) self.assertEqual(len(deliveries), 1) self.assertEqual(deliveries[0].id, 12345) self.assertEqual(deliveries[0].guid, "abcde-12345") self.assertEqual( deliveries[0].delivered_at, datetime(2012, 5, 27, 6, 0, 32, tzinfo=timezone.utc), ) self.assertEqual(deliveries[0].redelivery, False) self.assertEqual(deliveries[0].duration, 0.27) self.assertEqual(deliveries[0].status, "OK") self.assertEqual(deliveries[0].status_code, 200) self.assertEqual(deliveries[0].event, "issues") self.assertEqual(deliveries[0].action, "opened") self.assertEqual(deliveries[0].installation_id, 123) self.assertEqual(deliveries[0].repository_id, 456) self.assertEqual(deliveries[0].url, "https://www.example-webhook.com") def testGetIssues(self): self.assertListKeyEqual( self.repo.get_issues(), lambda i: i.id, [ 4769659, 4639931, 4452000, 4356743, 3716033, 3715946, 3643837, 3628022, 3624595, 3624570, 3624561, 3624556, 3619973, 3527266, 3527245, 3527231, ], ) def testGetIssuesWithArguments(self): milestone = self.repo.get_milestone(3) user = self.g.get_user("jacquev6") otherUser = self.g.get_user("Lyloa") bug = self.repo.get_label("Bug") self.assertListKeyEqual( self.repo.get_issues(milestone, "closed"), lambda i: i.id, [3624472, 3620132, 3619658, 3561926], ) self.assertListKeyEqual(self.repo.get_issues(labels=[bug]), lambda i: i.id, [4780155]) self.assertListKeyEqual(self.repo.get_issues(labels=[bug.name]), lambda i: i.id, [4780155]) self.assertListKeyEqual( self.repo.get_issues(assignee=user, sort="comments", direction="asc"), lambda i: i.id, [ 4793106, 3527231, 3527266, 3624556, 4793216, 3619973, 3624595, 4452000, 3643837, 3628022, 3527245, 4793162, 4356743, 4780155, ], ) self.assertListKeyEqual( self.repo.get_issues(since=datetime(2012, 5, 28, 23, 0, 0, tzinfo=timezone.utc)), lambda i: i.id, [4793216, 4793162, 4793106, 3624556, 3619973, 3527266], ) self.assertListKeyEqual(self.repo.get_issues(mentioned=otherUser), lambda i: i.id, [4793162]) def testGetIssuesWithWildcards(self): self.assertListKeyEqual( self.repo.get_issues(milestone="*"), lambda i: i.id, [4809786, 4793216, 4789817, 4452000, 3628022, 3624595, 3619973, 3527231], ) self.assertListKeyEqual( self.repo.get_issues(milestone="none"), lambda i: i.id, [4823331, 4809803, 4809778, 4793106, 3643837, 3527245], ) self.assertListKeyEqual( self.repo.get_issues(assignee="*"), lambda i: i.id, [ 4823331, 4809803, 4809786, 4809778, 4793216, 4793106, 4789817, 4452000, 3643837, 3628022, 3624595, 3527245, 3527231, ], ) self.assertListKeyEqual(self.repo.get_issues(assignee="none"), lambda i: i.id, [3619973]) def testGetKeys(self): self.assertListKeyEqual(self.repo.get_keys(), lambda k: k.title, ["Key added through PyGithub"]) def testGetLabels(self): self.assertListKeyEqual( self.repo.get_labels(), lambda lb: lb.name, [ "Refactoring", "Public interface", "Functionalities", "Project management", "Bug", "Question", ], ) def testGetLanguages(self): self.assertEqual(self.repo.get_languages(), {"Python": 127266, "Shell": 673}) def testGetMilestones(self): self.assertListKeyEqual(self.repo.get_milestones(), lambda m: m.id, [93547]) def testGetMilestonesWithArguments(self): self.assertListKeyEqual( self.repo.get_milestones("closed", "due_date", "asc"), lambda m: m.id, [93546, 95354, 108652, 124045], ) def testGetIssuesEvents(self): self.assertListKeyBegin( self.repo.get_issues_events(), lambda e: e.event, ["assigned", "subscribed", "closed", "assigned", "closed"], ) def testGetNetworkEvents(self): self.assertListKeyBegin( self.repo.get_network_events(), lambda e: e.type, [ "DownloadEvent", "DownloadEvent", "PushEvent", "IssuesEvent", "MemberEvent", ], ) def testGetTeams(self): repo = self.g.get_organization("BeaverSoftware").get_repo("FatherBeaver") self.assertListKeyEqual(repo.get_teams(), lambda t: t.name, ["Members"]) def testGetWatchers(self): self.assertListKeyEqual( self.repo.get_watchers(), lambda u: u.login, [ "Stals", "att14", "jardon-u", "huxley", "mikofski", "L42y", "fanzeyi", "abersager", "waylan", "adericbourg", "tallforasmurf", "pvicente", "roskakori", "michaelpedersen", "BeaverSoftware", ], ) def testGetWorkflows(self): workflows = self.g.get_repo("PyGithub/PyGithub").get_workflows() self.assertListKeyEqual(workflows, lambda w: w.name, ["check", "Publish to PyPI"]) def testGetWorkflowId(self): workflows = self.g.get_repo("PyGithub/PyGithub").get_workflow("1122712") self.assertEqual(workflows.id, 1122712) def testGetWorkflowRuns(self): self.assertListKeyEqual( self.g.get_repo("PyGithub/PyGithub").get_workflow_runs(), lambda r: r.id, [110932306, 110932159, 110932072, 110286191, 110278769], ) def testGetWorkflowRunsCreated(self): self.assertListKeyEqual( self.g.get_repo("PyGithub/PyGithub").get_workflow_runs(created="2022-12-24"), lambda r: r.id, [3770390952], ) def testGetSourceImport(self): import_repo = self.g.get_user("brix4dayz").get_repo("source-import-test") source_import = import_repo.get_source_import() self.assertEqual(source_import.authors_count, 1) self.assertEqual( source_import.authors_url, "https://api.github.com/repos/brix4dayz/source-import-test/import/authors", ) self.assertEqual(source_import.has_large_files, False) self.assertEqual( source_import.html_url, "https://github.com/brix4dayz/source-import-test/import", ) self.assertEqual(source_import.large_files_count, 0) self.assertEqual(source_import.large_files_size, 0) self.assertEqual( source_import.repository_url, "https://api.github.com/repos/brix4dayz/source-import-test", ) self.assertEqual(source_import.status, "complete") self.assertEqual(source_import.status_text, "Done") self.assertEqual( source_import.url, "https://api.github.com/repos/brix4dayz/source-import-test/import", ) self.assertEqual(source_import.use_lfs, "undecided") self.assertEqual(source_import.vcs, "mercurial") self.assertEqual(source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test") def testGetStargazers(self): self.assertListKeyEqual( self.repo.get_stargazers(), lambda u: u.login, [ "Stals", "att14", "jardon-u", "huxley", "mikofski", "L42y", "fanzeyi", "abersager", "waylan", "adericbourg", "tallforasmurf", "pvicente", "roskakori", "michaelpedersen", "stefanfoulis", "equus12", "JuRogn", "joshmoore", "jsilter", "dasapich", "ritratt", "hcilab", "vxnick", "pmuilu", "herlo", "malexw", "ahmetvurgun", "PengGu", "cosmin", "Swop", "kennethreitz", "bryandyck", "jason2506", "zsiciarz", "waawal", "gregorynicholas", "sente", "richmiller55", "thouis", "mazubieta", "michaelhood", "engie", "jtriley", "oangeor", "coryking", "noddi", "alejo8591", "omab", "Carreau", "bilderbuchi", "schwa", "rlerallut", "PengHub", "zoek1", "xobb1t", "notgary", "hattya", "ZebtinRis", "aaronhall", "youngsterxyf", "ailling", "gregwjacobs", "n0rmrx", "awylie", "firstthumb", "joshbrand", "berndca", ], ) def testGetStargazersWithDates(self): repo = self.g.get_user("danvk").get_repo("comparea") stargazers = repo.get_stargazers_with_dates() self.assertListKeyEqual( stargazers, lambda stargazer: (stargazer.starred_at, stargazer.user.login), [ ( datetime(2014, 8, 13, 19, 22, 5, tzinfo=timezone.utc), "sAlexander", ), ( datetime(2014, 10, 15, 5, 2, 30, tzinfo=timezone.utc), "ThomasG77", ), ( datetime(2015, 4, 14, 15, 22, 40, tzinfo=timezone.utc), "therusek", ), ( datetime(2015, 4, 29, 0, 9, 40, tzinfo=timezone.utc), "athomann", ), ( datetime(2015, 4, 29, 14, 26, 46, tzinfo=timezone.utc), "jcapron", ), ( datetime(2015, 5, 9, 19, 14, 45, tzinfo=timezone.utc), "JoePython1", ), ], ) self.assertEqual(repr(stargazers[0]), 'Stargazer(user="sAlexander")') def testGetSubscribers(self): self.assertListKeyEqual( self.repo.get_subscribers(), lambda u: u.login, [ "jacquev6", "equus12", "bilderbuchi", "hcilab", "hattya", "firstthumb", "gregwjacobs", "sagarsane", "liang456", "berndca", "Lyloa", ], ) def testCreatePull(self): pull = self.repo.create_pull( title="Pull request created by PyGithub", body="Body of the pull request", base="topic/RewriteWithGeneratedCode", head="BeaverSoftware:master", draft=False, maintainer_can_modify=True, ) self.assertEqual(pull.id, 1436215) def testCreateProject(self): project = self.repo.create_project("Project created by PyGithub", "Body of the project") self.assertEqual(project.id, 2013820) def testCreatePullFromIssue(self): issue = self.repo.get_issue(32) pull = self.repo.create_pull("topic/RewriteWithGeneratedCode", "BeaverSoftware:master", issue=issue) self.assertEqual(pull.id, 1436310) def testGetPulls(self): self.assertListKeyEqual(self.repo.get_pulls(), lambda p: p.id, [1436310]) def testGetPullsWithArguments(self): self.assertListKeyEqual(self.repo.get_pulls("closed"), lambda p: p.id, [1448168, 1436310, 1436215]) def testGetAutolinks(self): self.assertListKeyEqual( self.repo.get_autolinks(), lambda i: i.id, [ 209614, 209611, ], ) def testLegacySearchIssues(self): issues = self.repo.legacy_search_issues("open", "search") self.assertListKeyEqual(issues, lambda i: i.title, ["Support new Search API"]) # Attributes retrieved from legacy API without lazy completion call self.assertEqual(issues[0].number, 49) self.assertEqual( issues[0].created_at, datetime(2012, 6, 21, 12, 27, 38, tzinfo=timezone.utc), ) self.assertEqual(issues[0].comments, 4) self.assertEqual(issues[0].body[:20], "New API ported from ") self.assertEqual(issues[0].title, "Support new Search API") self.assertEqual( issues[0].updated_at, datetime(2012, 6, 28, 21, 13, 25, tzinfo=timezone.utc), ) self.assertEqual(issues[0].user.login, "kukuts") self.assertEqual(issues[0].user.url, "/users/kukuts") self.assertListKeyEqual(issues[0].labels, lambda lb: lb.name, ["Functionalities", "RequestedByUser"]) self.assertEqual(issues[0].state, "open") def testMarkNotificationsAsRead(self): repo = self.g.get_user().get_repo("PyGithub") repo.mark_notifications_as_read(datetime(2018, 10, 18, 18, 19, 43, 0)) def testAssignees(self): lyloa = self.g.get_user("Lyloa") jacquev6 = self.g.get_user("jacquev6") self.assertTrue(self.repo.has_in_assignees(jacquev6)) self.assertFalse(self.repo.has_in_assignees(lyloa)) self.repo.add_to_collaborators(lyloa) self.assertTrue(self.repo.has_in_assignees(lyloa)) self.assertListKeyEqual(self.repo.get_assignees(), lambda u: u.login, ["jacquev6", "Lyloa"]) self.repo.remove_from_collaborators(lyloa) self.assertFalse(self.repo.has_in_assignees(lyloa)) def testGetContents(self): self.assertEqual(len(self.repo.get_readme().content), 10212) self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md").content), 38121) def testGetContentsDir(self): contents = self.repo.get_contents("") self.assertTrue(isinstance(contents, list)) self.assertEqual(len(contents), 14) def testGetContentsDirWithSlash(self): contents = self.repo.get_contents("/") self.assertTrue(isinstance(contents, list)) self.assertEqual(len(contents), 14) def testGetContentsWithRef(self): self.assertEqual( len(self.repo.get_readme(ref="refs/heads/topic/ExperimentOnDocumentation").content), 6747, ) self.assertEqual( len( self.repo.get_contents( "doc/ReferenceOfClasses.md", ref="refs/heads/topic/ExperimentOnDocumentation", ).content ), 43929, ) def testCreateDeployment(self): deployment = self.repo.create_deployment( ref="743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5", task="deploy", auto_merge=False, required_contexts=[], payload={"test": True}, environment="test", description="Test deployment", transient_environment=True, production_environment=False, ) self.assertEqual(deployment.id, 263877258) def testGetDeployments(self): deployments = self.repo.get_deployments() self.assertListKeyEqual(deployments, lambda d: d.id, [263877258, 262350588]) def testCreateFile(self): newFile = "doc/testCreateUpdateDeleteFile.md" content = b"Hello world" author = github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00") self.assertEqual(repr(author), 'InputGitAuthor(name="Enix Yu")') self.repo.create_file( path=newFile, message="Create file for testCreateFile", content=content, branch="master", committer=author, author=author, ) def testUpdateFile(self): updateFile = "doc/testCreateUpdateDeleteFile.md" content = "Hello World" sha = self.repo.get_contents(updateFile).sha self.repo.update_file( path=updateFile, message="Update file for testUpdateFile", content=content, sha=sha, branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"), author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"), ) def testDeleteFile(self): deleteFile = "doc/testCreateUpdateDeleteFile.md" sha = self.repo.get_contents(deleteFile).sha self.repo.delete_file( path=deleteFile, message="Delete file for testDeleteFile", sha=sha, branch="master", ) def testGetArchiveLink(self): self.assertEqual( self.repo.get_archive_link("tarball"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/master", ) self.assertEqual( self.repo.get_archive_link("zipball"), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master", ) self.assertEqual( self.repo.get_archive_link("zipball", "master"), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master", ) self.assertEqual( self.repo.get_archive_link("tarball", "develop"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/develop", ) def testGetBranch(self): branch = self.repo.get_branch("develop") self.assertEqual(branch.commit.sha, "03058a36164d2a7d946db205f25538434fa27d94") def testRenameBranchObject(self): branch = self.repo.get_branch("neat-new-feature") self.assertTrue(self.repo.rename_branch(branch, "terrible-idea")) def testRenameBranchString(self): self.assertTrue(self.repo.rename_branch("neat-new-feature", "terrible-idea")) def testMergeWithoutMessage(self): commit = self.repo.merge("branchForBase", "branchForHead") self.assertEqual(commit.commit.message, "Merge branchForHead into branchForBase") def testMergeWithMessage(self): commit = self.repo.merge("branchForBase", "branchForHead", "Commit message created by PyGithub") self.assertEqual(commit.commit.message, "Commit message created by PyGithub") def testMergeWithNothingToDo(self): commit = self.repo.merge("branchForBase", "branchForHead", "Commit message created by PyGithub") self.assertEqual(commit, None) def testMergeWithConflict(self): with self.assertRaises(github.GithubException) as raisedexp: self.repo.merge("branchForBase", "branchForHead") self.assertEqual(raisedexp.exception.status, 409) self.assertEqual(raisedexp.exception.data, {"message": "Merge conflict"}) def testGetIssuesComments(self): self.assertListKeyEqual( self.repo.get_issues_comments()[:40], lambda c: c.id, [ 5168757, 5181640, 5183010, 5186061, 5226090, 5449237, 5518272, 5547576, 5780183, 5781803, 5820199, 5820912, 5924198, 5965724, 5965812, 5965891, 5966555, 5966633, 5981084, 5981232, 5981409, 5981451, 5991965, 6019700, 6088432, 6293572, 6305625, 6357374, 6357422, 6447481, 6467193, 6467312, 6467642, 6481200, 6481392, 6556134, 6557261, 6568164, 6568181, 6568553, ], ) self.assertListKeyEqual( self.repo.get_issues_comments(sort="created", direction="asc")[:40], lambda c: c.id, [ 5168757, 5181640, 5183010, 5186061, 5226090, 5449237, 5518272, 5547576, 5780183, 5781803, 5820199, 5820912, 5924198, 5965724, 5965812, 5965891, 5966555, 5966633, 5981084, 5981232, 5981409, 5981451, 5991965, 6019700, 6088432, 6293572, 6305625, 6357374, 6357422, 6447481, 6467193, 6467312, 6467642, 6481200, 6481392, 6556134, 6557261, 6568164, 6568181, 6568553, ], ) self.assertListKeyEqual( self.repo.get_issues_comments(since=datetime(2012, 5, 28, 23, 0, 0))[:40], lambda c: c.id, [ 5981084, 5981232, 5981409, 5981451, 5991965, 6019700, 6088432, 6293572, 6305625, 6357374, 6357422, 6447481, 6467193, 6467312, 6467642, 6481200, 6481392, 6556134, 6557261, 6568164, 6568181, 6568553, 6640187, 6640189, 6641223, 6673380, 6710355, 6727553, 6727659, 6727848, 6728069, 6728241, 6728370, 6886561, 6972414, 6994436, 7060818, 7060993, 7211543, 7407798, ], ) def testGetPullsComments(self): self.assertListKeyEqual(self.repo.get_pulls_comments(), lambda c: c.id, [1580134]) self.assertListKeyEqual( self.repo.get_pulls_comments(sort="created", direction="asc"), lambda c: c.id, [1580134], ) self.assertListKeyEqual( self.repo.get_pulls_comments(since=datetime(2012, 5, 28, 23, 0, 0)), lambda c: c.id, [1580134], ) def testSubscribePubSubHubbub(self): self.repo.subscribe_to_hub("push", "http://requestb.in/1bc1sc61", "my_secret") def testBadSubscribePubSubHubbub(self): with self.assertRaises(github.GithubException) as raisedexp: self.repo.subscribe_to_hub("non-existing-event", "http://requestb.in/1bc1sc61") self.assertEqual(raisedexp.exception.status, 422) self.assertEqual(raisedexp.exception.data, {"message": 'Invalid event: "non-existing-event"'}) def testUnsubscribePubSubHubbub(self): self.repo.unsubscribe_from_hub("push", "http://requestb.in/1bc1sc61") def testStatisticsContributors(self): stats = self.repo.get_stats_contributors() seenJacquev6 = False for s in stats: adTotal = 0 total = 0 for w in s.weeks: total += w.c adTotal += w.a + w.d self.assertEqual(total, s.total) if s.author.login == "jacquev6": seenJacquev6 = True self.assertEqual(adTotal, 282147) self.assertEqual( s.weeks[0].w, datetime(2012, 2, 12, tzinfo=timezone.utc), ) self.assertTrue(seenJacquev6) def testStatisticsCommitActivity(self): stats = self.repo.get_stats_commit_activity() self.assertEqual( stats[0].week, datetime(2012, 11, 18, 0, 0, tzinfo=timezone.utc), ) self.assertEqual(stats[0].total, 29) self.assertEqual(stats[0].days, [0, 7, 3, 9, 7, 3, 0]) def testStatisticsCodeFrequency(self): stats = self.repo.get_stats_code_frequency() self.assertEqual( stats[0].week, datetime(2012, 2, 12, 0, 0, tzinfo=timezone.utc), ) self.assertEqual(stats[0].additions, 3853) self.assertEqual(stats[0].deletions, -2098) def testStatisticsParticipation(self): stats = self.repo.get_stats_participation() self.assertEqual( stats.owner, [ 1, 36, 8, 0, 0, 8, 18, 0, 0, 0, 0, 7, 20, 6, 9, 0, 4, 11, 20, 16, 0, 3, 0, 16, 0, 0, 6, 1, 4, 0, 1, 6, 0, 0, 12, 10, 0, 0, 0, 1, 44, 0, 20, 10, 0, 0, 0, 0, 0, 10, 0, 0, ], ) self.assertEqual( stats.all, [ 4, 36, 8, 0, 0, 10, 20, 0, 0, 0, 0, 11, 20, 6, 9, 0, 4, 14, 21, 16, 0, 3, 0, 20, 0, 0, 8, 1, 9, 16, 1, 15, 1, 0, 12, 12, 0, 4, 6, 15, 116, 20, 20, 11, 0, 0, 0, 0, 0, 10, 0, 0, ], ) def testStatisticsPunchCard(self): stats = self.repo.get_stats_punch_card() self.assertEqual(stats.get(4, 12), 7) self.assertEqual(stats.get(6, 18), 2) def testGetLicense(self): self.assertEqual(len(self.repo.get_license().content), 47646) def testGetTopics(self): topic_list = self.repo.get_topics() topic = "github" self.assertIn(topic, topic_list) def testReplaceTopics(self): self.repo.replace_topics(["github", "testing"]) def testGetRepositoryWith301Redirect(self): repo = self.g.get_repo("protoncoin/protoncoin") self.assertEqual(repo.full_name, "padima2/protoncoin") def testGetMatchingRefs(self): refs = self.g.get_repo("FlorentClarret/PyGithub").get_git_matching_refs("tags") self.assertEqual(85, refs.totalCount) self.assertEqual("refs/tags/v0.1", refs[0].ref) self.assertEqual("refs/tags/v0.2", refs[1].ref) self.assertEqual("refs/tags/v0.3", refs[2].ref) self.assertEqual("refs/tags/v0.4", refs[3].ref) self.assertEqual("refs/tags/v0.5", refs[4].ref) self.assertEqual("refs/tags/v0.6", refs[5].ref) def testRepoVariable(self): variable = self.repo.create_variable("variable_name", "variable-value") self.assertTrue(variable.edit("variable-value123")) variable.delete() def testRepoVariables(self): # GitHub will always capitalize the variable name variables = (("VARIABLE_NAME_ONE", "variable-value-one"), ("VARIABLE_NAME_TWO", "variable-value-two")) repo = self.g.get_repo("AndrewJDawes/PyGithub") for variable in variables: repo.create_variable(variable[0], variable[1]) repo.update() repo_variables = repo.get_variables() matched_repo_variables = [] for variable in variables: for repo_variable in repo_variables: # GitHub will always capitalize the variable name, may be best to uppercase test data for comparison if repo_variable.name == variable[0].upper() and repo_variable.value == variable[1]: matched_repo_variables.append(repo_variable) break self.assertEqual(len(matched_repo_variables), len(variables)) for matched_repo_variable in matched_repo_variables: matched_repo_variable.delete() @mock.patch("github.PublicKey.encrypt") def testCreateRepoActionsSecret(self, encrypt): repo = self.g.get_repo("demoorg/demo-repo-1") # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = repo.create_secret("secret_name", "secret-value", "actions") self.assertIsNotNone(secret) @mock.patch("github.PublicKey.encrypt") def testCreateRepoDependabotSecret(self, encrypt): repo = self.g.get_repo("demoorg/demo-repo-1") # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" secret = repo.create_secret("secret_name", "secret-value", "dependabot") self.assertIsNotNone(secret) def testRepoGetSecretAssertion(self): repo = self.g.get_repo("demoorg/demo-repo-1") with self.assertRaises(AssertionError) as exc: repo.get_secret(secret_name="splat", secret_type="supersecret") self.assertEqual(str(exc.exception), "secret_type should be actions or dependabot") def testGetCustomProperties(self): custom_properties = self.repo.get_custom_properties() self.assertDictEqual(custom_properties, {"foo": "bar"}) def testUpdateCustomProperties(self): custom_properties = {"foo": "bar"} self.repo.update_custom_properties(custom_properties) class LazyRepository(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user() self.repository_name = f"{self.user.login}/PyGithub" def getLazyRepository(self): return self.g.get_repo(self.repository_name, lazy=True) def getEagerRepository(self): return self.g.get_repo(self.repository_name, lazy=False) def testGetIssues(self): lazy_repo = self.getLazyRepository() issues = lazy_repo.get_issues() eager_repo = self.getEagerRepository() issues2 = eager_repo.get_issues() self.assertListKeyEqual(issues2, id, [x for x in issues]) def testOwner(self): lazy_repo = self.getLazyRepository() owner = lazy_repo.owner eager_repo = self.getEagerRepository() self.assertEqual(owner, eager_repo.owner) def testEnableVulnerabilityAlert(self): lazy_repo = self.getLazyRepository() self.assertTrue(lazy_repo.enable_vulnerability_alert()) lazy_repo = self.g.get_repo("random", lazy=True) self.assertFalse(lazy_repo.enable_vulnerability_alert()) def testEnableAutomatedSecurityFixes(self): lazy_repo = self.getLazyRepository() self.assertTrue(lazy_repo.enable_automated_security_fixes()) lazy_repo = self.g.get_repo("random", lazy=True) self.assertFalse(lazy_repo.enable_automated_security_fixes()) def testDisableAutomatedSecurityFixes(self): lazy_repo = self.getLazyRepository() self.assertTrue(lazy_repo.disable_automated_security_fixes()) lazy_repo = self.g.get_repo("random", lazy=True) self.assertFalse(lazy_repo.disable_automated_security_fixes()) def testGetVulnerabilityAlert(self): lazy_repo = self.getEagerRepository() self.assertTrue(lazy_repo.get_vulnerability_alert()) lazy_repo = self.g.get_repo("random", lazy=True) self.assertFalse(lazy_repo.get_vulnerability_alert()) def testDisableVulnerabilityAlert(self): lazy_repo = self.getLazyRepository() self.assertTrue(lazy_repo.disable_vulnerability_alert()) lazy_repo = self.g.get_repo("random", lazy=True) self.assertFalse(lazy_repo.disable_vulnerability_alert()) def testChangeAutomateFixWhenNoVulnerabilityAlert(self): lazy_repo = self.getLazyRepository() self.assertFalse(lazy_repo.enable_automated_security_fixes()) self.assertFalse(lazy_repo.disable_automated_security_fixes()) def testGetVulnerabilityAlertWhenTurnedOff(self): lazy_repo = self.getEagerRepository() self.assertFalse(lazy_repo.get_vulnerability_alert()) def testRequester(self): lazy_repo = self.getLazyRepository() assert lazy_repo.requester is lazy_repo._requester
87,233
Python
.py
1,932
33.435818
713
0.594759
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,560
Environment.py
PyGithub_PyGithub/tests/Environment.py
############################ Copyrights and license ############################ # # # Copyright 2023 Andrew Dawes <53574062+AndrewJDawes@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 alson <git@alm.nufan.net> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from unittest import mock import pytest # type: ignore import github import github.EnvironmentDeploymentBranchPolicy import github.EnvironmentProtectionRule import github.EnvironmentProtectionRuleReviewer import github.NamedUser import github.Team from . import Framework class Environment(Framework.TestCase): def setUp(self): self.tokenAuthMode = True super().setUp() self.repo = self.g.get_user().get_repo("PyGithub") self.environment = self.repo.get_environment("dev") def testAttributes(self): self.assertEqual(self.environment.name, "dev") self.assertEqual(self.environment.id, 464814513) self.assertEqual(self.environment.node_id, "EN_kwDOHKhL9c4btIGx") self.assertEqual( self.environment.url, "https://api.github.com/repos/alson/PyGithub/environments/dev", ) self.assertEqual( self.environment.html_url, "https://github.com/alson/PyGithub/deployments/activity_log?environments_filter=dev", ) self.assertEqual( self.environment.created_at, datetime(2022, 4, 13, 15, 6, 32, tzinfo=timezone.utc), ) self.assertEqual( self.environment.updated_at, datetime(2022, 4, 13, 15, 6, 32, tzinfo=timezone.utc), ) self.assertTrue(self.environment.deployment_branch_policy.protected_branches) self.assertFalse(self.environment.deployment_branch_policy.custom_branch_policies) def testProtectionRules(self): protection_rules = self.environment.protection_rules self.assertEqual(len(protection_rules), 3) self.assertEqual(protection_rules[0].id, 216323) self.assertEqual(protection_rules[0].node_id, "GA_kwDOHKhL9c4AA00D") self.assertEqual(protection_rules[0].type, "branch_policy") self.assertEqual(protection_rules[1].id, 216324) self.assertEqual(protection_rules[1].node_id, "GA_kwDOHKhL9c4AA00E") self.assertEqual(protection_rules[1].type, "required_reviewers") self.assertEqual(protection_rules[2].id, 216325) self.assertEqual(protection_rules[2].node_id, "GA_kwDOHKhL9c4AA00F") self.assertEqual(protection_rules[2].type, "wait_timer") self.assertEqual(protection_rules[2].wait_timer, 15) def testReviewers(self): # This is necessary so we can maintain our own expectations, which have been manually editted, for this test. reviewers = self.repo.get_environment("dev").protection_rules[1].reviewers self.assertEqual(len(reviewers), 2) self.assertEqual(reviewers[0].type, "User") self.assertIsInstance(reviewers[0].reviewer, github.NamedUser.NamedUser) # Make type checker happy assert isinstance(reviewers[0].reviewer, github.NamedUser.NamedUser) self.assertEqual(reviewers[0].reviewer.id, 19245) self.assertEqual(reviewers[0].reviewer.login, "alson") self.assertEqual(reviewers[0].reviewer.type, "User") self.assertEqual(reviewers[1].type, "Team") self.assertIsInstance(reviewers[1].reviewer, github.Team.Team) # Make type checker happy assert isinstance(reviewers[1].reviewer, github.Team.Team) self.assertEqual(reviewers[1].reviewer.id, 1) self.assertEqual(reviewers[1].reviewer.slug, "justice-league") self.assertEqual(reviewers[1].reviewer.url, "https://api.github.com/teams/1") def testGetEnvironments(self): environments = self.repo.get_environments() self.assertEqual(environments.totalCount, 1) self.assertEqual( environments[0].url, "https://api.github.com/repos/alson/PyGithub/environments/dev", ) self.assertEqual(environments[0].name, "dev") def testCreateEnvironment(self): environment = self.repo.create_environment("test") self.assertEqual(environment.name, "test") self.assertEqual(environment.id, 470015651) self.assertEqual(environment.node_id, "EN_kwDOHKhL9c4cA96j") self.assertEqual( environment.url, "https://api.github.com/repos/alson/PyGithub/environments/test", ) self.assertEqual( environment.html_url, "https://github.com/alson/PyGithub/deployments/activity_log?environments_filter=test", ) self.assertEqual( environment.created_at, datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual( environment.updated_at, datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual(len(environment.protection_rules), 0) self.assertIsNone(environment.deployment_branch_policy) def testUpdateEnvironment(self): environment = self.repo.create_environment( "test", wait_timer=42, reviewers=[github.EnvironmentProtectionRuleReviewer.ReviewerParams(type_="User", id_=19245)], deployment_branch_policy=github.EnvironmentDeploymentBranchPolicy.EnvironmentDeploymentBranchPolicyParams( protected_branches=True, custom_branch_policies=False ), ) self.assertEqual(environment.name, "test") self.assertEqual(environment.id, 470015651) self.assertEqual(environment.node_id, "EN_kwDOHKhL9c4cA96j") self.assertEqual( environment.url, "https://api.github.com/repos/alson/PyGithub/environments/test", ) self.assertEqual( environment.html_url, "https://github.com/alson/PyGithub/deployments/activity_log?environments_filter=test", ) self.assertEqual( environment.created_at, datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual( environment.updated_at, datetime(2022, 4, 19, 14, 4, 32, tzinfo=timezone.utc), ) self.assertEqual(len(environment.protection_rules), 3) self.assertEqual(environment.protection_rules[0].type, "required_reviewers") self.assertEqual(len(environment.protection_rules[0].reviewers), 1) self.assertEqual(environment.protection_rules[0].reviewers[0].type, "User") self.assertEqual(environment.protection_rules[0].reviewers[0].reviewer.id, 19245) self.assertEqual(environment.protection_rules[1].type, "wait_timer") self.assertEqual(environment.protection_rules[1].wait_timer, 42) self.assertEqual(environment.protection_rules[2].type, "branch_policy") self.assertTrue(environment.deployment_branch_policy.protected_branches) self.assertFalse(environment.deployment_branch_policy.custom_branch_policies) def testDeleteEnvironment(self): self.repo.delete_environment("test") with pytest.raises(github.UnknownObjectException): self.repo.get_environment("test") def testEnvironmentVariable(self): repo = self.g.get_repo("AndrewJDawes/PyGithub") environment = repo.create_environment("test") variable = environment.create_variable("variable_name", "variable-value") self.assertTrue(variable.edit("variable-value123")) variable.delete() repo.delete_environment("test") def testEnvironmentVariables(self): # GitHub will always capitalize the variable name variables = (("VARIABLE_NAME_ONE", "variable-value-one"), ("VARIABLE_NAME_TWO", "variable-value-two")) repo = self.g.get_repo("AndrewJDawes/PyGithub") environment = repo.create_environment("test") for variable in variables: environment.create_variable(variable[0], variable[1]) environment.update() environment_variables = environment.get_variables() matched_environment_variables = [] for variable in variables: for environment_variable in environment_variables: # GitHub will always capitalize the variable name, may be best to uppercase test data for comparison if environment_variable.name == variable[0].upper() and environment_variable.value == variable[1]: matched_environment_variables.append(environment_variable) break self.assertEqual(len(matched_environment_variables), len(variables)) for matched_environment_variable in matched_environment_variables: matched_environment_variable.delete() repo.delete_environment("test") @mock.patch("github.PublicKey.encrypt") def testEnvironmentSecret(self, encrypt): # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" repo = self.g.get_repo("AndrewJDawes/PyGithub") environment = repo.create_environment("test") secret = environment.create_secret("secret_name", "secret-value") secret.update() # GitHub will always capitalize the secret name self.assertEqual(secret.name, "SECRET_NAME") secret.delete() repo.delete_environment("test") @mock.patch("github.PublicKey.encrypt") def testEnvironmentSecrets(self, encrypt): # encrypt returns a non-deterministic value, we need to mock it so the replay data matches encrypt.return_value = "M+5Fm/BqTfB90h3nC7F3BoZuu3nXs+/KtpXwxm9gG211tbRo0F5UiN0OIfYT83CKcx9oKES9Va4E96/b" # GitHub will always capitalize the secret name secrets = (("SECRET_NAME_ONE", "secret-value-one"), ("SECRET_NAME_TWO", "secret-value-two")) repo = self.g.get_repo("AndrewJDawes/PyGithub") environment = repo.create_environment("test") for secret in secrets: environment.create_secret(secret[0], secret[1]) environment.update() environment_secrets = environment.get_secrets() matched_environment_secrets = [] for secret in secrets: for environment_secret in environment_secrets: # GitHub will always capitalize the secret name, may be best to uppercase test data for comparison if environment_secret.name == secret[0].upper(): matched_environment_secrets.append(environment_secret) break self.assertEqual(len(matched_environment_secrets), len(secrets)) for matched_environment_secret in matched_environment_secrets: matched_environment_secret.delete() repo.delete_environment("test")
12,645
Python
.py
228
46.807018
118
0.640403
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,561
RequiredPullRequestReviews.py
PyGithub_PyGithub/tests/RequiredPullRequestReviews.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2024 Benjamin K <53038537+treee111@users.noreply.github.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class RequiredPullRequestReviews(Framework.TestCase): def setUp(self): super().setUp() self.required_pull_request_reviews = ( self.g.get_user().get_repo("PyGithub").get_branch("integrations").get_required_pull_request_reviews() ) def testAttributes(self): self.assertTrue(self.required_pull_request_reviews.dismiss_stale_reviews) self.assertTrue(self.required_pull_request_reviews.require_code_owner_reviews) self.assertIsNone(self.required_pull_request_reviews.require_last_push_approval) self.assertEqual(self.required_pull_request_reviews.required_approving_review_count, 3) self.assertEqual( self.required_pull_request_reviews.url, "https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews", ) self.assertIs(self.required_pull_request_reviews.dismissal_users, None) self.assertIs(self.required_pull_request_reviews.dismissal_teams, None) self.assertEqual( self.required_pull_request_reviews.__repr__(), 'RequiredPullRequestReviews(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection/required_pull_request_reviews", require_last_push_approval=None, require_code_owner_reviews=True, dismiss_stale_reviews=True)', ) def testOrganizationOwnedTeam(self): required_pull_request_reviews = ( self.g.get_repo("PyGithub/PyGithub", lazy=True) .get_branch("integrations") .get_required_pull_request_reviews() ) self.assertListKeyEqual( required_pull_request_reviews.dismissal_users, lambda u: u.login, ["jacquev6"], ) self.assertListKeyEqual( required_pull_request_reviews.dismissal_teams, lambda t: t.slug, ["pygithub-owners"], )
5,053
Python
.py
76
61.052632
252
0.54465
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,562
Issue131.py
PyGithub_PyGithub/tests/Issue131.py
############################ Copyrights and license ############################ # # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue131(Framework.TestCase): # https://github.com/jacquev6/PyGithub/pull/133 def setUp(self): super().setUp() self.user = self.g.get_user() self.repo = self.g.get_user("openmicroscopy").get_repo("ome-documentation") def testGetPullWithOrgHeadUser(self): user = self.repo.get_pull(204).head.user self.assertEqual(user.login, "imcf") self.assertEqual(user.type, "Organization") self.assertEqual(user.__class__.__name__, "NamedUser") # Should be Organization def testGetPullsWithOrgHeadUser(self): for pull in self.repo.get_pulls("closed"): if pull.number == 204: user = pull.head.user self.assertEqual(user, None) # Should be: # self.assertEqual(user.login, 'imcf') # self.assertEqual(user.type, 'Organization') # self.assertEqual(user.__class__.__name__, 'NamedUser') # Should be Organization break else: self.assertTrue(False)
3,440
Python
.py
52
60.826923
98
0.485368
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,563
__init__.py
PyGithub_PyGithub/tests/__init__.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################
2,354
Python
.py
29
80.172414
85
0.430108
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,564
GithubIntegration.py
PyGithub_PyGithub/tests/GithubIntegration.py
############################ Copyrights and license ############################ # # # Copyright 2019 Jake Wilkins <jakewilkins@github.com> # # Copyright 2019 Rigas Papathanasopoulos <rigaspapas@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Tomas Tomecek <nereone@gmail.com> # # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2019 秋葉 <ambiguous404@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Denis Blanchette <dblanchette@coveo.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 chantra <chantra@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import time # NOQA import requests # NOQA from urllib3.exceptions import InsecureRequestWarning import github from github import Consts from github.Auth import AppInstallationAuth from . import Framework APP_ID = 243473 PRIVATE_KEY = """ -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQC+5ePolLv6VcWLp2f17g6r6vHl+eoLuodOOfUl8JK+MVmvXbPa xDy0SS0pQhwTOMtB0VdSt++elklDCadeokhEoGDQp411o+kiOhzLxfakp/kewf4U HJnu4M/A2nHmxXVe2lzYnZvZHX5BM4SJo5PGdr0Ue2JtSXoAtYr6qE9maQIDAQAB AoGAFhOJ7sy8jG+837Clcihso+8QuHLVYTPaD+7d7dxLbBlS8NfaQ9Nr3cGUqm/N xV9NCjiGa7d/y4w/vrPwGh6UUsA+CvndwDgBd0S3WgIdWvAvHM8wKgNh/GBLLzhT Bg9BouRUzcT1MjAnkGkWqqCAgN7WrCSUMLt57TNleNWfX90CQQDjvVKTT3pOiavD 3YcLxwkyeGd0VMvKiS4nV0XXJ97cGXs2GpOGXldstDTnF5AnB6PbukdFLHpsx4sW Hft3LRWnAkEA1pY15ke08wX6DZVXy7zuQ2izTrWSGySn7B41pn55dlKpttjHeutA 3BEQKTFvMhBCphr8qST7Wf1SR9FgO0tFbwJAEhHji2yy96hUyKW7IWQZhrem/cP8 p4Va9CQolnnDZRNgg1p4eiDiLu3dhLiJ547joXuWTBbLX/Y1Qvv+B+a74QJBAMCW O3WbMZlS6eK6//rIa4ZwN00SxDg8I8FUM45jwBsjgVGrKQz2ilV3sutlhIiH82kk m1Iq8LMJGYl/LkDJA10CQBV1C+Xu3ukknr7C4A/4lDCa6Xb27cr1HanY7i89A+Ab eatdM6f/XVqWp8uPT9RggUV9TjppJobYGT2WrWJMkYw= -----END RSA PRIVATE KEY----- """ PUBLIC_KEY = """ -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+5ePolLv6VcWLp2f17g6r6vHl +eoLuodOOfUl8JK+MVmvXbPaxDy0SS0pQhwTOMtB0VdSt++elklDCadeokhEoGDQ p411o+kiOhzLxfakp/kewf4UHJnu4M/A2nHmxXVe2lzYnZvZHX5BM4SJo5PGdr0U e2JtSXoAtYr6qE9maQIDAQAB -----END PUBLIC KEY----- """ class GithubIntegration(Framework.BasicTestCase): def setUp(self): super().setUp() self.org_installation_id = 30614487 self.repo_installation_id = 30614431 self.user_installation_id = 30614431 def testDeprecatedAppAuth(self): # Replay data copied from testGetInstallations to test authentication only with self.assertWarns(DeprecationWarning) as warning: github_integration = github.GithubIntegration(integration_id=APP_ID, private_key=PRIVATE_KEY) installations = github_integration.get_installations() self.assertEqual(len(list(installations)), 2) self.assertWarning( warning, "Arguments integration_id, private_key, jwt_expiry, jwt_issued_at and " "jwt_algorithm are deprecated, please use auth=github.Auth.AppAuth(...) " "instead", ) def testRequiredAppAuth(self): # GithubIntegration requires AppAuth authentication. for auth in [self.oauth_token, self.jwt, self.login]: with self.assertRaises(AssertionError) as r: github.GithubIntegration(auth=auth) self.assertEqual( str(r.exception), f"GithubIntegration requires github.Auth.AppAuth authentication, not {type(auth)}", ) def testAppAuth(self): # Replay data copied from testDeprecatedAppAuth to test parity auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) installations = github_integration.get_installations() self.assertEqual(len(list(installations)), 2) def testNoneAppAuth(self): with self.assertRaises(AssertionError): github.GithubIntegration(auth=None) def testGetInstallations(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) installations = github_integration.get_installations() self.assertEqual(len(list(installations)), 2) self.assertEqual(installations[0].id, self.org_installation_id) self.assertEqual(installations[1].id, self.repo_installation_id) def testGetGithubForInstallation(self): # with verify=False, urllib3.connectionpool rightly may issue an InsecureRequestWarning # we ignore InsecureRequestWarning from urllib3.connectionpool with self.ignoreWarning(category=InsecureRequestWarning, module="urllib3.connectionpool"): kwargs = dict( auth=github.Auth.AppAuth(APP_ID, PRIVATE_KEY), # http protocol used to deviate from default base url, recording data might require https base_url="http://api.github.com", timeout=Consts.DEFAULT_TIMEOUT + 10, user_agent="PyGithub/Python-Test", per_page=Consts.DEFAULT_PER_PAGE + 10, verify=False, retry=3, pool_size=10, seconds_between_requests=100, seconds_between_writes=1000, ) # assert kwargs consists of ALL requester constructor arguments self.assertEqual(kwargs.keys(), github.Requester.Requester.__init__.__annotations__.keys()) github_integration = github.GithubIntegration(**kwargs) g = github_integration.get_github_for_installation(36541767) self.assertIsInstance(g._Github__requester.auth, AppInstallationAuth) actual = g._Github__requester.kwargs kwargs.update(auth=str(AppInstallationAuth)) actual.update(auth=str(type(actual["auth"]))) self.assertDictEqual(kwargs, actual) repo = g.get_repo("PyGithub/PyGithub") self.assertEqual(repo.full_name, "PyGithub/PyGithub") def testGetAccessToken(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) # Get repo installation access token repo_installation_authorization = github_integration.get_access_token(self.repo_installation_id) self.assertEqual( repo_installation_authorization.token, "ghs_1llwuELtXN5HDOB99XhpcTXdJxbOuF0ZlSmj", ) self.assertDictEqual( repo_installation_authorization.permissions, {"issues": "read", "metadata": "read"}, ) self.assertEqual(repo_installation_authorization.repository_selection, "selected") # Get org installation access token org_installation_authorization = github_integration.get_access_token(self.org_installation_id) self.assertEqual( org_installation_authorization.token, "ghs_V0xygF8yACXSDz5FM65QWV1BT2vtxw0cbgPw", ) org_permissions = { "administration": "write", "issues": "write", "metadata": "read", "organization_administration": "read", } self.assertDictEqual(org_installation_authorization.permissions, org_permissions) self.assertEqual(org_installation_authorization.repository_selection, "selected") # Get user installation access token user_installation_authorization = github_integration.get_access_token(self.user_installation_id) self.assertEqual( user_installation_authorization.token, "ghs_1llwuELtXN5HDOB99XhpcTXdJxbOuF0ZlSmj", ) self.assertDictEqual( user_installation_authorization.permissions, {"issues": "read", "metadata": "read"}, ) self.assertEqual(user_installation_authorization.repository_selection, "selected") def testGetUserInstallation(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) installation = github_integration.get_user_installation(username="ammarmallik") self.assertEqual(installation.id, self.user_installation_id) def testGetOrgInstallation(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) installation = github_integration.get_org_installation(org="GithubApp-Test-Org") self.assertEqual(installation.id, self.org_installation_id) def testGetRepoInstallation(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) installation = github_integration.get_repo_installation(owner="ammarmallik", repo="test-runner") self.assertEqual(installation.id, self.repo_installation_id) def testGetAppInstallation(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) installation = github_integration.get_app_installation(installation_id=self.org_installation_id) self.assertEqual(installation.id, self.org_installation_id) def testGetInstallationNotFound(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) with self.assertRaises(github.UnknownObjectException) as raisedexp: github_integration.get_org_installation(org="GithubApp-Test-Org-404") self.assertEqual(raisedexp.exception.status, 404) def testGetInstallationWithExpiredJWT(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) with self.assertRaises(github.GithubException) as raisedexp: github_integration.get_org_installation(org="GithubApp-Test-Org") self.assertEqual(raisedexp.exception.status, 401) def testGetAccessTokenWithExpiredJWT(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) with self.assertRaises(github.GithubException) as raisedexp: github_integration.get_access_token(self.repo_installation_id) self.assertEqual(raisedexp.exception.status, 401) def testGetAccessTokenForNoInstallation(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) with self.assertRaises(github.UnknownObjectException) as raisedexp: github_integration.get_access_token(40432121) self.assertEqual(raisedexp.exception.status, 404) def testGetAccessTokenWithInvalidPermissions(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) with self.assertRaises(github.GithubException) as raisedexp: github_integration.get_access_token(self.repo_installation_id, permissions={"test-permissions": "read"}) self.assertEqual(raisedexp.exception.status, 422) def testGetAccessTokenWithInvalidData(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) with self.assertRaises(github.GithubException) as raisedexp: github_integration.get_access_token(self.repo_installation_id, permissions="invalid_data") self.assertEqual(raisedexp.exception.status, 400) def testGetApp(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) github_integration = github.GithubIntegration(auth=auth) app = github_integration.get_app() self.assertEqual(app.name, "PyGithubTest") self.assertEqual(app.url, "/apps/pygithubtest") assert github_integration.requester is github_integration.__requester assert app.requester is app._requester
13,835
Python
.py
239
50.033473
116
0.669201
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,565
DependabotAlert.py
PyGithub_PyGithub/tests/DependabotAlert.py
############################ Copyrights and license ############################ # # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Thomas Cooper <coopernetes@proton.me> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone import pytest import github.DependabotAlert import github.PaginatedList from . import Framework class DependabotAlert(Framework.TestCase): alert: github.DependabotAlert.DependabotAlert def setUp(self): super().setUp() self.repo = self.g.get_repo("coopernetes/PyGithub") def testAttributes(self): alert = self.repo.get_dependabot_alert(1) self.assertEqual(alert.number, 1) self.assertEqual(alert.state, "dismissed") self.assertEqual(alert.dependency.package.ecosystem, "pip") self.assertEqual(alert.dependency.package.name, "jinja2") self.assertEqual(alert.dependency.manifest_path, "requirements/docs.txt") self.assertEqual(alert.dependency.scope, "runtime") self.assertEqual(alert.security_advisory.ghsa_id, "GHSA-h5c8-rqwp-cp95") self.assertEqual(alert.security_advisory.cve_id, "CVE-2024-22195") self.assertEqual( alert.security_advisory.summary, "Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter", ) self.assertEqual( alert.security_advisory.description, "The `xmlattr` filter in affected versions of Jinja accepts keys containing spaces. XML/HTML attributes cannot contain spaces, as each would then be interpreted as a separate attribute. If an application accepts keys (as opposed to only values) as user input, and renders these in pages that other users see as well, an attacker could use this to inject other attributes and perform XSS. Note that accepting keys as user input is not common or a particularly intended use case of the `xmlattr` filter, and an application doing so should already be verifying what keys are provided regardless of this fix.", ) self.assertEqual(alert.security_advisory.severity, "medium") self.assertEqual(alert.security_advisory.identifiers[0]["value"], "GHSA-h5c8-rqwp-cp95") self.assertEqual(alert.security_advisory.identifiers[0]["type"], "GHSA") self.assertEqual(alert.security_advisory.identifiers[1]["value"], "CVE-2024-22195") self.assertEqual(alert.security_advisory.identifiers[1]["type"], "CVE") self.assertEqual( alert.security_advisory.references[0]["url"], "https://github.com/pallets/jinja/security/advisories/GHSA-h5c8-rqwp-cp95", ) self.assertEqual( alert.security_advisory.references[1]["url"], "https://nvd.nist.gov/vuln/detail/CVE-2024-22195" ) self.assertEqual( alert.security_advisory.references[2]["url"], "https://github.com/pallets/jinja/commit/716795349a41d4983a9a4771f7d883c96ea17be7", ) self.assertEqual( alert.security_advisory.references[3]["url"], "https://github.com/pallets/jinja/releases/tag/3.1.3" ) self.assertEqual( alert.security_advisory.references[4]["url"], "https://github.com/advisories/GHSA-h5c8-rqwp-cp95" ) self.assertEqual(alert.security_advisory.published_at, datetime(2024, 1, 11, 15, 20, 48, tzinfo=timezone.utc)) self.assertEqual(alert.security_advisory.updated_at, datetime(2024, 1, 11, 15, 20, 50, tzinfo=timezone.utc)) self.assertEqual(alert.security_advisory.withdrawn_at, None) self.assertEqual(alert.security_advisory.vulnerabilities[0].package.ecosystem, "pip") self.assertEqual(alert.security_advisory.vulnerabilities[0].package.name, "jinja2") self.assertEqual(alert.security_advisory.vulnerabilities[0].vulnerable_version_range, "< 3.1.3") self.assertEqual(alert.security_advisory.vulnerabilities[0].severity, "medium") self.assertEqual(alert.security_advisory.vulnerabilities[0].first_patched_version["identifier"], "3.1.3") self.assertEqual(alert.security_vulnerability.package.ecosystem, "pip") self.assertEqual(alert.security_vulnerability.package.name, "jinja2") self.assertEqual(alert.security_vulnerability.vulnerable_version_range, "< 3.1.3") self.assertEqual(alert.security_vulnerability.severity, "medium") self.assertEqual(alert.security_vulnerability.first_patched_version["identifier"], "3.1.3") self.assertEqual(alert.url, "https://api.github.com/repos/coopernetes/PyGithub/dependabot/alerts/1") self.assertEqual(alert.html_url, "https://github.com/coopernetes/PyGithub/security/dependabot/1") self.assertEqual(alert.created_at, datetime(2024, 1, 20, 17, 12, 38, tzinfo=timezone.utc)) self.assertEqual(alert.updated_at, datetime(2024, 1, 21, 3, 35, 38, tzinfo=timezone.utc)) self.assertEqual(alert.dismissed_at, datetime(2024, 1, 21, 3, 35, 38, tzinfo=timezone.utc)) self.assertEqual(alert.dismissed_by.login, "coopernetes") self.assertEqual(alert.dismissed_reason, "tolerable_risk") self.assertEqual(alert.dismissed_comment, "Example comment") self.assertEqual(alert.fixed_at, None) def testMultipleAlerts(self): multiple_alerts = self.repo.get_dependabot_alerts() self.assertIsInstance(multiple_alerts, github.PaginatedList.PaginatedList) self.assertIsInstance(multiple_alerts[0], github.DependabotAlert.DependabotAlert) alert_list = [alert for alert in multiple_alerts] test_alert = alert_list[0] self.assertEqual(len(alert_list), 1) # Everything below is the same as testAttributes. This is just to make sure the list works. self.assertEqual(test_alert.number, 1) self.assertEqual(test_alert.state, "dismissed") self.assertEqual(test_alert.dependency.package.ecosystem, "pip") self.assertEqual(test_alert.dependency.package.name, "jinja2") self.assertEqual(test_alert.dependency.manifest_path, "requirements/docs.txt") self.assertEqual(test_alert.dependency.scope, "runtime") self.assertEqual(test_alert.security_advisory.ghsa_id, "GHSA-h5c8-rqwp-cp95") self.assertEqual(test_alert.security_advisory.cve_id, "CVE-2024-22195") self.assertEqual( test_alert.security_advisory.summary, "Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter", ) self.assertEqual( test_alert.security_advisory.description, "The `xmlattr` filter in affected versions of Jinja accepts keys containing spaces. XML/HTML attributes cannot contain spaces, as each would then be interpreted as a separate attribute. If an application accepts keys (as opposed to only values) as user input, and renders these in pages that other users see as well, an attacker could use this to inject other attributes and perform XSS. Note that accepting keys as user input is not common or a particularly intended use case of the `xmlattr` filter, and an application doing so should already be verifying what keys are provided regardless of this fix.", ) self.assertEqual(test_alert.security_advisory.severity, "medium") self.assertEqual(test_alert.security_advisory.identifiers[0]["value"], "GHSA-h5c8-rqwp-cp95") self.assertEqual(test_alert.security_advisory.identifiers[0]["type"], "GHSA") self.assertEqual(test_alert.security_advisory.identifiers[1]["value"], "CVE-2024-22195") self.assertEqual(test_alert.security_advisory.identifiers[1]["type"], "CVE") self.assertEqual( test_alert.security_advisory.published_at, datetime(2024, 1, 11, 15, 20, 48, tzinfo=timezone.utc) ) self.assertEqual( test_alert.security_advisory.updated_at, datetime(2024, 1, 11, 15, 20, 50, tzinfo=timezone.utc) ) self.assertEqual(test_alert.security_advisory.withdrawn_at, None) self.assertEqual(test_alert.security_advisory.vulnerabilities[0].package.ecosystem, "pip") self.assertEqual(test_alert.security_advisory.vulnerabilities[0].package.name, "jinja2") self.assertEqual(test_alert.security_advisory.vulnerabilities[0].vulnerable_version_range, "< 3.1.3") self.assertEqual(test_alert.security_advisory.vulnerabilities[0].severity, "medium") self.assertEqual(test_alert.security_advisory.vulnerabilities[0].first_patched_version["identifier"], "3.1.3") self.assertEqual(test_alert.security_vulnerability.package.ecosystem, "pip") self.assertEqual(test_alert.security_vulnerability.package.name, "jinja2") self.assertEqual(test_alert.security_vulnerability.vulnerable_version_range, "< 3.1.3") self.assertEqual(test_alert.security_vulnerability.severity, "medium") self.assertEqual(test_alert.security_vulnerability.first_patched_version["identifier"], "3.1.3") self.assertEqual(test_alert.url, "https://api.github.com/repos/coopernetes/PyGithub/dependabot/alerts/1") self.assertEqual(test_alert.html_url, "https://github.com/coopernetes/PyGithub/security/dependabot/1") self.assertEqual(test_alert.created_at, datetime(2024, 1, 20, 17, 12, 38, tzinfo=timezone.utc)) self.assertEqual(test_alert.updated_at, datetime(2024, 1, 20, 22, 4, tzinfo=timezone.utc)) self.assertEqual(test_alert.dismissed_at, datetime(2024, 1, 20, 22, 4, tzinfo=timezone.utc)) self.assertEqual(test_alert.dismissed_by.login, "coopernetes") self.assertEqual(test_alert.dismissed_reason, "tolerable_risk") self.assertEqual(test_alert.dismissed_comment, "Example comment") self.assertEqual(test_alert.fixed_at, None) def testRepr(self): alert = self.repo.get_dependabot_alert(1) self.assertEqual(repr(alert), 'DependabotAlert(number=1, ghsa_id="GHSA-h5c8-rqwp-cp95")') def testGetAlertsWithAllArguments(self): alerts = self.repo.get_dependabot_alerts( "open", "medium", "pip", "foo,jinja2", "bar/package.json,requirements/docs.txt", "runtime", "created", "asc" ) self.assertEqual(len(list(alerts)), 1) def testUpdateAlertDismissedWithoutReason(self): with pytest.raises(AssertionError): self.repo.update_dependabot_alert(1, "dismissed") def testUpdateAlertOpen(self): alert = self.repo.update_dependabot_alert(1, "open") self.assertEqual(alert.state, "open") self.assertEqual(alert.dismissed_reason, None) self.assertEqual(alert.dismissed_comment, None) def testUpdateAlertDismissed(self): alert = self.repo.update_dependabot_alert(1, "dismissed", "tolerable_risk", "Example comment") self.assertEqual(alert.state, "dismissed") self.assertEqual(alert.dismissed_reason, "tolerable_risk") self.assertEqual(alert.dismissed_comment, "Example comment")
12,577
Python
.py
170
65.970588
618
0.669115
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,566
Issue572.py
PyGithub_PyGithub/tests/Issue572.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import github from . import Framework class Issue572(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("PyGithub") def testIssueAsPullRequest(self): issue = self.repo.get_issue(2) pull = issue.as_pull_request() self.assertEqual(issue.html_url, pull.html_url) self.assertTrue(isinstance(pull, github.PullRequest.PullRequest)) def testPullReqeustAsIssue(self): pull = self.repo.get_pull(2) issue = pull.as_issue() self.assertEqual(pull.html_url, issue.html_url) self.assertTrue(isinstance(issue, github.Issue.Issue))
3,334
Python
.py
49
65.040816
85
0.486429
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,567
ReleaseAsset.py
PyGithub_PyGithub/tests/ReleaseAsset.py
############################ Copyrights and license ############################ # # # Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class ReleaseAsset(Framework.TestCase): def setUp(self): super().setUp() self.release = self.g.get_user().get_repo("PyGithub").get_releases()[0] self.asset = self.release.get_assets()[0] def testAttributes(self): self.assertEqual(self.release.id, 1210814) self.assertEqual(self.asset.id, 16) self.assertEqual( self.asset.url, "https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16", ) self.assertEqual(self.asset.name, "Archive.zip") self.assertEqual(self.asset.label, "Installation msi & runbook zipped") self.assertEqual(self.asset.content_type, "application/zip") self.assertEqual(self.asset.state, "uploaded") self.assertEqual(self.asset.size, 3783) self.assertEqual(self.asset.download_count, 2) self.assertEqual( self.asset.created_at, datetime(2017, 2, 1, 22, 40, 58, tzinfo=timezone.utc), ) self.assertEqual( self.asset.updated_at, datetime(2017, 2, 1, 22, 44, 58, tzinfo=timezone.utc), ) self.assertEqual( self.asset.browser_download_url, "https://github.com/edhollandAL/PyGithub/releases/download/v1.25.2/Asset.zip", ) self.assertEqual(self.asset.uploader.login, "PyGithub") self.assertEqual( repr(self.asset), 'GitReleaseAsset(url="https://api.github.com/api/v3/repos/edhollandAL/PyGithub/releases/assets/16")', ) def testDelete(self): self.assertTrue(self.asset.delete_asset()) def testUpdate(self): new_name = "updated-name.zip" new_label = "Updated label" updated_asset = self.asset.update_asset(new_name, new_label) self.assertEqual(updated_asset.name, new_name) self.assertNotEqual(self.asset.name, updated_asset.name) self.assertEqual(updated_asset.label, new_label) self.assertNotEqual(self.asset.label, updated_asset.label)
4,385
Python
.py
75
52.36
113
0.527307
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,568
Topic.py
PyGithub_PyGithub/tests/Topic.py
############################ Copyrights and license ############################ # # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from operator import attrgetter from . import Framework class Topic(Framework.TestCase): def setUp(self): super().setUp() self.topics = list(self.g.search_topics("python")) def testAllFields(self): topic = self.topics[0] self.assertEqual(topic.name, "python") self.assertEqual(topic.display_name, "Python") self.assertEqual( topic.short_description, "Python is a dynamically typed programming language.", ) self.assertEqual( topic.description, "Python is a dynamically typed programming language designed by Guido van Rossum. Much like the programming language Ruby, Python was designed to be easily read by programmers. Because of its large following and many libraries, Python can be implemented and used to do anything from webpages to scientific research.", ) self.assertEqual(topic.created_by, "Guido van Rossum") self.assertEqual(topic.released, "February 20, 1991") self.assertEqual(topic.created_at, datetime(2016, 12, 7, 0, 7, 2, tzinfo=timezone.utc)) self.assertEqual(topic.updated_at, datetime(2019, 10, 9, 20, 33, 49, tzinfo=timezone.utc)) self.assertEqual(topic.featured, True) self.assertEqual(topic.curated, True) self.assertEqual(topic.score, 7576.306) self.assertEqual(topic.__repr__(), 'Topic(name="python")') def testNamesFromSearchResults(self): expected_names = [ "python", "django", "flask", "python-script", "python36", "opencv-python", "ruby", "python-library", "scikit-learn", "python37", "selenium-python", "sublime-text", "leetcode-python", "learning-python", "tkinter-python", "python35", "machinelearning-python", "python-flask", "python-package", "python-telegram-bot", "python-wrapper", "python3-6", "opencv3-python", "hackerrank-python", "python-api", "python2-7", "pythonista", "haxe", "python-requests", "python-2-7", ] self.assertListKeyEqual(self.topics, attrgetter("name"), expected_names)
4,482
Python
.py
86
44.255814
329
0.504332
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,569
SourceImport.py
PyGithub_PyGithub/tests/SourceImport.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Hayden Fuss <wifu1234@gmail.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class SourceImport(Framework.TestCase): def setUp(self): super().setUp() self.user = self.g.get_user("brix4dayz") self.repo = self.user.get_repo("source-import-test") self.source_import = self.repo.get_source_import() def testAttributes(self): self.assertEqual(self.source_import.authors_count, 1) self.assertEqual( self.source_import.authors_url, "https://api.github.com/repos/brix4dayz/source-import-test/import/authors", ) self.assertEqual(self.source_import.has_large_files, False) self.assertEqual( self.source_import.html_url, "https://github.com/brix4dayz/source-import-test/import", ) self.assertEqual(self.source_import.large_files_count, 0) self.assertEqual(self.source_import.large_files_size, 0) self.assertEqual( self.source_import.repository_url, "https://api.github.com/repos/brix4dayz/source-import-test", ) self.assertEqual(self.source_import.status, "complete") self.assertEqual(self.source_import.status_text, "Done") self.assertEqual( self.source_import.url, "https://api.github.com/repos/brix4dayz/source-import-test/import", ) self.assertEqual(self.source_import.use_lfs, "undecided") self.assertEqual(self.source_import.vcs, "mercurial") self.assertEqual(self.source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test") self.assertEqual( self.source_import.__repr__(), 'SourceImport(vcs_url="https://bitbucket.org/hfuss/source-import-test", url="https://api.github.com/repos/brix4dayz/source-import-test/import", status="complete", repository_url="https://api.github.com/repos/brix4dayz/source-import-test")', ) def testUpdate(self): # The real test is that update() method passes the header update_ret = self.source_import.update() self.assertTrue(update_ret) self.assertEqual(self.source_import.status, "complete")
4,890
Python
.py
76
58.684211
252
0.541181
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,570
Issue174.py
PyGithub_PyGithub/tests/Issue174.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 AetherDeity <aetherdeity+github@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue174(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("twitter/bootstrap") def testGetDirContentsWhithHttpRedirect(self): contents = self.repo.get_contents("js/") self.assertEqual(len(contents), 15)
2,907
Python
.py
40
70.575
85
0.466993
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,571
Issue823.py
PyGithub_PyGithub/tests/Issue823.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 AetherDeity <aetherdeity+github@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Shibasis Patel <smartshibasish@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue823(Framework.TestCase): def setUp(self): super().setUp() self.org = self.g.get_organization("p-society") self.team = self.org.get_team(2745783) self.pending_invitations = self.team.invitations() def testGetPendingInvitationAttributes(self): team_url = self.pending_invitations[0].invitation_teams_url self.assertEqual( team_url, "https://api.github.com/organizations/29895434/invitations/6080804/teams", ) inviter = self.pending_invitations[0].inviter.login self.assertEqual(inviter, "palash25") role = self.pending_invitations[0].role self.assertEqual(role, "direct_member") team_count = self.pending_invitations[0].team_count self.assertEqual(team_count, 1)
3,514
Python
.py
52
63.884615
86
0.499422
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,572
ExposeAllAttributes.py
PyGithub_PyGithub/tests/ExposeAllAttributes.py
############################ Copyrights and license ############################ # # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class ExposeAllAttributes(Framework.TestCase): def testAllClasses(self): authenticatedUser = self.g.get_user() namedUser = self.g.get_user("nvie") repository = authenticatedUser.get_repo("PyGithub") organization = self.g.get_organization("BeaverSoftware") plan = authenticatedUser.plan branch = repository.get_branch("master") commit = repository.get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a") commitStats = commit.stats commitStatus = commit.get_statuses()[0] milestone = repository.get_milestone(17) gist = self.g.get_gist("149016") gistComment = gist.get_comment(4565) gistFile = gist.files[".gitignore"] gistHistoryState = gist.history[0] gitCommit = repository.get_git_commit("be37b8a7f3a68631c32672dcd84d9eba27438ee6") gitAuthor = gitCommit.author gitTree = repository.get_git_tree("6f7c2d8c66d78863f7b91792deaead619799a1ce") gitTreeElement = gitTree.tree[0] gitBlob = repository.get_git_blob("681fb61f1761743a02f5c790f1c762cbfe8cfad1") gitRef = repository.get_git_ref("tags/v1.17.0") gitObject = gitRef.object issue = repository.get_issue(188) issueComment = issue.get_comment(22686536) issueEvent = issue.get_events()[0] issuePullRequest = issue.pull_request gitignoreTemplate = self.g.get_gitignore_template("Python") team = organization.get_team(141487) label = repository.get_label("Bug") pullRequest = repository.get_pull(31) pullRequestComment = pullRequest.get_review_comment(1580134) pullRequestPart = pullRequest.base file = pullRequest.get_files()[0] commitComment = repository.get_comment(3630301) rateLimit = self.g.get_rate_limit() hook = repository.get_hooks()[0] hookResponse = hook.last_response hookDescription = self.g.get_hooks()[0] comparison = repository.compare("master", "develop") contentFile = repository.get_contents("README.rst") permissions = repository.permissions event = repository.get_events()[0] notification = authenticatedUser.get_notification("8406712") notificationSubject = notification.subject missingAttributes = self.gatherMissingAttributes( [ authenticatedUser, # authorization, # Security issue if put as-is in ReplayData # authorizationApplication, # Security issue if put as-is in ReplayData branch, commit, commitComment, commitStats, commitStatus, comparison, contentFile, # download, # Deprecated: https://github.com/blog/1302-goodbye-uploads event, file, gist, gistComment, gistFile, gistHistoryState, gitAuthor, gitBlob, gitCommit, gitignoreTemplate, gitObject, gitRef, # gitTag, gitTree, gitTreeElement, hook, hookDescription, hookResponse, issue, issueComment, issueEvent, issuePullRequest, label, milestone, namedUser, notification, notificationSubject, organization, permissions, plan, pullRequest, pullRequestComment, # pullRequestMergeStatus, # Only obtained when merging a pull request through the API pullRequestPart, rateLimit, repository, # repositoryKey, # Security issue if put as-is in ReplayData # tag, team, # userKey, # Security issue if put as-is in ReplayData ] ) for className, attributesMissingInClass in sorted(missingAttributes.items()): for attrName, value in sorted(attributesMissingInClass.items()): print(className, attrName, "->", repr(value)) self.assertEqual(sum(len(attrs) for attrs in missingAttributes.values()), 0) def findMissingAttributes(self, obj): if hasattr(obj, "update"): obj.update() className = obj.__class__.__name__ missingAttributes = {} for attribute in obj.raw_data: if attribute != "_links": if not hasattr(obj, attribute): missingAttributes[attribute] = obj.raw_data[attribute] return (className, missingAttributes) def gatherMissingAttributes(self, objs): allMissingAttributes = dict() for obj in objs: className, attributesMissingInClass = self.findMissingAttributes(obj) if len(attributesMissingInClass) > 0: if className not in allMissingAttributes: allMissingAttributes[className] = dict() allMissingAttributes[className].update(attributesMissingInClass) return allMissingAttributes
7,915
Python
.py
155
40.606452
102
0.546323
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,573
ApplicationOAuth.py
PyGithub_PyGithub/tests/ApplicationOAuth.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Rigas Papathanasopoulos <rigaspapas@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 chantra <chantra@users.noreply.github.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from unittest import mock import github from github.ApplicationOAuth import ApplicationOAuth as aoa from . import Framework class ApplicationOAuth(Framework.TestCase): def setUp(self): super().setUp() self.CLIENT_ID = "client_id_removed" self.CLIENT_SECRET = "client_secret_removed" self.app = self.g.get_oauth_application(self.CLIENT_ID, self.CLIENT_SECRET) self.ent_gh = github.Github(base_url="http://my.enterprise.com/path/to/github") self.ent_app = self.ent_gh.get_oauth_application(self.CLIENT_ID, self.CLIENT_SECRET) def testLoginURL(self): BASE_URL = "https://github.com/login/oauth/authorize" sample_uri = "https://myapp.com/some/path" sample_uri_encoded = "https%3A%2F%2Fmyapp.com%2Fsome%2Fpath" self.assertEqual(self.app.get_login_url(), f"{BASE_URL}?client_id={self.CLIENT_ID}") self.assertTrue(f"redirect_uri={sample_uri_encoded}" in self.app.get_login_url(redirect_uri=sample_uri)) self.assertTrue(f"client_id={self.CLIENT_ID}" in self.app.get_login_url(redirect_uri=sample_uri)) self.assertTrue("state=123abc" in self.app.get_login_url(state="123abc", login="user")) self.assertTrue("login=user" in self.app.get_login_url(state="123abc", login="user")) self.assertTrue(f"client_id={self.CLIENT_ID}" in self.app.get_login_url(state="123abc", login="user")) def testGetAccessToken(self): access_token = self.app.get_access_token("oauth_code_removed", state="state_removed") # Test string representation self.assertEqual( str(access_token), 'AccessToken(type="bearer", token="acces...", scope="", ' "refresh_token_expires_in=None, refresh_token=None, expires_in=None)", ) self.assertEqual(access_token.token, "access_token_removed") self.assertEqual(access_token.type, "bearer") self.assertEqual(access_token.scope, "") self.assertIsNone(access_token.expires_in) self.assertIsNone(access_token.expires_at) self.assertIsNone(access_token.refresh_token) self.assertIsNone(access_token.refresh_expires_in) self.assertIsNone(access_token.refresh_expires_at) def testEnterpriseSupport(self): requester = self.ent_gh._Github__requester self.assertEqual(requester.scheme, "http") self.assertEqual(requester.hostname, "my.enterprise.com") self.assertEqual(requester.hostname_and_port, "my.enterprise.com") self.assertEqual(self.ent_app.get_oauth_url("auth"), "http://my.enterprise.com/login/oauth/auth") gh_w_port = github.Github( base_url="http://my.enterprise.com:443/path/to/github" )._Github__requester.hostname_and_port self.assertEqual(gh_w_port, "my.enterprise.com:443") def testEnterpriseLoginURL(self): BASE_URL = "http://my.enterprise.com/login/oauth/authorize" sample_uri = "https://myapp.com/some/path" sample_uri_encoded = "https%3A%2F%2Fmyapp.com%2Fsome%2Fpath" self.assertEqual(self.ent_app.get_login_url(), f"{BASE_URL}?client_id={self.CLIENT_ID}") self.assertTrue(f"redirect_uri={sample_uri_encoded}" in self.ent_app.get_login_url(redirect_uri=sample_uri)) self.assertTrue(f"client_id={self.CLIENT_ID}" in self.ent_app.get_login_url(redirect_uri=sample_uri)) self.assertTrue("state=123abc" in self.ent_app.get_login_url(state="123abc", login="user")) self.assertTrue("login=user" in self.ent_app.get_login_url(state="123abc", login="user")) self.assertTrue(f"client_id={self.CLIENT_ID}" in self.ent_app.get_login_url(state="123abc", login="user")) def testEnterpriseGetAccessToken(self): access_token = self.ent_app.get_access_token("oauth_code_removed", state="state_removed") # Test string representation self.assertEqual( str(access_token), 'AccessToken(type="bearer", token="acces...", scope="", ' "refresh_token_expires_in=None, refresh_token=None, expires_in=None)", ) self.assertEqual(access_token.token, "access_token_removed") self.assertEqual(access_token.type, "bearer") self.assertEqual(access_token.scope, "") self.assertIsNone(access_token.expires_in) self.assertIsNone(access_token.expires_at) self.assertIsNone(access_token.refresh_token) self.assertIsNone(access_token.refresh_expires_in) self.assertIsNone(access_token.refresh_expires_at) def testGetAccessTokenWithExpiry(self): with mock.patch("github.AccessToken.datetime") as dt: dt.now = mock.Mock(return_value=datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc)) access_token = self.app.get_access_token("oauth_code_removed", state="state_removed") # Test string representation self.assertEqual( str(access_token), 'AccessToken(type="bearer", token="acces...", scope="", ' 'refresh_token_expires_in=15811200, refresh_token="refre...", expires_in=28800)', ) self.assertEqual(access_token.token, "access_token_removed") self.assertEqual(access_token.type, "bearer") self.assertEqual(access_token.scope, "") self.assertEqual(access_token.expires_in, 28800) self.assertEqual( access_token.expires_at, datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(access_token.refresh_token, "refresh_token_removed") self.assertEqual(access_token.refresh_expires_in, 15811200) self.assertEqual( access_token.refresh_expires_at, datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) def testRefreshAccessToken(self): access_token = self.app.get_access_token("oauth_code_removed", state="state_removed") with mock.patch("github.AccessToken.datetime") as dt: dt.now = mock.Mock(return_value=datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc)) refreshed = self.app.refresh_access_token(access_token.refresh_token) self.assertNotEqual(refreshed.token, access_token.token) self.assertNotEqual(refreshed.refresh_token, access_token.refresh_token) self.assertNotEqual(refreshed.created, access_token.created) # Test string representation self.assertEqual( str(refreshed), 'AccessToken(type="bearer", token="anoth...", scope="", ' 'refresh_token_expires_in=15811200, refresh_token="anoth...", expires_in=28800)', ) self.assertEqual(refreshed.token, "another_access_token_removed") self.assertEqual(refreshed.type, "bearer") self.assertEqual(refreshed.scope, "") self.assertEqual( refreshed.created, datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(refreshed.expires_in, 28800) self.assertEqual( refreshed.expires_at, datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(refreshed.refresh_token, "another_refresh_token_removed") self.assertEqual(refreshed.refresh_expires_in, 15811200) self.assertEqual( refreshed.refresh_expires_at, datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) def testGetAccessTokenBadCode(self): with self.assertRaises(github.BadCredentialsException) as exc: self.app.get_access_token("oauth_code_removed", state="state_removed") self.assertEqual(exc.exception.status, 200) self.assertIn("error", exc.exception.data) self.assertEqual(exc.exception.data["error"], "bad_verification_code") def testGetAccessTokenUnknownError(self): with self.assertRaises(github.GithubException) as exc: self.app.get_access_token("oauth_code_removed", state="state_removed") self.assertEqual(exc.exception.status, 200) self.assertIn("error", exc.exception.data) self.assertEqual(exc.exception.data["error"], "some_unknown_error") def testRefreshAccessTokenBadCode(self): with self.assertRaises(github.BadCredentialsException) as exc: self.app.refresh_access_token("oauth_code_removed") self.assertEqual(exc.exception.status, 200) self.assertIn("error", exc.exception.data) self.assertEqual(exc.exception.data["error"], "bad_verification_code") def testRefreshAccessTokenUnknownError(self): with self.assertRaises(github.GithubException) as exc: self.app.refresh_access_token("oauth_code_removed") self.assertEqual(exc.exception.status, 200) self.assertIn("error", exc.exception.data) self.assertEqual(exc.exception.data["error"], "some_unknown_error") def testCheckError(self): expected_header = {"header": True} expected_data = {"data": True} header, data = aoa._checkError(expected_header, None) self.assertEqual(header, expected_header) self.assertIsNone(data) header, data = aoa._checkError(expected_header, expected_data) self.assertEqual(header, expected_header) self.assertEqual(data, expected_data) with self.assertRaises(github.BadCredentialsException) as exc: aoa._checkError({}, {"error": "bad_verification_code"}) self.assertEqual(exc.exception.status, 200) self.assertIn("error", exc.exception.data) self.assertEqual(exc.exception.data["error"], "bad_verification_code") with self.assertRaises(github.GithubException) as exc: aoa._checkError({}, {"error": "other"}) self.assertEqual(exc.exception.status, 200) self.assertIn("error", exc.exception.data) self.assertEqual(exc.exception.data["error"], "other")
12,910
Python
.py
210
53.585714
116
0.625858
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,574
Issue33.py
PyGithub_PyGithub/tests/Issue33.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue33(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issues/33 def setUp(self): super().setUp() self.repo = self.g.get_user("openframeworks").get_repo("openFrameworks") def testOpenIssues(self): self.assertEqual(len(list(self.repo.get_issues())), 338) def testClosedIssues(self): self.assertEqual(len(list(self.repo.get_issues(state="closed"))), 950)
2,962
Python
.py
40
71.825
85
0.47446
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,575
Authentication.py
PyGithub_PyGithub/tests/Authentication.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Arda Kuyumcu <kuyumcuarda@gmail.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Denis Blanchette <dblanchette@coveo.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 chantra <chantra@users.noreply.github.com> # # Copyright 2024 Jonathan Kliem <jonathan.kliem@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import os from datetime import datetime, timezone from tempfile import NamedTemporaryFile from unittest import mock from unittest.mock import Mock import jwt import github from github.Auth import Auth from . import Framework from .GithubIntegration import APP_ID, PRIVATE_KEY, PUBLIC_KEY class Authentication(Framework.BasicTestCase): def testNoAuthentication(self): g = github.Github() self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") def testBasicAuthentication(self): with self.assertWarns(DeprecationWarning) as warning: g = github.Github(self.login.login, self.login.password) self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") self.assertWarning( warning, "Arguments login_or_token and password are deprecated, please use auth=github.Auth.Login(...) instead", ) def testOAuthAuthentication(self): with self.assertWarns(DeprecationWarning) as warning: g = github.Github(self.oauth_token.token) self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") self.assertWarning( warning, "Argument login_or_token is deprecated, please use auth=github.Auth.Token(...) instead", ) def testJWTAuthentication(self): with self.assertWarns(DeprecationWarning) as warning: g = github.Github(jwt=self.jwt.token) self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") self.assertWarning( warning, "Argument jwt is deprecated, please use auth=github.Auth.AppAuth(...) or " "auth=github.Auth.AppAuthToken(...) instead", ) def testAppAuthentication(self): with self.assertWarns(DeprecationWarning) as warning: app_auth = github.AppAuthentication( app_id=self.app_auth.app_id, private_key=self.app_auth.private_key, installation_id=29782936, ) g = github.Github(app_auth=app_auth) self.assertEqual(g.get_user("ammarmallik").name, "Ammar Akbar") self.assertWarnings( warning, "Call to deprecated class AppAuthentication. (Use github.Auth.AppInstallationAuth instead)", "Argument app_auth is deprecated, please use auth=github.Auth.AppInstallationAuth(...) instead", ) def testLoginAuthentication(self): # test data copied from testBasicAuthentication to test parity g = github.Github(auth=self.login) self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") def testTokenAuthentication(self): # test data copied from testOAuthAuthentication to test parity g = github.Github(auth=self.oauth_token) self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") def testAppAuthTokenAuthentication(self): # test data copied from testJWTAuthentication to test parity g = github.Github(auth=self.jwt) self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") def testAppAuthAuthentication(self): # test data copied from testAppAuthentication to test parity g = github.Github(auth=self.app_auth.get_installation_auth(29782936)) self.assertEqual(g.get_user("ammarmallik").name, "Ammar Akbar") def assert_requester_args(self, g, expected_requester): expected_args = expected_requester.kwargs expected_args.pop("auth") auth_args = g._Github__requester.auth.requester.kwargs auth_args.pop("auth") self.assertEqual(expected_args, auth_args) auth_integration_args = ( g._Github__requester.auth._AppInstallationAuth__integration._GithubIntegration__requester.kwargs ) auth_integration_args.pop("auth") self.assertEqual(expected_args, auth_integration_args) def testAppAuthAuthenticationWithGithubRequesterArgs(self): # test that Requester arguments given to github.Github are passed to auth and auth.__integration g = github.Github( auth=self.app_auth.get_installation_auth(29782936), base_url="https://base.net/", timeout=60, user_agent="agent", per_page=100, verify="cert", retry=999, pool_size=10, seconds_between_requests=100, seconds_between_writes=1000, ) self.assert_requester_args(g, g._Github__requester) def testAppAuthAuthenticationWithGithubIntegrationRequesterArgs(self): # test that Requester arguments given to github.GithubIntegration are passed to auth and auth.__integration gi = github.GithubIntegration( auth=self.app_auth, base_url="https://base.net/", timeout=60, user_agent="agent", per_page=100, verify="cert", retry=999, pool_size=10, seconds_between_requests=100, seconds_between_writes=1000, ) self.assert_requester_args(gi.get_github_for_installation(29782936), gi._GithubIntegration__requester) def testAppInstallationAuthAuthentication(self): # test data copied from testAppAuthentication to test parity installation_auth = github.Auth.AppInstallationAuth(self.app_auth, 29782936) g = github.Github(auth=installation_auth) # test token expiry # token expires 2024-11-25 01:00:02 token = installation_auth.token self.assertFalse(installation_auth._is_expired) self.assertEqual( installation_auth._AppInstallationAuth__installation_authorization.expires_at, datetime(2024, 11, 25, 1, 0, 2, tzinfo=timezone.utc), ) # forward the clock so token expires with mock.patch("github.Auth.datetime") as dt: # just before expiry dt.now = mock.Mock(return_value=datetime(2024, 11, 25, 0, 59, 3, tzinfo=timezone.utc)) self.assertFalse(installation_auth._is_expired) # just after expiry dt.now = mock.Mock(return_value=datetime(2024, 11, 25, 1, 0, 3, tzinfo=timezone.utc)) self.assertTrue(installation_auth._is_expired) # expect refreshing the token refreshed_token = installation_auth.token self.assertNotEqual(refreshed_token, token) self.assertFalse(installation_auth._is_expired) self.assertEqual( installation_auth._AppInstallationAuth__installation_authorization.expires_at, datetime(2025, 11, 25, 1, 0, 2, tzinfo=timezone.utc), ) # use the token self.assertEqual(g.get_user("ammarmallik").name, "Ammar Akbar") self.assertEqual(g.get_repo("PyGithub/PyGithub").full_name, "PyGithub/PyGithub") def testAppInstallationAuthAuthenticationRequesterArgs(self): installation_auth = github.Auth.AppInstallationAuth(self.app_auth, 29782936) github.Github( auth=installation_auth, ) def testAppUserAuthentication(self): client_id = "removed client id" client_secret = "removed client secret" refresh_token = "removed refresh token" g = github.Github() app = g.get_oauth_application(client_id, client_secret) with mock.patch("github.AccessToken.datetime") as dt: dt.now = mock.Mock(return_value=datetime(2023, 6, 7, 12, 0, 0, 123, tzinfo=timezone.utc)) token = app.refresh_access_token(refresh_token) self.assertEqual(token.token, "fresh access token") self.assertEqual(token.type, "bearer") self.assertEqual(token.scope, "") self.assertEqual(token.expires_in, 28800) self.assertEqual( token.expires_at, datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc), ) self.assertEqual(token.refresh_token, "fresh refresh token") self.assertEqual(token.refresh_expires_in, 15811200) self.assertEqual( token.refresh_expires_at, datetime(2023, 12, 7, 12, 0, 0, 123, tzinfo=timezone.utc), ) auth = app.get_app_user_auth(token) with mock.patch("github.Auth.datetime") as dt: dt.now = mock.Mock(return_value=datetime(2023, 6, 7, 20, 0, 0, 123, tzinfo=timezone.utc)) self.assertEqual(auth._is_expired, False) self.assertEqual(auth.token, "fresh access token") self.assertEqual(auth.token_type, "bearer") self.assertEqual(auth.refresh_token, "fresh refresh token") # expire auth token with mock.patch("github.Auth.datetime") as dt: dt.now = mock.Mock(return_value=datetime(2023, 6, 7, 20, 0, 1, 123, tzinfo=timezone.utc)) self.assertEqual(auth._is_expired, True) self.assertEqual(auth.token, "another access token") self.assertEqual(auth._is_expired, False) self.assertEqual(auth.token_type, "bearer") self.assertEqual(auth.refresh_token, "another refresh token") g = github.Github(auth=auth) user = g.get_user() self.assertEqual(user.login, "EnricoMi") def testNetrcAuth(self): with NamedTemporaryFile("wt", delete=False) as tmp: # write temporary netrc file tmp.write("machine api.github.com\n") tmp.write("login github-user\n") tmp.write("password github-password\n") tmp.close() auth = github.Auth.NetrcAuth() with mock.patch.dict(os.environ, {"NETRC": tmp.name}): github.Github(auth=auth) self.assertEqual(auth.login, "github-user") self.assertEqual(auth.password, "github-password") self.assertEqual(auth.token, "Z2l0aHViLXVzZXI6Z2l0aHViLXBhc3N3b3Jk") self.assertEqual(auth.token_type, "Basic") def testNetrcAuthFails(self): # provide an empty netrc file to make sure this test does not find one with NamedTemporaryFile("wt", delete=False) as tmp: tmp.close() auth = github.Auth.NetrcAuth() with mock.patch.dict(os.environ, {"NETRC": tmp.name}): with self.assertRaises(RuntimeError) as exc: github.Github(auth=auth) self.assertEqual(exc.exception.args, ("Could not get credentials from netrc for host api.github.com",)) def testCreateJWT(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY) with mock.patch("github.Auth.time") as t: t.time = mock.Mock(return_value=1550055331.7435968) token = auth.create_jwt() payload = jwt.decode( token, key=PUBLIC_KEY, algorithms=["RS256"], options={"verify_exp": False}, ) self.assertDictEqual(payload, {"iat": 1550055271, "exp": 1550055631, "iss": APP_ID}) def testCreateJWTWithExpiration(self): auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY, jwt_expiry=120, jwt_issued_at=-30) with mock.patch("github.Auth.time") as t: t.time = mock.Mock(return_value=1550055331.7435968) token = auth.create_jwt(60) payload = jwt.decode( token, key=PUBLIC_KEY, algorithms=["RS256"], options={"verify_exp": False}, ) self.assertDictEqual(payload, {"iat": 1550055301, "exp": 1550055391, "iss": APP_ID}) def testUserAgent(self): g = github.Github(user_agent="PyGithubTester") self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") def testAuthorizationHeaderWithLogin(self): # See special case in Framework.fixAuthorizationHeader g = github.Github(auth=github.Auth.Login("fake_login", "fake_password")) with self.assertRaises(github.GithubException): g.get_user().name def testAuthorizationHeaderWithToken(self): # See special case in Framework.fixAuthorizationHeader g = github.Github(auth=github.Auth.Token("ZmFrZV9sb2dpbjpmYWtlX3Bhc3N3b3Jk")) with self.assertRaises(github.GithubException): g.get_user().name def testAddingCustomHeaders(self): requester = github.Github(auth=CustomAuth())._Github__requester def requestRaw(cnx, verb, url, requestHeaders, encoded_input): self.modifiedHeaders = requestHeaders return Mock(), {}, Mock() requester._Requester__requestRaw = requestRaw requestHeaders = {"Custom key": "secret"} requester._Requester__requestEncode(None, "GET", "http://github.com", None, requestHeaders, None, Mock()) self.assertEqual("Custom token", self.modifiedHeaders["Custom key"]) class CustomAuth(Auth): @property def token_type(self) -> str: return "custom auth" @property def token(self) -> str: return "Custom token" def authentication(self, headers): headers["Custom key"] = self.token def mask_authentication(self, headers): headers["Custom key"] = "Masked custom header"
16,370
Python
.py
306
44.53268
119
0.614794
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,576
GlobalAdvisory.py
PyGithub_PyGithub/tests/GlobalAdvisory.py
############################ Copyrights and license ############################ # # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Joseph Henrich <crimsonknave@gmail.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from decimal import Decimal import github.GlobalAdvisory from . import Framework class GlobalAdvisory(Framework.TestCase): advisory: github.GlobalAdvisory.GlobalAdvisory def setUp(self): super().setUp() def testAttributes(self): self.advisory = self.g.get_global_advisory("GHSA-wqc8-x2pr-7jqh") self.assertListKeyEqual( self.advisory.credits, lambda e: (e.user.login, e.type), [ ("loechel", "remediation_developer"), ("Quasar0147", "reporter"), ("despawningbone", "reporter"), ("dataflake", "coordinator"), ("nneonneo", "other"), ], ) self.assertEqual(self.advisory.cve_id, "CVE-2023-37271") self.assertEqual(self.advisory.cvss.version, Decimal("3.1")) self.assertEqual(self.advisory.cvss.score, Decimal("8.4")) self.assertEqual(self.advisory.cvss.vector_string, "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L") self.assertListKeyEqual( self.advisory.cwes, lambda e: (e.cwe_id, e.name), [ ("CWE-913", "Improper Control of Dynamically-Managed Code Resources"), ], ) self.assertEqual( self.advisory.description, "### Impact\n\nRestrictedPython does not check access to stack frames...", ) self.assertEqual(self.advisory.ghsa_id, "GHSA-wqc8-x2pr-7jqh") self.assertEqual( self.advisory.github_reviewed_at, datetime(2023, 7, 10, 21, 53, 22, tzinfo=timezone.utc), ) self.assertEqual( self.advisory.html_url, "https://github.com/advisories/GHSA-wqc8-x2pr-7jqh", ) self.assertListEqual( self.advisory.identifiers, [{"type": "GHSA", "value": "GHSA-wqc8-x2pr-7jqh"}, {"type": "CVE", "value": "CVE-2023-37271"}], ) self.assertEqual(self.advisory.nvd_published_at, None) self.assertEqual( self.advisory.published_at, datetime(2023, 7, 10, 21, 53, 22, tzinfo=timezone.utc), ) self.assertListEqual( self.advisory.references, [ "https://github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-wqc8-x2pr-7jqh", "https://github.com/zopefoundation/RestrictedPython/commit/c8eca66ae49081f0016d2e1f094c3d72095ef531", "https://nvd.nist.gov/vuln/detail/CVE-2023-37271", "https://github.com/pypa/advisory-database/tree/main/vulns/restrictedpython/PYSEC-2023-118.yaml", "https://github.com/advisories/GHSA-wqc8-x2pr-7jqh", ], ) self.assertEqual( self.advisory.repository_advisory_url, "https://api.github.com/repos/zopefoundation/RestrictedPython/security-advisories/GHSA-wqc8-x2pr-7jqh", ) self.assertEqual(self.advisory.severity, "high") self.assertEqual( self.advisory.source_code_location, "https://github.com/zopefoundation/RestrictedPython", ) self.assertEqual( self.advisory.summary, "RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape", ) self.assertEqual( self.advisory.type, "reviewed", ) self.assertEqual( self.advisory.updated_at, datetime(2023, 7, 20, 18, 59, 27, tzinfo=timezone.utc), ) self.assertEqual( self.advisory.url, "https://api.github.com/advisories/GHSA-wqc8-x2pr-7jqh", ) self.assertListKeyEqual( self.advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [ (("pip", "RestrictedPython"), None, [], "< 5.3"), (("pip", "RestrictedPython"), None, [], ">= 6.0a1.dev0, < 6.1"), (("pip", "restrictedpython"), None, [], ">= 0, < 5.3"), ], ) self.assertEqual(self.advisory.withdrawn_at, None) def testNewlyReleased(self): """ Test an advisory that was freshly released and does not have values for all fields. """ self.advisory = self.g.get_global_advisory("GHSA-cx3j-qqxj-9597") self.assertListKeyEqual( self.advisory.credits, lambda e: (e.user.login, e.type), [], ) self.assertEqual(self.advisory.cve_id, "CVE-2023-3481") self.assertEqual(self.advisory.cvss.version, None) self.assertEqual(self.advisory.cvss.score, None) self.assertEqual(self.advisory.cvss.vector_string, None) self.assertListKeyEqual( self.advisory.cwes, lambda e: (e.cwe_id, e.name), [ ("CWE-80", "Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)"), ("CWE-116", "Improper Encoding or Escaping of Output"), ], ) self.assertEqual( self.advisory.description, "### Impact\nCritters version 0.0.17-0.0.19 have an issue when parsing..." ) self.assertEqual(self.advisory.ghsa_id, "GHSA-cx3j-qqxj-9597") self.assertEqual( self.advisory.github_reviewed_at, datetime(2023, 8, 11, 18, 57, 53, tzinfo=timezone.utc), ) self.assertEqual( self.advisory.html_url, "https://github.com/advisories/GHSA-cx3j-qqxj-9597", ) self.assertListEqual( self.advisory.identifiers, [{"type": "GHSA", "value": "GHSA-cx3j-qqxj-9597"}, {"type": "CVE", "value": "CVE-2023-3481"}], ) self.assertEqual(self.advisory.nvd_published_at, None) self.assertEqual( self.advisory.published_at, datetime(2023, 8, 11, 18, 57, 53, tzinfo=timezone.utc), ) self.assertListEqual( self.advisory.references, [ "https://github.com/GoogleChromeLabs/critters/security/advisories/GHSA-cx3j-qqxj-9597", "https://github.com/GoogleChromeLabs/critters/pull/133", "https://github.com/GoogleChromeLabs/critters/commit/7757902c9e0b3285d516359b3cb602cd9d50d80e", "https://github.com/advisories/GHSA-cx3j-qqxj-9597", ], ) self.assertEqual( self.advisory.repository_advisory_url, "https://api.github.com/repos/GoogleChromeLabs/critters/security-advisories/GHSA-cx3j-qqxj-9597", ) self.assertEqual(self.advisory.severity, "high") self.assertEqual( self.advisory.source_code_location, "https://github.com/GoogleChromeLabs/critters", ) self.assertEqual( self.advisory.summary, "Critters Cross-site Scripting Vulnerability", ) self.assertEqual( self.advisory.type, "reviewed", ) self.assertEqual( self.advisory.updated_at, datetime(2023, 8, 11, 18, 57, 54, tzinfo=timezone.utc), ) self.assertEqual( self.advisory.url, "https://api.github.com/advisories/GHSA-cx3j-qqxj-9597", ) self.assertListKeyEqual( self.advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [(("npm", "critters"), None, [], ">= 0.0.17, <= 0.0.19")], ) self.assertEqual(self.advisory.withdrawn_at, None)
9,928
Python
.py
216
35.685185
117
0.542869
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,577
GitBlob.py
PyGithub_PyGithub/tests/GitBlob.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class GitBlob(Framework.TestCase): def setUp(self): super().setUp() self.blob = self.g.get_user().get_repo("PyGithub").get_git_blob("53bce9fa919b4544e67275089b3ec5b44be20667") def testAttributes(self): self.assertTrue( self.blob.content.startswith( "IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgpmcm9tIGRpc3R1dGlscy5jb3JlIGlt\ncG9ydCBzZXR1cAppbXBvcnQgdGV4dHdyYXAKCnNldHVwKAogICAgbmFtZSA9\n" ) ) self.assertTrue( self.blob.content.endswith( "Z3JhbW1pbmcgTGFuZ3VhZ2UgOjogUHl0aG9uIiwKICAgICAgICAiVG9waWMg\nOjogU29mdHdhcmUgRGV2ZWxvcG1lbnQiLAogICAgXSwKKQo=\n" ) ) self.assertEqual(len(self.blob.content), 1757) self.assertEqual(self.blob.encoding, "base64") self.assertEqual(self.blob.size, 1295) self.assertEqual(self.blob.sha, "53bce9fa919b4544e67275089b3ec5b44be20667") self.assertEqual( self.blob.url, "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/53bce9fa919b4544e67275089b3ec5b44be20667", ) self.assertEqual( repr(self.blob), 'GitBlob(sha="53bce9fa919b4544e67275089b3ec5b44be20667")', )
4,020
Python
.py
62
59.774194
142
0.517956
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,578
RepositoryKey.py
PyGithub_PyGithub/tests/RepositoryKey.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Laurent Raufaste <analogue@glop.org> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2024 Ramiro Morales <ramiro@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class RepositoryKey(Framework.TestCase): def setUp(self): super().setUp() # When recording test, be sure to create a deploy key for yourself on # Github and update it here. repo = self.g.get_user("lra").get_repo("mackup") self.key = repo.get_key(21870881) self.yet_unused_key = repo.get_key(98051552) def testAttributes(self): self.assertEqual(self.key.id, 21870881) self.assertEqual( self.key.key, "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLOoLSVPwG1OSgVSeEXNbfIofYdxR5zs3u4PryhnamfFPYwi2vZW3ZxeI1oRcDh2VEdwGvlN5VUduKJNoOWMVzV2jSyR8CeDHH+I0soQCC7kfJVodU96HcPMzZ6MuVwSfD4BFGvKMXyCnBUqzo28BGHFwVQG8Ya9gL6/cTbuWywgM4xaJgMHv1OVcESXBtBkrqOneTJuOgeEmP0RfUnIAK/3/wbg9mfiBq7JV4cmWAg1xNE8GJoAbci59Tdx1dQgVuuqdQGk5jzNusOVneyMtGEB+p7UpPLJsGBW29rsMt7ITUbXM/kl9v11vPtWb+oOUThoFsDYmsWy7fGGP9YAFB", ) self.assertEqual(self.key.title, "PyGithub Test Key") self.assertEqual(self.key.url, "https://api.github.com/repos/lra/mackup/keys/21870881") self.assertEqual( self.key.created_at, datetime(2017, 2, 22, 8, 16, 23, tzinfo=timezone.utc), ) self.assertTrue(self.key.verified) self.assertTrue(self.key.read_only) self.assertEqual(repr(self.key), 'RepositoryKey(title="PyGithub Test Key", id=21870881)') self.assertEqual(self.key.added_by, "key-admin-user") self.assertEqual( self.key.last_used, datetime(2024, 4, 13, 10, 0, 21, tzinfo=timezone.utc), ) def testYetUnusedKey(self): self.assertEqual(self.yet_unused_key.id, 98051552) self.assertEqual( self.yet_unused_key.key, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOXEPB9eqJ2DwZepFxrPwCDczIReVeWOOt3NMs8KOn3h", ) self.assertEqual(self.yet_unused_key.last_used, None) def testDelete(self): self.key.delete()
5,012
Python
.py
76
60.855263
395
0.55285
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,579
GitRef.py
PyGithub_PyGithub/tests/GitRef.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class GitRef(Framework.TestCase): def setUp(self): super().setUp() self.ref = self.g.get_user().get_repo("PyGithub").get_git_ref("heads/BranchCreatedByPyGithub") def testAttributes(self): self.assertEqual(self.ref.object.sha, "1292bf0e22c796e91cc3d6e24b544aece8c21f2a") self.assertEqual(self.ref.object.type, "commit") self.assertEqual( self.ref.object.url, "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1292bf0e22c796e91cc3d6e24b544aece8c21f2a", ) self.assertEqual(self.ref.ref, "refs/heads/BranchCreatedByPyGithub") self.assertEqual( self.ref.url, "https://api.github.com/repos/jacquev6/PyGithub/git/refs/heads/BranchCreatedByPyGithub", ) self.assertEqual(repr(self.ref), 'GitRef(ref="refs/heads/BranchCreatedByPyGithub")') self.assertEqual( repr(self.ref.object), 'GitObject(sha="1292bf0e22c796e91cc3d6e24b544aece8c21f2a")', ) def testEdit(self): self.ref.edit("04cde900a0775b51f762735637bd30de392a2793") def testEditWithForce(self): self.ref.edit("4303c5b90e2216d927155e9609436ccb8984c495", force=True) def testDelete(self): self.ref.delete()
3,983
Python
.py
61
60.688525
114
0.524016
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,580
Issue494.py
PyGithub_PyGithub/tests/Issue494.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue494(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("apache/brooklyn-server", lazy=True) self.pull = self.repo.get_pull(465) def testRepr(self): expected = ( 'PullRequest(title="Change SetHostnameCustomizer to check if ' '/etc/sysconfig/network exist…", number=465)' ) self.assertEqual(self.pull.__repr__(), expected)
3,220
Python
.py
45
68.955556
122
0.48029
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,581
ContentFile.py
PyGithub_PyGithub/tests/ContentFile.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class ContentFile(Framework.TestCase): def setUp(self): super().setUp() self.file = self.g.get_user().get_repo("PyGithub").get_readme() def testAttributes(self): self.assertEqual(self.file.type, "file") self.assertEqual(self.file.encoding, "base64") self.assertEqual(self.file.size, 7531) self.assertEqual(self.file.name, "ReadMe.md") self.assertEqual(self.file.path, "ReadMe.md") self.assertEqual(len(self.file.content), 10212) self.assertEqual(len(self.file.decoded_content), 7531) self.assertEqual(self.file.sha, "5628799a7d517a4aaa0c1a7004d07569cd154df0") self.assertEqual( self.file.download_url, "https://raw.githubusercontent.com/jacquev6/PyGithub/master/README.md", ) self.assertIsNone(self.file.license) self.assertEqual(repr(self.file), 'ContentFile(path="ReadMe.md")')
3,711
Python
.py
54
64.981481
85
0.496304
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,582
Hook.py
PyGithub_PyGithub/tests/Hook.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Hook(Framework.TestCase): def setUp(self): super().setUp() self.hook = self.g.get_user().get_repo("PyGithub").get_hook(257993) def testAttributes(self): self.assertTrue(self.hook.active) # WTF self.assertEqual(self.hook.config, {"url": "http://foobar.com"}) self.assertEqual( self.hook.created_at, datetime(2012, 5, 19, 6, 1, 45, tzinfo=timezone.utc), ) self.assertEqual(self.hook.events, ["push"]) self.assertEqual(self.hook.id, 257993) self.assertEqual(self.hook.last_response.status, "ok") self.assertEqual(self.hook.last_response.message, "OK") self.assertEqual(self.hook.last_response.code, 200) self.assertEqual(self.hook.name, "web") self.assertEqual( self.hook.updated_at, datetime(2012, 5, 29, 18, 49, 47, tzinfo=timezone.utc), ) self.assertEqual(self.hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993") self.assertEqual( self.hook.test_url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/tests", ) self.assertEqual( self.hook.ping_url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/pings", ) self.assertEqual( repr(self.hook), 'Hook(url="https://api.github.com/repos/jacquev6/PyGithub/hooks/257993", id=257993)', ) self.assertEqual(repr(self.hook.last_response), 'HookResponse(status="ok")') def testEditWithMinimalParameters(self): self.hook.edit("web", {"url": "http://foobar.com/hook"}) self.assertEqual(self.hook.config, {"url": "http://foobar.com/hook"}) self.assertEqual( self.hook.updated_at, datetime(2012, 5, 19, 5, 8, 16, tzinfo=timezone.utc), ) def testDelete(self): self.hook.delete() def testTest(self): self.hook.test() # This does not update attributes of hook def testPing(self): self.hook.ping() # This does not update attributes of hook def testEditWithAllParameters(self): self.hook.edit("web", {"url": "http://foobar.com"}, events=["fork", "push"]) self.assertEqual(self.hook.events, ["fork", "push"]) self.hook.edit("web", {"url": "http://foobar.com"}, add_events=["push"]) self.assertEqual(self.hook.events, ["fork", "push"]) self.hook.edit("web", {"url": "http://foobar.com"}, remove_events=["fork"]) self.assertEqual(self.hook.events, ["push"]) self.hook.edit("web", {"url": "http://foobar.com"}, active=True) self.assertTrue(self.hook.active)
5,539
Python
.py
93
53.408602
102
0.532843
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,583
Logging_.py
PyGithub_PyGithub/tests/Logging_.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Hugo <hugovk@users.noreply.github.com> # # Copyright 2018 R1kk3r <R1kk3r@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2024 Jonathan Kliem <jonathan.kliem@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import github from . import Framework from .Authentication import CustomAuth class Logging(Framework.BasicTestCase): class MockLogger: def __init__(self): self.verb = None self.url = None self.requestHeaders = None self.input = None self.status = None self.responseHeaders = None self.output = None def isEnabledFor(self, kind): return True def debug( self, format_string, verb, scheme, hostname, fragment, requestHeaders, input_, status, responseHeaders, output, ): self.verb = verb self.url = f"{scheme}://{hostname}{fragment}" self.requestHeaders = requestHeaders self.input = input_ self.status = status self.responseHeaders = responseHeaders self.output = output def setUp(self): super().setUp() self.logger = self.MockLogger() github.Requester.Requester.injectLogger(self.logger) def tearDown(self): github.Requester.Requester.resetLogger() super().tearDown() def assertLogging(self, verb, url, requestHeaders, responseHeaders, output): self.assertEqual(self.logger.verb, verb) self.assertEqual(self.logger.url, url) self.assertEqual(self.logger.requestHeaders, requestHeaders) self.assertIsNone(self.logger.input) self.assertEqual(self.logger.status, 200) self.assertEqual(self.logger.responseHeaders, responseHeaders) self.assertEqual(self.logger.output, output) def testLoggingWithBasicAuthentication(self): self.assertEqual(github.Github(auth=self.login).get_user().name, "Vincent Jacques") url = "https://api.github.com/user" requestHeaders = { "Authorization": "Basic (login and password removed)", "User-Agent": "PyGithub/Python", } responseHeaders = { "status": "200 OK", "content-length": "806", "x-github-media-type": "github.beta; format=json", "x-content-type-options": "nosniff", "x-ratelimit-limit": "5000", "vary": "Accept, Authorization, Cookie", "x-ratelimit-remaining": "4993", "server": "nginx", "last-modified": "Fri, 14 Sep 2012 18:47:46 GMT", "connection": "keep-alive", "etag": '"434dfe5d3f50558fe3cea087cb95c401"', "cache-control": "private, s-maxage=60, max-age=60", "date": "Mon, 17 Sep 2012 17:12:32 GMT", "content-type": "application/json; charset=utf-8", "DEBUG_FRAME": 0, } output = '{"owned_private_repos":3,"disk_usage":18612,"following":28,"type":"User","public_repos":13,"location":"Paris, France","company":"Criteo","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","plan":{"space":614400,"private_repos":5,"name":"micro","collaborators":1},"blog":"http://vincent-jacques.net","login":"jacquev6","public_gists":3,"html_url":"https://github.com/jacquev6","hireable":false,"created_at":"2010-07-09T06:10:06Z","private_gists":5,"followers":13,"name":"Vincent Jacques","email":"vincent@vincent-jacques.net","bio":"","total_private_repos":3,"collaborators":0,"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"url":"https://api.github.com/users/jacquev6"}' self.assertLogging("GET", url, requestHeaders, responseHeaders, output) def testLoggingWithOAuthAuthentication(self): self.assertEqual(github.Github(auth=self.oauth_token).get_user().name, "Vincent Jacques") url = "https://api.github.com/user" requestHeaders = { "Authorization": "token (oauth token removed)", "User-Agent": "PyGithub/Python", } responseHeaders = { "status": "200 OK", "x-ratelimit-remaining": "4993", "x-github-media-type": "github.beta; format=json", "x-content-type-options": "nosniff", "vary": "Accept, Authorization, Cookie", "content-length": "628", "server": "nginx", "last-modified": "Tue, 25 Sep 2012 07:42:42 GMT", "connection": "keep-alive", "x-ratelimit-limit": "5000", "etag": '"c23ad6b5815fc3d6ec6341c4a47afe85"', "cache-control": "private, max-age=60, s-maxage=60", "date": "Tue, 25 Sep 2012 20:36:54 GMT", "x-oauth-scopes": "", "content-type": "application/json; charset=utf-8", "x-accepted-oauth-scopes": "user", "DEBUG_FRAME": 0, } output = '{"type":"User","bio":"","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","blog":"http://vincent-jacques.net","public_repos":13,"created_at":"2010-07-09T06:10:06Z","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","email":"vincent@vincent-jacques.net","following":29,"name":"Vincent Jacques","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","hireable":false,"id":327146,"public_gists":3,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}' self.assertLogging("GET", url, requestHeaders, responseHeaders, output) def testLoggingWithoutAuthentication(self): self.assertEqual(github.Github().get_user("jacquev6").name, "Vincent Jacques") url = "https://api.github.com/users/jacquev6" requestHeaders = {"User-Agent": "PyGithub/Python"} responseHeaders = { "status": "200 OK", "content-length": "628", "x-github-media-type": "github.beta; format=json", "x-content-type-options": "nosniff", "x-ratelimit-limit": "5000", "vary": "Accept", "x-ratelimit-remaining": "4989", "server": "nginx", "last-modified": "Tue, 25 Sep 2012 07:42:42 GMT", "connection": "keep-alive", "etag": '"9bd085221a16b6d2ea95e72634c3c1ac"', "cache-control": "public, max-age=60, s-maxage=60", "date": "Tue, 25 Sep 2012 20:38:56 GMT", "content-type": "application/json; charset=utf-8", "DEBUG_FRAME": 0, } output = '{"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}' self.assertLogging("GET", url, requestHeaders, responseHeaders, output) def testLoggingWithBaseUrl(self): # ReplayData forged, not recorded self.assertEqual( github.Github(base_url="http://my.enterprise.com/my/prefix").get_user("jacquev6").name, "Vincent Jacques", ) url = "http://my.enterprise.com/my/prefix/users/jacquev6" requestHeaders = {"User-Agent": "PyGithub/Python"} responseHeaders = { "status": "200 OK", "content-length": "628", "x-github-media-type": "github.beta; format=json", "x-content-type-options": "nosniff", "x-ratelimit-limit": "5000", "vary": "Accept", "x-ratelimit-remaining": "4989", "server": "nginx", "last-modified": "Tue, 25 Sep 2012 07:42:42 GMT", "connection": "keep-alive", "etag": '"9bd085221a16b6d2ea95e72634c3c1ac"', "cache-control": "public, max-age=60, s-maxage=60", "date": "Tue, 25 Sep 2012 20:38:56 GMT", "content-type": "application/json; charset=utf-8", "DEBUG_FRAME": 0, } output = '{"type":"User","html_url":"https://github.com/jacquev6","login":"jacquev6","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"vincent@vincent-jacques.net","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}' self.assertLogging("GET", url, requestHeaders, responseHeaders, output) def testLoggingDoesNotModifyRequestHeaders(self): # Recorded replay data already sanitizes Authorization headers, so we # need to go under the covers requestHeaders = {"Authorization": "thisisnotatoken"} responseHeaders = {"status": "200 OK"} github.Github()._Github__requester._Requester__log( "GET", "http://example.com", requestHeaders, None, 200, responseHeaders, None, ) self.assertEqual(requestHeaders["Authorization"], "thisisnotatoken") def testMaskingOfCustomAuthHeader(self): requestHeaders = {"Custom key": "secret"} responseHeaders = {"status": "200 OK"} github.Github(auth=CustomAuth())._Github__requester._Requester__log( "GET", "http://example.com", requestHeaders, None, 200, responseHeaders, None, ) self.assertEqual({"Custom key": "Masked custom header"}, self.logger.requestHeaders)
13,189
Python
.py
218
51.100917
825
0.582047
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,584
Issue80.py
PyGithub_PyGithub/tests/Issue80.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import github from . import Framework class Issue80(Framework.BasicTestCase): # https://github.com/jacquev6/PyGithub/issues/80 def testIgnoreHttpsFromGithubEnterprise(self): g = github.Github(auth=self.login, base_url="http://my.enterprise.com/some/prefix") # http here org = g.get_organization("BeaverSoftware") self.assertEqual(org.url, "https://my.enterprise.com/some/prefix/orgs/BeaverSoftware") # https returned self.assertListKeyEqual( org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"] ) # But still http in second request based on org.url def testIgnoreHttpsFromGithubEnterpriseWithPort(self): g = github.Github( auth=self.login, base_url="http://my.enterprise.com:1234/some/prefix", ) # http here org = g.get_organization("BeaverSoftware") self.assertEqual(org.url, "https://my.enterprise.com:1234/some/prefix/orgs/BeaverSoftware") # https returned self.assertListKeyEqual( org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"] ) # But still http in second request based on org.url
3,775
Python
.py
52
68.730769
117
0.519365
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,585
CommitCombinedStatus.py
PyGithub_PyGithub/tests/CommitCombinedStatus.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 John Eskew <jeskew@edx.org> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class CommitCombinedStatus(Framework.TestCase): def setUp(self): super().setUp() self.combined_status = ( self.g.get_repo("edx/edx-platform", lazy=True) .get_commit("74e70119a23fa3ffb3db19d4590eccfebd72b659") .get_combined_status() ) def testAttributes(self): self.assertEqual(self.combined_status.state, "success") self.assertEqual( self.combined_status.statuses[0].url, "https://api.github.com/repos/edx/edx-platform/statuses/74e70119a23fa3ffb3db19d4590eccfebd72b659", ) self.assertEqual(self.combined_status.statuses[1].id, 390603044) self.assertEqual(self.combined_status.statuses[2].state, "success") self.assertEqual(self.combined_status.statuses[3].description, "Build finished.") self.assertEqual( self.combined_status.statuses[4].target_url, "https://build.testeng.edx.org/job/edx-platform-python-unittests-pr/10504/", ) self.assertEqual( self.combined_status.statuses[4].created_at, datetime(2015, 12, 14, 13, 24, 18, tzinfo=timezone.utc), ) self.assertEqual( self.combined_status.statuses[3].updated_at, datetime(2015, 12, 14, 13, 23, 35, tzinfo=timezone.utc), ) self.assertEqual(self.combined_status.sha, "74e70119a23fa3ffb3db19d4590eccfebd72b659") self.assertEqual(self.combined_status.total_count, 6) self.assertEqual(self.combined_status.repository.id, 10391073) self.assertEqual(self.combined_status.repository.full_name, "edx/edx-platform") self.assertEqual( self.combined_status.commit_url, "https://api.github.com/repos/edx/edx-platform/commits/74e70119a23fa3ffb3db19d4590eccfebd72b659", ) self.assertEqual( self.combined_status.url, "https://api.github.com/repos/edx/edx-platform/commits/74e70119a23fa3ffb3db19d4590eccfebd72b659/status", ) self.assertEqual( repr(self.combined_status), 'CommitCombinedStatus(state="success", sha="74e70119a23fa3ffb3db19d4590eccfebd72b659")', )
5,199
Python
.py
83
56.614458
116
0.543338
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,586
Markdown.py
PyGithub_PyGithub/tests/Markdown.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Markdown(Framework.TestCase): def setUp(self): super().setUp() self.text = "MyTitle\n=======\n\nIssue #1" self.repo = self.g.get_user().get_repo("PyGithub") def testRenderMarkdown(self): self.assertEqual( self.g.render_markdown(self.text), '<h1><a name="mytitle" class="anchor" href="#mytitle"><span class="mini-icon mini-icon-link"></span></a>MyTitle</h1><p>Issue #1</p>', ) def testRenderGithubFlavoredMarkdown(self): self.assertEqual( self.g.render_markdown(self.text, self.repo), '<h1>MyTitle</h1><p>Issue <a href="https://github.com/jacquev6/PyGithub/issues/1" class="issue-link" title="Gitub -&gt; Github everywhere">#1</a></p>', )
3,305
Python
.py
47
66.744681
163
0.47925
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,587
RepositoryAdvisory.py
PyGithub_PyGithub/tests/RepositoryAdvisory.py
############################ Copyrights and license ############################ # # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Jonathan Leitschuh <jonathan.leitschuh@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone import github.RepositoryAdvisory from . import Framework class RepositoryAdvisory(Framework.TestCase): advisory: github.RepositoryAdvisory.RepositoryAdvisory def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("security-research") self.advisory = self.repo.get_repository_advisory("GHSA-wmmh-r9w4-hpxx") self.advisory.clear_credits() self.advisory.offer_credit("octocat", "analyst") def testAttributes(self): self.assertEqual(self.advisory.author.login, "JLLeitschuh") self.assertEqual(self.advisory.closed_at, None) self.assertEqual( self.advisory.created_at, datetime(2023, 3, 28, 21, 41, 40, tzinfo=timezone.utc), ) self.assertListKeyEqual(self.advisory.credits, lambda e: (e.login, e.type), [("octocat", "analyst")]) self.assertListKeyEqual( self.advisory.credits_detailed, lambda e: (e.user.login, e.type), [("octocat", "analyst")], ) self.assertEqual(self.advisory.cve_id, "CVE-2023-00000") self.assertListEqual(self.advisory.cwe_ids, ["CWE-400", "CWE-501"]) self.assertListKeyEqual( self.advisory.cwes, lambda e: (e.cwe_id, e.name), [ ("CWE-400", "Uncontrolled Resource Consumption"), ("CWE-501", "Trust Boundary Violation"), ], ) self.assertEqual( self.advisory.description, "This is a detailed description of this advisories impact and patches.", ) self.assertEqual(self.advisory.ghsa_id, "GHSA-wmmh-r9w4-hpxx") self.assertEqual( self.advisory.html_url, "https://github.com/JLLeitschuh/security-research/security/advisories/GHSA-wmmh-r9w4-hpxx", ) self.assertEqual(self.advisory.published_at, None) self.assertEqual(self.advisory.severity, "high") self.assertEqual(self.advisory.state, "draft") self.assertEqual(self.advisory.summary, "A test creating a GHSA via the API") self.assertEqual( self.advisory.updated_at, datetime(2023, 3, 30, 19, 31, 33, tzinfo=timezone.utc), ) self.assertEqual( self.advisory.url, "https://api.github.com/repos/JLLeitschuh/security-research/security-advisories/GHSA-wmmh-r9w4-hpxx", ) self.assertListKeyEqual( self.advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [(("npm", "a-package"), "1.0.5", ["function-name"], ">= 1.0.2")], ) self.assertEqual(self.advisory.withdrawn_at, None) def testRemoveCredit(self): self.advisory.revoke_credit("octocat") self.assertListKeyEqual( self.advisory.credits, lambda e: e.login, [], ) self.assertListKeyEqual( self.advisory.credits_detailed, lambda e: e.user.login, [], ) def testOfferCredit(self): self.advisory.offer_credit("JLLeitschuh", "reporter") self.assertListKeyEqual( self.advisory.credits, lambda e: e.login, ["octocat", "JLLeitschuh"], ) self.assertListKeyEqual( self.advisory.credits_detailed, lambda e: e.user.login, ["octocat", "JLLeitschuh"], ) def testOfferCredits(self): self.advisory.clear_credits() self.advisory.offer_credits( [ {"login": "octocat", "type": "sponsor"}, {"login": "JLLeitschuh", "type": "reporter"}, ] ) self.assertListKeyEqual( self.advisory.credits_detailed, lambda e: (e.user.login, e.type), [("octocat", "sponsor"), ("JLLeitschuh", "reporter")], ) def testRepositoryWithNoAdvisories(self): repo = self.g.get_user().get_repo("PyGithub") self.assertListKeyEqual( repo.get_repository_advisories(), lambda e: e.ghsa_id, [], ) def testGetAdvisories(self): self.assertListKeyEqual( self.repo.get_repository_advisories(), lambda e: e.ghsa_id, [ "GHSA-wmmh-r9w4-hpxx", "GHSA-wvgm-59wj-rh8h", "GHSA-22cq-8f5q-p5g2", "GHSA-7hfp-mpq6-2jhf", "GHSA-hfmw-fx2m-jj4c", "GHSA-rvp4-r3g6-8hxq", "GHSA-cm59-pr5q-cw85", "GHSA-vpcc-9rh2-8jfp", "GHSA-7fjx-657r-9r5h", "GHSA-22c6-wcjm-qfjg", "GHSA-5w9v-8x7x-rfqm", "GHSA-2r85-x9cf-8fcg", "GHSA-6m9h-r5m3-9r7f", "GHSA-f4jh-ww96-9h9j", "GHSA-j83w-7qr9-wv86", "GHSA-7gf3-89f6-823j", "GHSA-jpcm-4485-69p7", ], ) def testCreateRepositoryAdvisory(self): repo = self.g.get_repo("JLLeitschuh/code-sandbox") advisory = repo.create_repository_advisory( "A test creating a GHSA via the API", "This is a detailed description of this advisories impact and patches.", "high", "CVE-2000-00000", vulnerabilities=[ { "package": {"ecosystem": "npm", "name": "b-package"}, "vulnerable_version_range": "<=4.0.4", "patched_versions": "4.0.5", "vulnerable_functions": ["function-name"], } ], cwe_ids=["CWE-401", "CWE-502"], credits=[ {"login": "octocat", "type": "analyst"}, {"login": "JLLeitschuh", "type": "reporter"}, ], ) self.assertEqual(advisory.ghsa_id, "GHSA-g45c-2crh-4xmp") self.assertEqual(advisory.summary, "A test creating a GHSA via the API") self.assertEqual( advisory.description, "This is a detailed description of this advisories impact and patches.", ) self.assertEqual(advisory.severity, "high") self.assertEqual(advisory.cve_id, "CVE-2000-00000") self.assertListKeyEqual( advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [(("npm", "b-package"), "4.0.5", ["function-name"], "<=4.0.4")], ) self.assertListKeyEqual( advisory.cwe_ids, lambda e: e, ["CWE-401", "CWE-502"], ) self.assertListKeyEqual( advisory.credits_detailed, lambda e: (e.user.login, e.type), [("octocat", "analyst"), ("JLLeitschuh", "reporter")], ) def testUpdateRepositoryAdvisory(self): repo = self.g.get_repo("JLLeitschuh/code-sandbox") advisory = repo.get_repository_advisory("GHSA-g45c-2crh-4xmp") advisory.edit( summary="A test updating a GHSA via the API", description="This is an updated detailed description of this advisories impact and patches.", severity_or_cvss_vector_string="low", cve_id="CVE-2000-00001", vulnerabilities=[ { "package": {"ecosystem": "npm", "name": "c-package"}, "vulnerable_version_range": "<=4.0.6", "patched_versions": "4.0.7", "vulnerable_functions": ["function-name-a"], } ], cwe_ids=["CWE-402", "CWE-500"], credits=[ {"login": "octocat", "type": "sponsor"}, {"login": "JLLeitschuh", "type": "reporter"}, ], ) self.assertEqual(advisory.ghsa_id, "GHSA-g45c-2crh-4xmp") self.assertEqual(advisory.summary, "A test updating a GHSA via the API") self.assertEqual( advisory.description, "This is an updated detailed description of this advisories impact and patches.", ) self.assertEqual(advisory.severity, "low") self.assertEqual(advisory.cve_id, "CVE-2000-00001") self.assertListKeyEqual( advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [(("npm", "c-package"), "4.0.7", ["function-name-a"], "<=4.0.6")], ) self.assertListKeyEqual( advisory.cwe_ids, lambda e: e, ["CWE-402", "CWE-500"], ) self.assertListKeyEqual( advisory.credits_detailed, lambda e: (e.user.login, e.type), [("octocat", "sponsor"), ("JLLeitschuh", "reporter")], ) def testUpdateSingleFieldDoesNotRemoveOtherFields(self): repo = self.g.get_repo("JLLeitschuh/code-sandbox") advisory = repo.create_repository_advisory( "A test editing a GHSA via the API with only a single manipulation", "This is a detailed description of this advisories impact and patches.", "high", "CVE-2000-00000", vulnerabilities=[ { "package": {"ecosystem": "npm", "name": "b-package"}, "vulnerable_version_range": "<=4.0.4", "patched_versions": "4.0.5", "vulnerable_functions": ["function-name"], } ], cwe_ids=["CWE-401", "CWE-502"], credits=[ {"login": "octocat", "type": "analyst"}, {"login": "JLLeitschuh", "type": "reporter"}, ], ) advisory.edit(description="A modified description") self.assertEqual(advisory.ghsa_id, "GHSA-4wwp-8jp9-9233") self.assertEqual( advisory.summary, "A test editing a GHSA via the API with only a single manipulation", ) self.assertEqual(advisory.description, "A modified description") self.assertEqual(advisory.severity, "high") self.assertEqual(advisory.cve_id, "CVE-2000-00000") self.assertListKeyEqual( advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [(("npm", "b-package"), "4.0.5", ["function-name"], "<=4.0.4")], ) self.assertListKeyEqual( advisory.cwe_ids, lambda e: e, ["CWE-401", "CWE-502"], ) self.assertListKeyEqual( advisory.credits_detailed, lambda e: (e.user.login, e.type), [("octocat", "analyst"), ("JLLeitschuh", "reporter")], ) def testAddVulnerability(self): repo = self.g.get_repo("JLLeitschuh/code-sandbox") advisory = repo.create_repository_advisory( summary="A test creating a GHSA via the API adding and removing vulnerabilities", description="Simple description", severity_or_cvss_vector_string="low", ) advisory.add_vulnerability(ecosystem="maven") self.assertListKeyEqual( advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [(("maven", None), None, [], None)], ) advisory.add_vulnerability( ecosystem="npm", package_name="b-package", vulnerable_version_range="<=4.0.9", patched_versions="4.0.10", vulnerable_functions=["function-name-c"], ) self.assertListKeyEqual( advisory.vulnerabilities, lambda e: ( (e.package.ecosystem, e.package.name), e.patched_versions, e.vulnerable_functions, e.vulnerable_version_range, ), [ (("maven", None), None, [], None), (("npm", "b-package"), "4.0.10", ["function-name-c"], "<=4.0.9"), ], )
14,724
Python
.py
344
31.27907
113
0.521094
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,588
Issue133.py
PyGithub_PyGithub/tests/Issue133.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class Issue133(Framework.TestCase): # https://github.com/jacquev6/PyGithub/pull/133 def setUp(self): super().setUp() self.user = self.g.get_user() def testGetPageWithoutInitialArguments(self): self.assertEqual(len(self.user.get_followers().get_page(0)), 22)
2,835
Python
.py
38
72.657895
85
0.465091
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,589
PullRequestComment.py
PyGithub_PyGithub/tests/PullRequestComment.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Nicolas Agustín Torres <nicolastrres@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Huan-Cheng Chang <changhc84@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class PullRequestComment(Framework.TestCase): def setUp(self): super().setUp() self.comment = self.g.get_user().get_repo("PyGithub").get_pull(31).get_comment(886298) def testAttributes(self): self.assertEqual(self.comment.body, "Comment created by PyGithub") self.assertEqual(self.comment.commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206") self.assertEqual( self.comment.created_at, datetime(2012, 5, 27, 9, 40, 12, tzinfo=timezone.utc), ) self.assertEqual(self.comment.id, 886298) self.assertEqual(self.comment.original_commit_id, "8a4f306d4b223682dd19410d4a9150636ebe4206") self.assertEqual(self.comment.original_position, 5) self.assertEqual(self.comment.path, "src/github/Issue.py") self.assertEqual(self.comment.position, 5) self.assertEqual( self.comment.updated_at, datetime(2012, 5, 27, 9, 40, 12, tzinfo=timezone.utc), ) self.assertEqual( self.comment.url, "https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298", ) self.assertEqual(self.comment.user.login, "jacquev6") self.assertEqual( self.comment.html_url, "https://github.com/jacquev6/PyGithub/pull/170#issuecomment-18637907", ) self.assertEqual( repr(self.comment), 'PullRequestComment(user=NamedUser(login="jacquev6"), id=886298)', ) def testEdit(self): self.comment.edit("Comment edited by PyGithub") self.assertEqual(self.comment.body, "Comment edited by PyGithub") def testDelete(self): self.comment.delete() def testGetReactions(self): reactions = self.comment.get_reactions() self.assertEqual(reactions[0].content, "+1") def testCreateReaction(self): reaction = self.comment.create_reaction("hooray") self.assertEqual(reaction.id, 17283822) self.assertEqual(reaction.content, "hooray") def testDeleteReaction(self): self.assertTrue(self.comment.delete_reaction(85750463))
5,058
Python
.py
84
54.559524
101
0.547451
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,590
PullRequest1375.py
PyGithub_PyGithub/tests/PullRequest1375.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Matthew Neal <meneal@matthews-mbp.raleigh.ibm.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2016 Sam Corbett <sam.corbett@cloudsoftcorp.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Olof-Joachim Frahm (欧雅福) <olof@macrolet.net> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PullRequest1375(Framework.TestCase): def setUp(self): super().setUp() self.pr = self.g.get_repo("rsn491/PyGithub").get_pulls()[0] def testCreateReviewCommentReply(self): comment_id = 373866377 # id of pull request comment without replies first_reply_body = "Comment reply created by PyGithub" second_reply_body = "Second comment reply created by PyGithub" first_reply = self.pr.create_review_comment_reply(comment_id, first_reply_body) second_reply = self.pr.create_review_comment_reply(first_reply.id, second_reply_body) # ensure both first and second reply have `in_reply_to_id` attr set to top comment self.assertEqual(first_reply.in_reply_to_id, comment_id) self.assertEqual(second_reply.in_reply_to_id, comment_id) self.assertEqual(first_reply.body, first_reply_body) self.assertEqual(second_reply.body, second_reply_body)
3,816
Python
.py
51
71.529412
93
0.523454
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,591
Autolink.py
PyGithub_PyGithub/tests/Autolink.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2022 Marco Köpcke <hello@parakoopa.de> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Oskar Jansson <56458534+janssonoskar@users.noreply.github.com># # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from tests import Framework class Autolink(Framework.TestCase): def setUp(self): super().setUp() # When recording test, be sure to create a autolink for yourself on # Github and update it here. links = [x for x in self.g.get_user("theCapypara").get_repo("PyGithub").get_autolinks() if x.id == 209614] self.assertEqual(1, len(links), "There must be exactly one autolink with the ID 209614.") self.link = links[0] def testAttributes(self): self.assertEqual(self.link.id, 209614) self.assertEqual(self.link.key_prefix, "DUMMY-") self.assertEqual(self.link.url_template, "https://github.com/PyGithub/PyGithub/issues/<num>") self.assertEqual(self.link.is_alphanumeric, True)
3,603
Python
.py
49
70.653061
114
0.506761
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,592
Download.py
PyGithub_PyGithub/tests/Download.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Download(Framework.TestCase): def setUp(self): super().setUp() self.download = self.g.get_user().get_repo("PyGithub").get_download(242550) def testAttributes(self): self.assertEqual(self.download.accesskeyid, None) self.assertEqual(self.download.acl, None) self.assertEqual(self.download.bucket, None) self.assertEqual(self.download.content_type, "text/plain") self.assertEqual( self.download.created_at, datetime(2012, 5, 22, 18, 58, 32, tzinfo=timezone.utc), ) self.assertEqual(self.download.description, None) self.assertEqual(self.download.download_count, 0) self.assertEqual(self.download.expirationdate, None) self.assertEqual( self.download.html_url, "https://github.com/downloads/jacquev6/PyGithub/Foobar.txt", ) self.assertEqual(self.download.id, 242550) self.assertEqual(self.download.mime_type, None) self.assertEqual(self.download.name, "Foobar.txt") self.assertEqual(self.download.path, None) self.assertEqual(self.download.policy, None) self.assertEqual(self.download.prefix, None) self.assertEqual(self.download.redirect, None) self.assertEqual(self.download.s3_url, None) self.assertEqual(self.download.signature, None) self.assertEqual(self.download.size, 1024) self.assertEqual( self.download.url, "https://api.github.com/repos/jacquev6/PyGithub/downloads/242550", ) self.assertEqual(repr(self.download), "Download(id=242550)") def testDelete(self): self.download.delete()
4,364
Python
.py
71
56.15493
85
0.532307
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,593
PaginatedList.py
PyGithub_PyGithub/tests/PaginatedList.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2013 davidbrai <davidbrai@gmail.com> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2015 Eliot Walker <eliot@lyft.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2021 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2022 Liuyang Wan <tsfdye@gmail.com> # # Copyright 2023 Andrew Dawes <53574062+AndrewJDawes@users.noreply.github.com> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 YugoHino <henom06@gmail.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from github.PaginatedList import PaginatedList as PaginatedListImpl from . import Framework class PaginatedList(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user("openframeworks").get_repo("openFrameworks") self.list = self.repo.get_issues() self.licenses = self.g.get_enterprise("beaver-group").get_consumed_licenses() def testIteration(self): self.assertEqual(len(list(self.list)), 333) def testIterationWithPrefetchedFirstPage(self): # test data taken from EnterpriseAdmin.testGetEnterpriseUsers users = self.licenses.get_users() self.assertEqual(len(list(users)), 102) self.assertEqual(len({user.github_com_login for user in users}), 102) def testSeveralIterations(self): self.assertEqual(len(list(self.list)), 333) self.assertEqual(len(list(self.list)), 333) self.assertEqual(len(list(self.list)), 333) self.assertEqual(len(list(self.list)), 333) def testIntIndexingInFirstPage(self): self.assertEqual(self.list[0].id, 4772349) self.assertEqual(self.list[24].id, 4286936) def testReversedIterationWithSinglePage(self): r = self.list.reversed self.assertEqual(r[0].id, 4286936) self.assertEqual(r[1].id, 4317009) def testReversedIterationWithMultiplePages(self): r = self.list.reversed self.assertEqual(r[0].id, 94898) self.assertEqual(r[1].id, 104702) self.assertEqual(r[13].id, 166211) self.assertEqual(r[14].id, 166212) self.assertEqual(r[15].id, 166214) def testReversedIterationSupportsIterator(self): r = self.list.reversed for i in r: self.assertEqual(i.id, 4286936) return self.fail("empty iterator") def testGettingTheReversedListDoesNotModifyTheOriginalList(self): self.assertEqual(self.list[0].id, 18345408) self.assertEqual(self.list[30].id, 17916118) r = self.list.reversed self.assertEqual(self.list[0].id, 18345408) self.assertEqual(self.list[30].id, 17916118) self.assertEqual(r[0].id, 132373) self.assertEqual(r[30].id, 543694) def testIntIndexingInThirdPage(self): self.assertEqual(self.list[50].id, 3911629) self.assertEqual(self.list[74].id, 3605277) def testGetFirstPage(self): self.assertListKeyEqual( self.list.get_page(0), lambda i: i.id, [ 4772349, 4767675, 4758608, 4700182, 4662873, 4608132, 4604661, 4588997, 4557803, 4554058, 4539985, 4507572, 4507492, 4507416, 4447561, 4406584, 4384548, 4383465, 4373361, 4373201, 4370619, 4356530, 4352401, 4317009, 4286936, ], ) def testGetThirdPage(self): self.assertListKeyEqual( self.list.get_page(2), lambda i: i.id, [ 3911629, 3911537, 3910580, 3910555, 3910549, 3897090, 3883598, 3856005, 3850655, 3825582, 3813852, 3812318, 3812275, 3807459, 3799872, 3799653, 3795495, 3754055, 3710293, 3662214, 3647640, 3631618, 3627067, 3614231, 3605277, ], ) def testIntIndexingAfterIteration(self): self.assertEqual(len(list(self.list)), 333) self.assertEqual(self.list[11].id, 4507572) self.assertEqual(self.list[73].id, 3614231) self.assertEqual(self.list[332].id, 94898) def testSliceIndexingInFirstPage(self): self.assertListKeyEqual( self.list[:13], lambda i: i.id, [ 4772349, 4767675, 4758608, 4700182, 4662873, 4608132, 4604661, 4588997, 4557803, 4554058, 4539985, 4507572, 4507492, ], ) self.assertListKeyEqual( self.list[:13:3], lambda i: i.id, [4772349, 4700182, 4604661, 4554058, 4507492], ) self.assertListKeyEqual(self.list[10:13], lambda i: i.id, [4539985, 4507572, 4507492]) self.assertListKeyEqual(self.list[5:13:3], lambda i: i.id, [4608132, 4557803, 4507572]) def testSliceIndexingUntilFourthPage(self): self.assertListKeyEqual( self.list[:99:10], lambda i: i.id, [ 4772349, 4539985, 4370619, 4207350, 4063366, 3911629, 3813852, 3647640, 3528378, 3438233, ], ) self.assertListKeyEqual( self.list[73:78], lambda i: i.id, [3614231, 3605277, 3596240, 3594731, 3593619], ) self.assertListKeyEqual( self.list[70:80:2], lambda i: i.id, [3647640, 3627067, 3605277, 3594731, 3593430], ) def testSliceIndexingUntilEnd(self): self.assertListKeyEqual( self.list[310::3], lambda i: i.id, [268332, 204247, 169176, 166211, 165898, 163959, 132373, 104702], ) self.assertListKeyEqual( self.list[310:], lambda i: i.id, [ 268332, 211418, 205935, 204247, 172424, 171615, 169176, 166214, 166212, 166211, 166209, 166208, 165898, 165537, 165409, 163959, 132671, 132377, 132373, 130269, 111018, 104702, 94898, ], ) def testInterruptedIteration(self): # No asserts, but checks that only three pages are fetched count = 0 for element in self.list: # pragma no branch (exits only by break) count += 1 if count == 75: break def testInterruptedIterationInSlice(self): # No asserts, but checks that only three pages are fetched count = 0 # pragma no branch (exits only by break) for element in self.list[:100]: count += 1 if count == 75: break def testTotalCountWithNoLastPage(self): # Fudged replay data, we don't need the data, only the headers repos = self.g.get_repos() self.assertEqual(0, repos.totalCount) def testTotalCountWithDictionary(self): # PullRequest.get_review_requests() actually returns a dictionary that # we fudge into two lists, which means data is a dict, not a list. # We should check the member, not data itself for totalCount. pr = self.g.get_repo("PyGithub/PyGithub").get_pull(2078) review_requests = pr.get_review_requests() self.assertEqual(review_requests[0].totalCount, 0) self.assertEqual(review_requests[1].totalCount, 0) def testCustomPerPage(self): self.assertEqual(self.g.per_page, 30) self.g.per_page = 100 self.assertEqual(self.g.per_page, 100) self.assertEqual(len(list(self.repo.get_issues())), 456) def testCustomPerPageWithNoUrlParams(self): from . import ( # Don't polute github.tests namespace, it would conflict with github.tests.CommitComment CommitComment, ) self.g.per_page = 100 PaginatedListImpl( CommitComment.CommitComment, self.repo._requester, f"{self.repo.url}/comments", None, ) def testCustomPerPageWithNoUrlParams2(self): # This test is redundant and less unitary than testCustomPerPageWithNoUrlParams # but I hope it will be more robust if we refactor PaginatedList, # because testCustomPerPageWithNoUrlParams only tests the constructor self.g.per_page = 100 self.assertEqual(len(list(self.repo.get_comments())), 325) def testCustomPerPageWithGetPage(self): self.g.per_page = 100 self.assertEqual(len(self.repo.get_issues().get_page(2)), 100) def testNoFirstPage(self): self.assertFalse(next(iter(self.list), None)) def testMergeDicts(self): self.assertDictEqual( PaginatedListImpl.merge_dicts( {"a": 1, "b": 2, "c": 3}, {"c": 4, "d": 5, "e": 6}, ), {"a": 1, "b": 2, "c": 4, "d": 5, "e": 6}, ) def testOverrideAttributes(self): input_dict = {"a": 1, "b": 2, "c": 3} overrides_dict = {"c": 4, "d": 5, "e": 6} transformer = PaginatedListImpl.override_attributes(overrides_dict) self.assertDictEqual(transformer(input_dict), {"a": 1, "b": 2, "c": 4, "d": 5, "e": 6})
12,884
Python
.py
314
30.187898
113
0.517984
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,594
UserKey.py
PyGithub_PyGithub/tests/UserKey.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class UserKey(Framework.TestCase): def setUp(self): super().setUp() self.key = self.g.get_user().get_key(2626650) def testAttributes(self): self.assertEqual(self.key.id, 2626650) self.assertEqual( self.key.key, "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw==", ) self.assertEqual(self.key.title, "Key added through PyGithub") self.assertEqual(self.key.url, "https://api.github.com/user/keys/2626650") self.assertTrue(self.key.verified) self.assertEqual( repr(self.key), 'UserKey(title="Key added through PyGithub", id=2626650)', ) def testDelete(self): self.key.delete()
3,760
Python
.py
53
67.056604
395
0.52188
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,595
GitMembership.py
PyGithub_PyGithub/tests/GitMembership.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Simon <spam@esemi.ru> # # Copyright 2018 Laurent Raufaste <analogue@glop.org> # # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Adam Baratz <adam.baratz@gmail.com> # # Copyright 2019 Pavan Kunisetty <nagapavan@users.noreply.github.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class GitMembership(Framework.TestCase): def testGetMembership(self): octocat = self.g.get_user() self.assertEqual(octocat.login, "octocat") membership_data = octocat.get_organization_membership("github") self.assertEqual(membership_data.user.login, "octocat") self.assertEqual(membership_data.role, "admin") self.assertEqual(membership_data.organization.login, "github")
3,453
Python
.py
46
72.869565
85
0.482667
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,596
PullRequestFile.py
PyGithub_PyGithub/tests/PullRequestFile.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from . import Framework class PullRequestFile(Framework.TestCase): def setUp(self): super().setUp() self.file = self.g.get_user().get_repo("PyGithub").get_pull(31).get_files()[0] def testAttributes(self): self.assertEqual(self.file.additions, 1) self.assertEqual( self.file.blob_url, "https://github.com/jacquev6/PyGithub/blob/8a4f306d4b223682dd19410d4a9150636ebe4206/codegen/templates/GithubObject.py", ) self.assertEqual(self.file.changes, 2) self.assertEqual(self.file.deletions, 1) self.assertEqual(self.file.filename, "codegen/templates/GithubObject.py") self.assertEqual( self.file.patch, '@@ -70,7 +70,7 @@ def __useAttributes( self, attributes ):\n \n # @toto No need to check if attribute is in attributes when attribute is mandatory\n {% for attribute in class.attributes|dictsort:"name" %}\n- if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None:\n+ if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None: # pragma no branch\n \n {% if attribute.type.cardinality == "scalar" %}\n {% if attribute.type.simple %}', ) self.assertEqual( self.file.raw_url, "https://github.com/jacquev6/PyGithub/raw/8a4f306d4b223682dd19410d4a9150636ebe4206/codegen/templates/GithubObject.py", ) self.assertEqual(self.file.sha, "8a4f306d4b223682dd19410d4a9150636ebe4206") self.assertEqual(self.file.status, "modified") self.assertEqual( repr(self.file), 'File(sha="8a4f306d4b223682dd19410d4a9150636ebe4206", filename="codegen/templates/GithubObject.py")', )
4,379
Python
.py
60
68.05
540
0.528158
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,597
Persistence.py
PyGithub_PyGithub/tests/Persistence.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Hugo <hugovk@users.noreply.github.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from io import BytesIO as IO import github from . import Framework class Persistence(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_repo("akfish/PyGithub") self.dumpedRepo = IO() self.g.dump(self.repo, self.dumpedRepo) self.dumpedRepo.seek(0) def tearDown(self): self.dumpedRepo.close() super().tearDown() def testLoad(self): loadedRepo = self.g.load(self.dumpedRepo) self.assertTrue(isinstance(loadedRepo, github.Repository.Repository)) self.assertTrue(loadedRepo._requester is self.repo._requester) self.assertTrue(loadedRepo.owner._requester is self.repo._requester) self.assertEqual(loadedRepo.name, "PyGithub") self.assertEqual(loadedRepo.url, "https://api.github.com/repos/akfish/PyGithub") def testLoadAndUpdate(self): loadedRepo = self.g.load(self.dumpedRepo) self.assertTrue(loadedRepo.update())
3,577
Python
.py
55
61.4
88
0.508682
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,598
Issue.py
PyGithub_PyGithub/tests/Issue.py
############################ Copyrights and license ############################ # # # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2012 Zearin <zearin@gonk.net> # # Copyright 2013 Stuart Glaser <stuglaser@gmail.com> # # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> # # Copyright 2016 @tmshn <tmshn@r.recruit.co.jp> # # Copyright 2016 Jannis Gebauer <ja.geb@me.com> # # Copyright 2016 Matt Babineau <babineaum@users.noreply.github.com> # # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> # # Copyright 2017 Nicolas Agustín Torres <nicolastrres@gmail.com> # # Copyright 2018 sfdye <tsfdye@gmail.com> # # Copyright 2019 Filipe Laíns <filipe.lains@gmail.com> # # Copyright 2019 Nick Campbell <nicholas.j.campbell@gmail.com> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Huan-Cheng Chang <changhc84@gmail.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # Copyright 2023 Nicolas Schweitzer <nicolas.schweitzer@datadoghq.com> # # Copyright 2024 Enrico Minack <github@enrico.minack.dev> # # Copyright 2024 Malik Shahzad Muzaffar <shahzad.malik.muzaffar@cern.ch> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ from datetime import datetime, timezone from . import Framework class Issue(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("PyGithub") self.issue = self.repo.get_issue(28) def testAttributes(self): self.assertEqual(self.issue.assignee.login, "jacquev6") self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) self.assertEqual(self.issue.body, "Body edited by PyGithub") self.assertEqual( self.issue.closed_at, datetime(2012, 5, 26, 14, 59, 33, tzinfo=timezone.utc), ) self.assertEqual(self.issue.closed_by.login, "jacquev6") self.assertEqual(self.issue.comments, 0) self.assertEqual( self.issue.comments_url, "https://github.com/jacquev6/PyGithub/issues/28/comments", ) self.assertEqual( self.issue.created_at, datetime(2012, 5, 19, 10, 38, 23, tzinfo=timezone.utc), ) self.assertEqual( self.issue.events_url, "https://github.com/jacquev6/PyGithub/issues/28/events", ) self.assertEqual(self.issue.html_url, "https://github.com/jacquev6/PyGithub/issues/28") self.assertEqual(self.issue.id, 4653757) self.assertListKeyEqual( self.issue.labels, lambda lb: lb.name, ["Bug", "Project management", "Question"], ) self.assertEqual( self.issue.labels_url, "https://github.com/jacquev6/PyGithub/issues/28/labels{/name}", ) self.assertEqual(self.issue.milestone.title, "Version 0.4") self.assertEqual(self.issue.number, 28) self.assertEqual(self.issue.pull_request.diff_url, None) self.assertEqual(self.issue.pull_request.patch_url, None) self.assertEqual(self.issue.pull_request.html_url, None) self.assertEqual(self.issue.state, "closed") self.assertEqual(self.issue.state_reason, "completed") self.assertEqual(self.issue.title, "Issue created by PyGithub") self.assertEqual( self.issue.updated_at, datetime(2012, 5, 26, 14, 59, 33, tzinfo=timezone.utc), ) self.assertEqual(self.issue.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/28") self.assertFalse(self.issue.locked) self.assertIsNone(self.issue.active_lock_reason) self.assertEqual(self.issue.user.login, "jacquev6") self.assertEqual(self.issue.repository.name, "PyGithub") self.assertEqual(repr(self.issue), 'Issue(title="Issue created by PyGithub", number=28)') self.assertEqual( self.issue.reactions, { "+1": 0, "-1": 0, "confused": 0, "eyes": 0, "heart": 0, "hooray": 2, "laugh": 0, "rocket": 0, "total_count": 2, "url": "https://api.github.com/repos/PyGithub/PyGithub/issues/28/reactions", }, ) def testEditWithoutParameters(self): self.issue.edit() def testEditWithAllParameters(self): user = self.g.get_user("jacquev6") milestone = self.repo.get_milestone(2) self.issue.edit( "Title edited by PyGithub", "Body edited by PyGithub", user, "open", milestone, ["Bug"], ["jacquev6", "stuglaser"], ) self.assertEqual(self.issue.assignee.login, "jacquev6") self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) self.assertEqual(self.issue.body, "Body edited by PyGithub") self.assertEqual(self.issue.state, "open") self.assertEqual(self.issue.title, "Title edited by PyGithub") self.assertListKeyEqual(self.issue.labels, lambda lb: lb.name, ["Bug"]) def testEditResetMilestone(self): self.assertEqual(self.issue.milestone.title, "Version 0.4") self.issue.edit(milestone=None) self.assertEqual(self.issue.milestone, None) def testEditResetAssignee(self): self.assertEqual(self.issue.assignee.login, "jacquev6") self.issue.edit(assignee=None) self.assertEqual(self.issue.assignee, None) def testEditWithStateReasonNotPlanned(self): self.issue.edit(state="closed", state_reason="not_planned") self.assertEqual(self.issue.state, "closed") self.assertEqual(self.issue.state_reason, "not_planned") def testEditWithStateReasonReopened(self): self.issue.edit(state="open", state_reason="reopened") self.assertEqual(self.issue.state, "open") self.assertEqual(self.issue.state_reason, "reopened") def testLock(self): self.issue.lock("resolved") def testUnlock(self): self.issue.unlock() def testCreateComment(self): comment = self.issue.create_comment("Comment created by PyGithub") self.assertEqual(comment.id, 5808311) def testGetComments(self): self.assertListKeyEqual(self.issue.get_comments(), lambda c: c.user.login, ["jacquev6", "roskakori"]) def testGetCommentsSince(self): self.assertListKeyEqual( self.issue.get_comments(datetime(2012, 5, 26, 13, 59, 33, tzinfo=timezone.utc)), lambda c: c.user.login, ["jacquev6", "roskakori"], ) def testGetEvents(self): self.assertListKeyEqual(self.issue.get_events(), lambda e: e.id, [15819975, 15820048]) def testGetLabels(self): self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) def testAddAndRemoveAssignees(self): user1 = "jayfk" user2 = self.g.get_user("jzelinskie") self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) self.issue.add_to_assignees(user1, user2) self.assertListKeyEqual( self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser", "jayfk", "jzelinskie"], ) self.issue.remove_from_assignees(user1, user2) self.assertListKeyEqual(self.issue.assignees, lambda a: a.login, ["jacquev6", "stuglaser"]) def testAddAndRemoveLabels(self): bug = self.repo.get_label("Bug") question = self.repo.get_label("Question") self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) self.issue.remove_from_labels(bug) self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Project management", "Question"], ) self.issue.remove_from_labels(question) self.assertListKeyEqual(self.issue.get_labels(), lambda lb: lb.name, ["Project management"]) self.issue.add_to_labels(bug, question) self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) def testAddAndRemoveLabelsWithStringArguments(self): bug = "Bug" question = "Question" self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) self.issue.remove_from_labels(bug) self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Project management", "Question"], ) self.issue.remove_from_labels(question) self.assertListKeyEqual(self.issue.get_labels(), lambda lb: lb.name, ["Project management"]) self.issue.add_to_labels(bug, question) self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) def testDeleteAndSetLabels(self): bug = self.repo.get_label("Bug") question = self.repo.get_label("Question") self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) self.issue.delete_labels() self.assertListKeyEqual(self.issue.get_labels(), None, []) self.issue.set_labels(bug, question) self.assertListKeyEqual(self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Question"]) def testDeleteAndSetLabelsWithStringArguments(self): bug = "Bug" question = "Question" self.assertListKeyEqual( self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Project management", "Question"], ) self.issue.delete_labels() self.assertListKeyEqual(self.issue.get_labels(), None, []) self.issue.set_labels(bug, question) self.assertListKeyEqual(self.issue.get_labels(), lambda lb: lb.name, ["Bug", "Question"]) def testGetReactions(self): reactions = self.issue.get_reactions() self.assertEqual(reactions[0].content, "+1") def testCreateReaction(self): reaction = self.issue.create_reaction("hooray") self.assertEqual(reaction.id, 16917472) self.assertEqual(reaction.content, "hooray") def testDeleteReaction(self): self.assertTrue(self.issue.delete_reaction(85740167)) def testGetTimeline(self): expected_events = { "referenced", "cross-referenced", "locked", "unlocked", "closed", "assigned", "commented", "subscribed", "labeled", } events = self.issue.get_timeline() first = events[0] self.assertEqual(15819975, first.id) self.assertEqual("MDE1OlN1YnNjcmliZWRFdmVudDE1ODE5OTc1", first.node_id) self.assertEqual( "https://api.github.com/repos/PyGithub/PyGithub/issues/events/15819975", first.url, ) self.assertEqual("jacquev6", first.actor.login) self.assertEqual(327146, first.actor.id) self.assertEqual("subscribed", first.event) self.assertIsNone(first.commit_id) self.assertIsNone(first.commit_url) self.assertEqual(repr(first), "TimelineEvent(id=15819975)") for event in events: self.assertIn(event.event, expected_events) self.assertIsNotNone(event.created_at) self.assertIsNotNone(event.actor) if event.event == "cross-referenced": # cross-referenced events don't include an event id or node_id self.assertIsNotNone(event.source) self.assertEqual(event.source.type, "issue") self.assertEqual(event.source.issue.number, 857) self.assertEqual(repr(event.source), 'TimelineEventSource(type="issue")') else: self.assertIsNotNone(event.id) self.assertIsNotNone(event.node_id) if event.event == "commented": self.assertIsNotNone(event.body) else: self.assertIsNone(event.source) self.assertIsNotNone(event.actor)
15,001
Python
.py
308
39.529221
109
0.582782
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)
12,599
Project.py
PyGithub_PyGithub/tests/Project.py
############################ Copyrights and license ############################ # # # Copyright 2018 Benoit Latinier <benoit@latinier.fr> # # Copyright 2018 Yossarian King <yggy@blackbirdinteractive.com> # # Copyright 2019 Benoit Latinier <benoit@latinier.fr> # # Copyright 2019 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2019 TechnicalPirate <35609336+TechnicalPirate@users.noreply.github.com># # Copyright 2019 Wan Liuyang <tsfdye@gmail.com> # # Copyright 2020 Jody McIntyre <scjody@modernduck.com> # # Copyright 2020 Steve Kowalik <steven@wedontsleep.org> # # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # # Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # # # # PyGithub is free software: you can redistribute it and/or modify it under # # the terms of the GNU Lesser General Public License as published by the Free # # Software Foundation, either version 3 of the License, or (at your option) # # any later version. # # # # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # # details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # # # ################################################################################ import github from . import Framework class Project(Framework.TestCase): def setUp(self): super().setUp() self.repo = self.g.get_user().get_repo("PyGithub") def testGetProject(self): pid = 1682941 proj = self.g.get_project(pid) self.assertEqual(proj.id, pid) self.assertEqual(proj.name, "TestProject") self.assertEqual(repr(proj), 'Project(name="TestProject")') def testGetOrganizationProjects(self): expectedProjects = ["Project1", "Project2", "Project3"] org = self.g.get_organization("PyGithubTestOrg") projects = [] for proj in org.get_projects("open"): projects.append(proj.name) self.assertEqual(projects, expectedProjects) def testGetRepositoryProjects(self): expectedProjects = ["TestProject", "TestProjectClosed"] projects = [] for proj in self.repo.get_projects("all"): projects.append(proj.name) self.assertEqual(projects, expectedProjects) # See https://developer.github.com/v3/projects/#get-a-project def testProjectAttributes(self): pid = 1682941 proj = self.g.get_project(pid) self.assertEqual(proj.owner_url, "https://api.github.com/repos/bbi-yggy/PyGithub") self.assertEqual(proj.url, "https://api.github.com/projects/1682941") self.assertEqual(proj.html_url, "https://github.com/bbi-yggy/PyGithub/projects/1") self.assertEqual(proj.columns_url, "https://api.github.com/projects/1682941/columns") self.assertEqual(proj.id, pid) self.assertEqual(proj.node_id, "MDc6UHJvamVjdDE2ODI5NDE=") self.assertEqual(proj.name, "TestProject") self.assertEqual(proj.body, "To be used for testing project access API for PyGithub.") self.assertEqual(proj.number, 1) self.assertEqual(proj.state, "open") self.assertEqual(proj.creator, self.repo.owner) self.assertEqual(proj.created_at.year, 2018) self.assertTrue(proj.updated_at > proj.created_at) # See https://developer.github.com/v3/projects/columns/#get-a-project-column def testProjectColumnAttributes(self): proj = self.g.get_project(1682941) col = proj.get_columns()[0] self.assertEqual(col.id, 3138830) self.assertEqual(col.node_id, "MDEzOlByb2plY3RDb2x1bW4zMTM4ODMw") self.assertEqual(col.name, "To Do") self.assertEqual(col.url, "https://api.github.com/projects/columns/3138830") self.assertEqual(col.project_url, "https://api.github.com/projects/1682941") self.assertEqual(col.cards_url, "https://api.github.com/projects/columns/3138830/cards") self.assertEqual(col.created_at.year, 2018) self.assertTrue(col.updated_at >= col.created_at) self.assertEqual(repr(col), 'ProjectColumn(name="To Do")') # See https://developer.github.com/v3/projects/cards/#get-a-project-card def testProjectCardAttributes(self): proj = self.g.get_project(1682941) col = proj.get_columns()[1] card = col.get_cards()[0] self.assertEqual(card.url, "https://api.github.com/projects/columns/cards/11780055") self.assertEqual(card.column_url, "https://api.github.com/projects/columns/3138831") self.assertEqual(card.content_url, "https://api.github.com/repos/bbi-yggy/PyGithub/issues/1") self.assertEqual(card.id, 11780055) self.assertEqual(card.node_id, "MDExOlByb2plY3RDYXJkMTE3ODAwNTU=") self.assertEqual(card.note, None) # No notes for cards with content. self.assertEqual(card.creator, self.repo.owner) self.assertEqual(card.created_at.year, 2018) self.assertTrue(card.updated_at >= card.created_at) self.assertFalse(card.archived) self.assertEqual(repr(card), "ProjectCard(id=11780055)") def testGetProjectCardContent(self): proj = self.g.get_project(1682941) col = proj.get_columns()[1] cards = col.get_cards() pull_card = cards[0] pull = pull_card.get_content("PullRequest") self.assertIsInstance(pull, github.PullRequest.PullRequest) self.assertEqual(pull.title, "Work in progress on support for GitHub projects API.") self.assertRaises(ValueError, pull_card.get_content, "foo") issue_card = cards[1] issue = issue_card.get_content() self.assertIsInstance(issue, github.Issue.Issue) self.assertEqual(issue.title, "Test issue") note_card = cards[2] note_content = note_card.get_content() self.assertEqual(note_content, None) def testProjectCardMove(self): proj = self.g.get_project(1682941) cols = proj.get_columns() card = cols[1].get_cards()[0] self.assertTrue(card.move("top", cols[2].id)) self.assertTrue(card.move("bottom", cols[1])) def testProjectCardDelete(self): proj = self.g.get_project(1682941) cols = proj.get_columns() card = cols[1].get_cards()[0] self.assertTrue(card.delete()) def testGetAllProjectCards(self): expectedProjects = ["TestProject"] expectedCards = 5 projects = [] cards = 0 for proj in self.repo.get_projects(): projects.append(proj.name) for col in proj.get_columns(): for card in col.get_cards("all"): cards += 1 self.assertEqual(projects, expectedProjects) self.assertEqual(cards, expectedCards) def testCreateColumn(self): project = self.repo.create_project("Project created by PyGithub", "Project Body") column = project.create_column( "Project Column created by PyGithub", ) self.assertEqual(column.id, 3999333) def testCreateCardWithNote(self): project = self.repo.create_project("Project created by PyGithub", "Project Body") column = project.create_column( "Project Column created by PyGithub", ) card1 = column.create_card(note="Project Card") self.assertEqual(card1.id, 16039019) def testCreateCardFromIssue(self): project = self.repo.create_project("Project created by PyGithub", "Project Body") column = project.create_column( "Project Column created by PyGithub", ) issue = self.repo.create_issue(title="Issue created by PyGithub") card2 = column.create_card(content_id=issue.id, content_type="Issue") self.assertEqual(card2.id, 16039106) def testEditCardWithoutParameters(self): proj = self.g.get_project(4015343) col = proj.get_columns()[0] card = col.create_card(note="Project Card") card.edit() def testEditCardNote(self): proj = self.g.get_project(4015343) col = proj.get_columns()[0] card = col.create_card(note="Project Card") card.edit(note="Edited Card") self.assertEqual(card.note, "Edited Card") def testEditCardArchived(self): proj = self.g.get_project(4015343) col = proj.get_columns()[0] card = col.create_card(note="Project Card") card.edit(archived=True) self.assertEqual(card.archived, True)
9,683
Python
.py
178
46.932584
101
0.606307
PyGithub/PyGithub
6,892
1,756
334
LGPL-3.0
9/5/2024, 5:11:50 PM (Europe/Amsterdam)