def test_run_no_auth(self): wayscript = WayScript() with patch('requests.post') as post_request: wayscript.run(self.PROGRAM_ID) headers = {'X-WayScript-Api': 'python'} post_request.assert_called_once_with(self.API_URL, data=None, headers=headers, params=None)
def test_run_custom_endpoint_no_auth(self): wayscript = WayScript() with patch('requests.post') as post_request: wayscript.run(self.PROGRAM_ID, endpoint=self.ENDPOINT) headers = {'X-WayScript-Api': 'python'} post_request.assert_called_once_with(self.API_URL + self.ENDPOINT, data=None, headers=headers, params=None)
def test_run_with_api_key(self): wayscript = WayScript(**{'api_key': self.DUMMY_API_KEY}) with patch('requests.post') as post_request: wayscript.run(self.PROGRAM_ID) headers = { 'X-WayScript-Api': 'python', 'Authorization': f'Bearer { self.DUMMY_API_KEY }' } post_request.assert_called_once_with(self.API_URL, data=None, headers=headers, params=None)
def test_run_custom_endpoint_authenticated_with_body_params(self): wayscript = WayScript(**{'api_key': self.DUMMY_API_KEY}) with patch('requests.post') as post_request: wayscript.run(self.PROGRAM_ID, data=self.QUERY_PARAMS, endpoint=self.ENDPOINT) headers = { 'X-WayScript-Api': 'python', 'Authorization': f'Bearer { self.DUMMY_API_KEY }' } post_request.assert_called_once_with(self.API_URL + self.ENDPOINT, data=self.QUERY_PARAMS, headers=headers, params=None)
def test_empty_params(self): wayscript = WayScript(**{'api_key': self.DUMMY_API_KEY}) with patch('requests.post') as post_request: wayscript.run(self.PROGRAM_ID, params={}, data={}, endpoint=self.ENDPOINT) headers = { 'X-WayScript-Api': 'python', 'Authorization': f'Bearer {self.DUMMY_API_KEY}' } post_request.assert_called_once_with(self.API_URL + self.ENDPOINT, data={}, headers=headers, params={})
def test_run_with_username_and_password(self): wayscript = WayScript(**{ 'username': self.USERNAME, 'password': self.PASSWORD }) with patch('requests.post') as post_request: wayscript.run(self.PROGRAM_ID) headers = { 'X-WayScript-Api': 'python', 'Authorization': 'Basic Y2FwdGFpbkB3YXlzY3JpcHQuY29tOmxldG1laW4=' } post_request.assert_called_once_with(self.API_URL, data=None, headers=headers, params=None)
def test_returns_response(self): wayscript = WayScript() with patch('requests.post', return_value='ok') as post_request: response = wayscript.run(self.PROGRAM_ID, params=self.QUERY_PARAMS) headers = {'X-WayScript-Api': 'python'} post_request.assert_called_once_with(self.API_URL, data=None, headers=headers, params=self.QUERY_PARAMS) self.assertEqual(response, 'ok')