FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update test_user_secrets to expect a POST request instead of GET. · HpcDataLab/docker-python@ede9d48 · GitHub

Repository navigation

Commit ede9d48

Browse files
committed
Update test_user_secrets to expect a POST request instead of GET.
1 parent 570cbd1 commit ede9d48

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎tests/test_user_secrets.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_response(self):
2626
def do_HEAD(s):
2727
s.send_response(200)
2828

29-
def do_GET(s):
29+
def do_POST(s):
3030
s.set_request()
3131
s.send_response(200)
3232
s.send_header("Content-type", "application/json")
@@ -37,13 +37,15 @@ def do_GET(s):
3737
class TestUserSecrets(unittest.TestCase):
3838
SERVER_ADDRESS = urlparse(os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME))
3939

40-
def _test_client(self, client_func, expected_path, secret):
40+
def _test_client(self, client_func, expected_path, expected_body, secret):
4141
_request = {}
4242

4343
class AccessTokenHandler(UserSecretsHTTPHandler):
4444

4545
def set_request(self):
4646
_request['path'] = self.path
47+
content_len = int(self.headers.get('Content-Length'))
48+
_request['body'] = json.loads(self.rfile.read(content_len))
4749
_request['headers'] = self.headers
4850

4951
def get_response(self):
@@ -60,11 +62,15 @@ def get_response(self):
6062
finally:
6163
httpd.shutdown()
6264

63-
path, headers = _request['path'], _request['headers']
65+
path, headers, body = _request['path'], _request['headers'], _request['body']
6466
self.assertEqual(
6567
path,
6668
expected_path,
6769
msg="Fake server did not receive the right request from the UserSecrets client.")
70+
self.assertEqual(
71+
body,
72+
expected_body,
73+
msg="Fake server did not receive the right body from the UserSecrets client.")
6874
self.assertTrue(
6975
any(
7076
k for k in headers
@@ -86,4 +92,4 @@ def call_get_access_token():
8692
secret_response = client.get_bigquery_access_token()
8793
self.assertEqual(secret_response, secret)
8894
self._test_client(call_get_access_token,
89-
'/requests/GetUserSecretRequest?Target=1', secret)
95+
'/requests/GetUserSecretRequest', {'Target': 1}, secret)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL