def test_request_no_auth(self): def stubbed_request(method, url, data, auth): self.assertEqual(auth, None) return FakeResponse(json.dumps({'data': {}})) self.monkey_patch(requests, 'request', stubbed_request) client = DiamondashApiClient() client.request('put', 'foo', {}),
def test_request(self): self.vumi_helper.patch_settings( DIAMONDASH_API_USERNAME='******', DIAMONDASH_API_PASSWORD='******') resp = FakeResponse(json.dumps({ 'success': True, 'data': {'spam': 'ham'} })) def stubbed_request(method, url, data, auth): self.assertEqual(method, 'put') self.assertEqual(url, 'http://diamondash.moc/api/foo') self.assertEqual(data, json.dumps({'bar': 'baz'})) self.assertEqual(auth, ('username', 'password')) return resp self.monkey_patch(requests, 'request', stubbed_request) client = DiamondashApiClient() self.assertEqual( client.request('put', 'foo', {'bar': 'baz'}), {'spam': 'ham'})
def test_request(self): self.vumi_helper.patch_settings(DIAMONDASH_API_USERNAME='******', DIAMONDASH_API_PASSWORD='******') resp = FakeResponse( json.dumps({ 'success': True, 'data': { 'spam': 'ham' } })) def stubbed_request(method, url, data, auth): self.assertEqual(method, 'put') self.assertEqual(url, 'http://diamondash.moc/api/foo') self.assertEqual(data, json.dumps({'bar': 'baz'})) self.assertEqual(auth, ('username', 'password')) return resp self.monkey_patch(requests, 'request', stubbed_request) client = DiamondashApiClient() self.assertEqual(client.request('put', 'foo', {'bar': 'baz'}), {'spam': 'ham'})