Skip to content

Commit 9f2061a

Browse files
committed
Add test to check proxy env vars still works
1 parent 92e664b commit 9f2061a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/test_interests.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,74 @@ def test_publish_to_interests_should_make_correct_http_request(self):
8383
},
8484
)
8585

86+
def test_enabling_proxies_should_not_fail(self):
87+
pn_client = PushNotifications(
88+
'INSTANCE_ID',
89+
'SECRET_KEY',
90+
use_proxy_env_vars=True,
91+
)
92+
with requests_mock.Mocker() as http_mock:
93+
http_mock.register_uri(
94+
requests_mock.ANY,
95+
requests_mock.ANY,
96+
status_code=200,
97+
json={
98+
'publishId': '1234',
99+
},
100+
)
101+
response = pn_client.publish_to_interests(
102+
interests=['donuts'],
103+
publish_body={
104+
'apns': {
105+
'aps': {
106+
'alert': 'Hello World!',
107+
},
108+
},
109+
},
110+
)
111+
req = http_mock.request_history[0]
112+
113+
method = req.method
114+
path = req.path
115+
headers = dict(req._request.headers.lower_items())
116+
body = req.json()
117+
118+
self.assertEqual(
119+
method,
120+
'POST',
121+
)
122+
self.assertEqual(
123+
path,
124+
'/publish_api/v1/instances/instance_id/publishes/interests',
125+
)
126+
self.assertDictEqual(
127+
headers,
128+
{
129+
'content-type': 'application/json',
130+
'content-length': '69',
131+
'authorization': 'Bearer SECRET_KEY',
132+
'x-pusher-library': 'pusher-push-notifications-python 1.1.0',
133+
'host': 'instance_id.pushnotifications.pusher.com',
134+
},
135+
)
136+
self.assertDictEqual(
137+
body,
138+
{
139+
'interests': ['donuts'],
140+
'apns': {
141+
'aps': {
142+
'alert': 'Hello World!',
143+
},
144+
},
145+
},
146+
)
147+
self.assertDictEqual(
148+
response,
149+
{
150+
'publishId': '1234',
151+
},
152+
)
153+
86154
def test_deprecated_alias_still_works(self):
87155
pn_client = PushNotifications(
88156
'INSTANCE_ID',

0 commit comments

Comments
 (0)