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_raw_request_for_error_responses(self): resp = FakeErrorResponse(':(') self.monkey_patch(requests, 'request', lambda *a, **kw: resp) client = DiamondashApiClient() self.assertRaises(DiamondashApiError, client.raw_request, 'put', 'foo', 'bar')
def test_raw_request(self): self.vumi_helper.patch_settings(DIAMONDASH_API_USERNAME='******', DIAMONDASH_API_PASSWORD='******') resp = FakeResponse('spam', 201) def stubbed_request(method, url, data, auth): self.assertEqual(method, 'put') self.assertEqual(url, 'http://diamondash.moc/api/foo') self.assertEqual(data, 'bar') self.assertEqual(auth, ('username', 'password')) return resp self.monkey_patch(requests, 'request', stubbed_request) client = DiamondashApiClient() self.assertEqual(client.raw_request('put', 'foo', 'bar'), { 'code': 201, 'content': 'spam' })
def test_raw_request(self): self.vumi_helper.patch_settings( DIAMONDASH_API_USERNAME='******', DIAMONDASH_API_PASSWORD='******') resp = FakeResponse('spam', 201) def stubbed_request(method, url, data, auth): self.assertEqual(method, 'put') self.assertEqual(url, 'http://diamondash.moc/api/foo') self.assertEqual(data, 'bar') self.assertEqual(auth, ('username', 'password')) return resp self.monkey_patch(requests, 'request', stubbed_request) client = DiamondashApiClient() self.assertEqual(client.raw_request('put', 'foo', 'bar'), { 'code': 201, 'content': 'spam' })
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'})
def test_make_api_url(self): client = DiamondashApiClient() self.assertEqual( client.make_api_url('dashboards'), 'http://diamondash.moc/api/dashboards')
def test_make_api_url(self): client = DiamondashApiClient() self.assertEqual(client.make_api_url('dashboards'), 'http://diamondash.moc/api/dashboards')