def test_make_request(self, *args, **kvargs): headers = {'content-type': 'application/json'} params = { 'method': 'GET', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': 'ABC', 'private_key': 'Mzjg58S93/qdg0HuVP6PsLSRDTe+fQZ5++v/mkUUx4k=', 'data_binary': False } make_request(**params) expected = { 'content-type': 'application/json', 'x-altus-date': 'Thu, 01 Jan 1970 00:00:00 GMT', 'x-altus-auth': 'eyJhY2Nlc3Nfa2V5X2lkIjogIkFCQyIsICJhdXRoX21ldGhvZCI6ICJlZDI1NTE5djEifQ==.bej2viXTt1s2fhCwl65y10TiOdduxAyCRm1APvVj1qhTYzaTn3L-4xnlCj_UeTt_nFFUHa0rj03RPdzwBjvQCQ==' } self.assertEqual(expected, headers) pass
def test_make_request(self, mocked_resp): resp = Response() resp.status_code = 200 resp._content = b'{"file_name": "test.yml", "env": "staging", "hash": "\xe5\xad\x97"}' resp.encoding = 'UTF-8' mocked_resp.return_value = resp headers = {} params = { 'method': 'GET', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': b'C\xcfI\x91\xc1\xd0\tw<\xa8\x13\x06{=\x9b\xb3\x1c\xfcl\xfe\xb9\xb18zS\xf4%i*Q\xc9v', 'access_key': '', 'private_key': 'Mzjg58S93/qdg0HuVP6PsLSRDTe+fQZ5++v/mkUUx4k=', 'data_binary': True } r = make_request(**params) expected = u'хнЧ' ### assert that the unicode character is in the response.text output self.assertTrue(expected in r.text) ### assert that the unicode character is _not_ in the response.text which has been converted to bytes self.assertFalse(expected in str(r.text.encode('utf-8'))) pass
def test_make_request(self, *args, **kvargs): headers = {'content-type': 'application/json'} params = { 'method': 'GET', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': 'ABC', 'private_key': 'NOPE', 'data_binary': False, 'verify': False } with pytest.raises(Exception): make_request(**params) pass