def testGetSubscriptions(self):
self.assertListKeyEqual(self.user.get_subscriptions(), lambda r: r.name, ["ViDE", "Boost.HierarchicalEnum", "QuadProgMm", "DrawSyntax", "DrawTurksHead", "PrivateStuff", "vincent-jacques.net", "Hacking", "C4Planner", "developer.github.com", "PyGithub", "PyGithub", "django", "CinePlanning", "PyGithub", "PyGithub", "PyGithub", "IpMap", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub", "PyGithub"])
python类com()的实例源码
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"
def testIgnoreHttpsFromGithubEnterprise(self):
g = github.Github(self.login, self.password, 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(self.login, self.password, 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
def testRaiseErrorWithOutBranch(self):
raised = False
try:
self.repo.protect_branch("", True, "everyone", ["test"])
except github.GithubException as exception:
raised = True
self.assertEqual(exception.status, 404)
self.assertEqual(
exception.data, {
'documentation_url': 'https://developer.github.com/v3/repos/#get-branch',
'message': 'Branch not found'
}
)
self.assertTrue(raised)
def testCreateLabel(self):
label = self.repo.create_label("Label with silly name % * + created by PyGithub", "00ff00")
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 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)