def test_raises(self, request): request.return_value = MockResponse(404, '{}') ucare = UploadCare('pub', 'secret') with self.assertRaises(UploadCareException): ucare.make_request('GET', '/files/') request.return_value = MockResponse(200, 'meh') with self.assertRaises(ValueError) as cm: ucare.make_request('GET', '/files/') self.assertEqual('no json in response', cm.exception.message)
def test_request_headers(self, request): request.return_value = MockResponse(200, '[]') ucare = UploadCare('pub', 'secret') ucare.make_request('GET', '/files/') headers = request.call_args[1]['headers'] self.assertIn('Accept', headers) self.assertIn('User-Agent', headers) self.assertEqual(headers['Accept'], 'application/vnd.uploadcare-v0.2+json') self.assertEqual(headers['User-Agent'], 'pyuploadcare/0.12') ucare = UploadCare('pub', 'secret', api_version='0.1') ucare.make_request('GET', '/files/') headers = request.call_args[1]['headers'] self.assertIn('Accept', headers) self.assertIn('User-Agent', headers) self.assertEqual(headers['Accept'], 'application/json') self.assertEqual(headers['User-Agent'], 'pyuploadcare/0.12')