-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy patharestclient_test.py
More file actions
executable file
·104 lines (80 loc) · 2.83 KB
/
arestclient_test.py
File metadata and controls
executable file
·104 lines (80 loc) · 2.83 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# Copyright 2012-2016 Jonathan Paugh and contributors
# See COPYING for license details
from arestclient.GitHub import GitHub
from arestclient.base import IncompleteRequest
import unittest
class Client(object):
http_methods = ('demo', 'test')
def __init__(self, username=None, password=None, token=None,
connection_properties=None):
pass
def setConnectionProperties(self, props):
pass
def demo(self, *args, **params):
return self.methodCalled('demo', *args, **params)
def test(self, *args, **params):
return self.methodCalled('test', *args, **params)
def methodCalled(self, methodName, *args, **params):
return {
'methodName': methodName,
'args': args,
'params': params
}
class TestGitHubObjectCreation(unittest.TestCase):
def test_user_pw(self):
gh = GitHub('korfuri', '1234')
self.assertTrue(gh is not None)
gh = GitHub(username='korfuri', password='1234')
self.assertTrue(gh is not None)
def test_token(self):
gh = GitHub(username='korfuri', token='deadbeef')
self.assertTrue(gh is not None)
gh = GitHub(token='deadbeef')
self.assertTrue(gh is not None)
def test_token_password(self):
with self.assertRaises(TypeError):
GitHub(username='korfuri', password='1234', token='deadbeef')
class TestIncompleteRequest(unittest.TestCase):
def newIncompleteRequest(self):
return IncompleteRequest(Client())
def test_pathByGetAttr(self):
rb = self.newIncompleteRequest()
rb.hug.an.octocat
self.assertEqual(rb.url, "/hug/an/octocat")
def test_callMethodDemo(self):
rb = self.newIncompleteRequest()
self.assertEqual(
rb.path.demo(),
{
"methodName": "demo",
"args": (),
"params": {"url": "/path"}
}
)
def test_pathByGetItem(self):
rb = self.newIncompleteRequest()
rb["hug"][1]["octocat"]
self.assertEqual(rb.url, "/hug/1/octocat")
def test_callMethodTest(self):
rb = self.newIncompleteRequest()
self.assertEqual(
rb.path.demo(),
{
"methodName": "demo",
"args": (),
"params": {"url": "/path"}
}
)
def test_github():
g = GitHub()
status, data = g.users.octocat.get()
assert data.get('name') == 'The Octocat'
assert status == 200
# Workaround to https://github.com/mozilla/agithub/issues/67
response_headers = dict([(x.lower(), y) for x, y in g.getheaders()])
assert (
response_headers.get('Content-Type'.lower()) ==
'application/json; charset=utf-8')
if __name__ == '__main__':
unittest.main()