-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_rest.py
More file actions
58 lines (41 loc) · 2.04 KB
/
Copy pathtest_rest.py
File metadata and controls
58 lines (41 loc) · 2.04 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
from __future__ import absolute_import
from patch_api.configuration import Configuration
from patch_api import rest
import unittest
import os
from patch_api.api_client import ApiClient
class TestRESTClientObject(unittest.TestCase):
def test_recursive_urlencode(self):
"""Test that the correct query params get encoded"""
api_key = os.environ.get("SANDBOX_API_KEY")
configuration = Configuration()
client = rest.RESTClientObject(api_key, configuration)
encoded_params = client.recursive_urlencode({})
self.assertEqual(encoded_params, "")
encoded_params = client.recursive_urlencode({"page": 1})
self.assertEqual(encoded_params, "page=1")
encoded_params = client.recursive_urlencode({"string": "value"})
self.assertEqual(encoded_params, "string=value")
encoded_params = client.recursive_urlencode(
{"multiple": "values", "top": "level"}
)
self.assertEqual(encoded_params, "multiple=values&top=level")
encoded_params = client.recursive_urlencode({"metadata": {"some": "arg"}})
self.assertEqual(encoded_params, "metadata[some]=arg")
encoded_params = client.recursive_urlencode(
{"deeply": {"nested": {"hash": {"of": "args"}}}}
)
self.assertEqual(encoded_params, "deeply[nested][hash][of]=args")
def test_encoded_query_params(self):
"""Test that the correct query params get encoded"""
api_key = os.environ.get("SANDBOX_API_KEY")
configuration = Configuration()
client = rest.RESTClientObject(api_key, configuration)
encoded_params = client.encoded_query_params([])
self.assertEqual(encoded_params, "")
encoded_params = client.encoded_query_params([("mass_g", 100)])
self.assertEqual(encoded_params, "?mass_g=100")
encoded_params = client.encoded_query_params(
[("mass_g", 100), ("metadata", {"external_id": "abc-123"})]
)
self.assertEqual(encoded_params, "?metadata[external_id]=abc-123&mass_g=100")