Authenticate via headers

Closes bennylope/pydiscourse#27
This commit is contained in:
Alex Kerney
2019-12-04 16:16:57 -05:00
committed by Ben Lopatin
parent 69867b3c10
commit aeb763c42c
3 changed files with 10 additions and 9 deletions
+1 -1
View File
@@ -9,4 +9,4 @@ Scott Nixon
Jason Dorweiler
Pierre-Alain Dupont
Karl Goetz
Alex Kerney
+5 -4
View File
@@ -1350,12 +1350,13 @@ class DiscourseClient(object):
dictionary of response body data or None
"""
params["api_key"] = self.api_key
if "api_username" not in params:
params["api_username"] = self.api_username
url = self.host + path
headers = {"Accept": "application/json; charset=utf-8"}
headers = {
"Accept": "application/json; charset=utf-8",
"Api-Key": self.api_key,
"Api-Username": self.api_username,
}
# How many times should we retry if rate limited
retry_count = 4
+4 -4
View File
@@ -49,12 +49,12 @@ class ClientBaseTestCase(unittest.TestCase):
self.assertEqual(args[0], verb)
self.assertEqual(args[1], self.host + url)
kwargs = kwargs["params"]
self.assertEqual(kwargs.pop("api_username"), self.api_username)
self.assertEqual(kwargs.pop("api_key"), self.api_key)
headers = kwargs["headers"]
self.assertEqual(headers.pop("Api-Username"), self.api_username)
self.assertEqual(headers.pop("Api-Key"), self.api_key)
if verb == "GET":
self.assertEqual(kwargs, params)
self.assertEqual(kwargs["params"], params)
class TestClientRequests(ClientBaseTestCase):