|
12 | 12 | CRUD functions. These tests always use a mock http connection so not not
|
13 | 13 | need a live server to run against."""
|
14 | 14 |
|
15 |
| -import base64 |
16 | 15 | import datetime
|
17 |
| -from shotgun_api3.lib.six.moves import urllib |
18 | 16 | import os
|
19 | 17 | import re
|
| 18 | + |
| 19 | +from shotgun_api3.lib.six.moves import urllib |
20 | 20 | from shotgun_api3.lib import six
|
21 | 21 | try:
|
22 | 22 | import simplejson as json
|
|
38 | 38 | from . import base
|
39 | 39 |
|
40 | 40 |
|
| 41 | +if six.PY3: |
| 42 | + from base64 import encodebytes as base64encode |
| 43 | +else: |
| 44 | + from base64 import encodestring as base64encode |
| 45 | + |
| 46 | + |
41 | 47 | def b64encode(val):
|
42 |
| - return base64.encodestring(six.ensure_binary(val)).decode("utf-8") |
| 48 | + return base64encode(six.ensure_binary(val)).decode("utf-8") |
43 | 49 |
|
44 | 50 |
|
45 | 51 | class TestShotgunClient(base.MockTestBase):
|
@@ -164,6 +170,61 @@ def test_url(self):
|
164 | 170 | expected = "Basic " + b64encode(urllib.parse.unquote(login_password)).strip()
|
165 | 171 | self.assertEqual(expected, sg.config.authorization)
|
166 | 172 |
|
| 173 | + def test_b64encode(self): |
| 174 | + """Parse value using the proper encoder.""" |
| 175 | + login = "thelogin" |
| 176 | + password = "%thepassw0r#$" |
| 177 | + login_password = "%s:%s" % (login, password) |
| 178 | + expected = 'dGhlbG9naW46JXRoZXBhc3N3MHIjJA==' |
| 179 | + result = b64encode(urllib.parse.unquote(login_password)).strip() |
| 180 | + self.assertEqual(expected, result) |
| 181 | + |
| 182 | + def test_read_config(self): |
| 183 | + """Validate that config values are properly coerced.""" |
| 184 | + this_dir = os.path.dirname(os.path.realpath(__file__)) |
| 185 | + config_path = os.path.join(this_dir, "test_config_file") |
| 186 | + config = base.ConfigParser() |
| 187 | + config.read(config_path) |
| 188 | + result = config.get("SERVER_INFO", "api_key") |
| 189 | + expected = "%abce" |
| 190 | + |
| 191 | + self.assertEqual(expected, result) |
| 192 | + |
| 193 | + def test_split_url(self): |
| 194 | + """Validate that url parts are properly extracted.""" |
| 195 | + |
| 196 | + sg = api.Shotgun("https://ci.shotgunstudio.com", |
| 197 | + "foo", "bar", connect=False) |
| 198 | + |
| 199 | + |
| 200 | + base_url = "https://ci.shotgunstudio.com" |
| 201 | + expected_server = "ci.shotgunstudio.com" |
| 202 | + expected_auth = None |
| 203 | + auth, server = sg._split_url(base_url) |
| 204 | + self.assertEqual(auth, expected_auth) |
| 205 | + self.assertEqual(server, expected_server) |
| 206 | + |
| 207 | + base_url = "https://ci.shotgunstudio.com:9500" |
| 208 | + expected_server = "ci.shotgunstudio.com:9500" |
| 209 | + expected_auth = None |
| 210 | + auth, server = sg._split_url(base_url) |
| 211 | + self.assertEqual(auth, expected_auth) |
| 212 | + self.assertEqual(server, expected_server) |
| 213 | + |
| 214 | + base_url = "https://x:[email protected]:9500" |
| 215 | + expected_server = "ci.shotgunstudio.com:9500" |
| 216 | + expected_auth = "x:y" |
| 217 | + auth, server = sg._split_url(base_url) |
| 218 | + self.assertEqual(auth, expected_auth) |
| 219 | + self.assertEqual(server, expected_server) |
| 220 | + |
| 221 | + base_url = "https://[email protected]:9500" |
| 222 | + expected_server = "ci.shotgunstudio.com:9500" |
| 223 | + expected_auth = "12345XYZ" |
| 224 | + auth, server = sg._split_url(base_url) |
| 225 | + self.assertEqual(auth, expected_auth) |
| 226 | + self.assertEqual(server, expected_server) |
| 227 | + |
167 | 228 | def test_authorization(self):
|
168 | 229 | """Authorization passed to server"""
|
169 | 230 | login = self.human_user['login']
|
|
0 commit comments