def test_defaults(self): """ Call to the list endpoint with the defaults params. """ api = CDMSRestApi() api.list(self.service) self.assertEqual(len(responses.calls), 1) self.assertEqual( urlparse(responses.calls[0].request.url).query, '$top=50&$skip=0&')
def test_order_by_as_string(self): """ Call to the list endpoint with the order_by param as a string instead of a list. """ api = CDMSRestApi() api.list(self.service, order_by='something') self.assertEqual(len(responses.calls), 1) self.assertEqual( urlparse(responses.calls[0].request.url).query, '$top=50&$skip=0&$orderby=something')
def cdms_list(client, entity_name, offset): ''' Call the `cdms_api.list` method, passing through the entity_name and offset. This function records the duration of the network request. It also caches the resulting response if it’s successful and raises an informative exception if it’s not. ''' cached, cache_path = is_cached(entity_name, offset) if cached: # nothing to do, just load resp from cache return services.redis.get(cache_path) start_time = datetime.datetime.now() if client is None: client = CDMSRestApi() resp = client.list(entity_name, skip=offset) # the actual request time_delta = (datetime.datetime.now() - start_time).seconds # the below will raise something useful, or pass by quietly raise_on_cdms_resp_errors(entity_name, offset, resp) # record our expensive network request services.redis.set(duration_record(entity_name, offset), str(time_delta)) services.redis.set(cache_path, resp.content.decode(resp.encoding or 'utf-8')) LOGGER.info("{0} ({1}) {2}s".format(entity_name, offset, time_delta)) return resp.content
def test_complete(self): """ Call to the list endpoint with all params defined. """ api = CDMSRestApi() api.list(self.service, top=10, skip=1, select=['a', 'b'], filters='c,d', order_by=['e', 'f']) self.assertEqual(len(responses.calls), 1) self.assertEqual( urlparse(responses.calls[0].request.url).query, '$top=10&$skip=1&$filter=c,d&$orderby=e,f&$select=a,b')