forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_tests.py
More file actions
85 lines (67 loc) · 2.52 KB
/
auth_tests.py
File metadata and controls
85 lines (67 loc) · 2.52 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
"""
SoftLayer.tests.auth_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
from SoftLayer import auth
from SoftLayer import testing
from SoftLayer import transports
class TestAuthenticationBase(testing.TestCase):
def test_get_request(self):
auth_base = auth.AuthenticationBase()
self.assertEqual(auth_base.get_request({}), {})
self.assertEqual(auth_base.get_headers(), {})
class TestBasicAuthentication(testing.TestCase):
def set_up(self):
self.auth = auth.BasicAuthentication('USERNAME', 'APIKEY')
def test_attribs(self):
self.assertEqual(self.auth.username, 'USERNAME')
self.assertEqual(self.auth.api_key, 'APIKEY')
def test_get_request(self):
req = transports.Request()
authed_req = self.auth.get_request(req)
self.assertEqual(authed_req.headers, {
'authenticate': {
'username': 'USERNAME',
'apiKey': 'APIKEY',
}
})
def test_repr(self):
s = repr(self.auth)
self.assertIn('BasicAuthentication', s)
self.assertIn('USERNAME', s)
class TestTokenAuthentication(testing.TestCase):
def set_up(self):
self.auth = auth.TokenAuthentication(12345, 'TOKEN')
def test_attribs(self):
self.assertEqual(self.auth.user_id, 12345)
self.assertEqual(self.auth.auth_token, 'TOKEN')
def test_get_request(self):
req = transports.Request()
authed_req = self.auth.get_request(req)
self.assertEqual(authed_req.headers, {
'authenticate': {
'complexType': 'PortalLoginToken',
'userId': 12345,
'authToken': 'TOKEN',
}
})
def test_repr(self):
s = repr(self.auth)
self.assertIn('TokenAuthentication', s)
self.assertIn('12345', s)
class TestBasicHTTPAuthentication(testing.TestCase):
def set_up(self):
self.auth = auth.BasicHTTPAuthentication('USERNAME', 'APIKEY')
def test_attribs(self):
self.assertEqual(self.auth.username, 'USERNAME')
self.assertEqual(self.auth.api_key, 'APIKEY')
def test_get_request(self):
req = transports.Request()
authed_req = self.auth.get_request(req)
self.assertEqual(authed_req.transport_user, 'USERNAME')
self.assertEqual(authed_req.transport_password, 'APIKEY')
def test_repr(self):
s = repr(self.auth)
self.assertIn('BasicHTTPAuthentication', s)
self.assertIn('USERNAME', s)