-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathagithub_test.py
More file actions
executable file
·77 lines (61 loc) · 2.29 KB
/
agithub_test.py
File metadata and controls
executable file
·77 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import agithub
import mock
import mock.http.client
import unittest
class TestGithubObjectCreation(unittest.TestCase):
def test_user_pw(self):
gh = agithub.Github('korfuri', '1234')
self.assertTrue(gh is not None)
gh = agithub.Github(username='korfuri', password='1234')
self.assertTrue(gh is not None)
def test_token(self):
gh = agithub.Github(username='korfuri', token='deadbeef')
self.assertTrue(gh is not None)
gh = agithub.Github(token='deadbeef')
self.assertTrue(gh is not None)
def test_token_password(self):
with self.assertRaises(TypeError):
gh = agithub.Github(
username='korfuri', password='1234', token='deadbeef')
class TestRequestBuilder(unittest.TestCase):
def newRequestBuilder(self):
return agithub.RequestBuilder(mock.Client())
def test_pathByGetAttr(self):
rb = self.newRequestBuilder()
rb.hug.an.octocat
self.assertEqual(rb.url, "/hug/an/octocat")
def test_callMethodDemo(self):
rb = self.newRequestBuilder()
self.assertEqual(rb.path.demo(),
{ "methodName" : "demo"
, "args" : ()
, "params" : { "url" : "/path" }
})
def test_pathByGetItem(self):
rb = self.newRequestBuilder()
rb["hug"][1]["octocat"]
self.assertEqual(rb.url, "/hug/1/octocat")
def test_callMethodDemo(self):
rb = self.newRequestBuilder()
self.assertEqual(rb.path.demo(),
{ "methodName" : "demo"
, "args" : ()
, "params" : { "url" : "/path" }
})
def test_callMethodTest(self):
rb = self.newRequestBuilder()
self.assertEqual(rb.path.test(),
{ "methodName" : "test"
, "args" : ()
, "params" : { "url" : "/path" }
})
class TestClient(unittest.TestCase):
def newClient(self, *args, **params):
return agithub.Client(*args, httpClient = mock.http.client, **params)
def test_anonymousClient(self):
client = self.newClient()
def test_passwordClient(self):
client = self.newClient(username="user", password="freepass")
if __name__ == '__main__':
unittest.main()