def test_result_list(session): """Test the result object.""" obj = base.ResultList(parent=session, item_class=MockDataObject, resp={ "_metadata": { "count": 2, "next": None, "previous": None, }, "results": [{ "attr1": "value1", "attr2": "value2", }, { "attr1": "value3" }], }) next_list = session.loop.run_until_complete(obj.get_next()) previous_list = session.loop.run_until_complete(obj.get_previous()) assert obj.next is None assert obj.previous is None assert next_list is None assert previous_list is None assert len(obj) == 2 assert sorted([item.attr1 for item in obj]) == sorted(["value1", "value3"])
def get_devices(self, **kwargs): """Get all devices associated with this user account. :param device__serial_number: Device serial number :param page: Page number of paginated result to return :param limit: Number of results per page """ querystring = gen_query_string(validation.DEVICES_REQUEST(kwargs)) _LOGGER.info("Fetching devices.") resp = yield from self._get('?'.join((const.DEVICE_URL, querystring))) return base.ResultList(self, resp, data.Device)
def get_vehicles(self, **kwargs): """Get all vehicles associated with this user account. :param created_at__lte: Maximum start time filter :param created_at__gte: Minimum start time filter :param updated_at__lte: Maximum end time filter :param updated_at__gte: Minimum end time filter :param vin: Vin filter :param page: Page number of paginated result to return :param limit: Number of results per page """ querystring = gen_query_string(validation.VEHICLES_REQUEST(kwargs)) _LOGGER.info("Fetching vehicles.") resp = yield from self._get('?'.join((const.VEHICLE_URL, querystring))) return base.ResultList(self, resp, data.Vehicle)
def get_trips(self, **kwargs): """Get all vehicles associated with this user account. :param started_at__lte: Maximum start time filter :param started_at__gte: Minimum start time filter :param ended_at__lte: Maximum end time filter :param ended_at__gte: Minimum end time filter :param vehicle: Vehicle Filter :param tags__in: Tags Filter :param page: Page number of paginated result to return :param limit: Number of results per page """ querystring = gen_query_string(validation.TRIPS_REQUEST(kwargs)) _LOGGER.info("Fetching trips.") resp = yield from self._get('?'.join((const.TRIP_URL, querystring))) return base.ResultList(self, resp, data.Trip)
def test_result_previous_list(session): """Test the result object get previous list.""" obj = base.ResultList(parent=session, item_class=MockDataObject, resp={ "_metadata": { "count": 0, "next": None, "previous": "previous_url", }, "results": [], }) resp = AsyncMock() resp.status = 200 mock_json = { "_metadata": { "count": 2, "next": None, "previous": None, }, "results": [{ "attr1": "value1", "attr2": "value2", }, { "attr1": "value3" }], } resp.json.return_value = mock_json session._client_session.request.return_value = resp next_list = session.loop.run_until_complete(obj.get_next()) previous_list = session.loop.run_until_complete(obj.get_previous()) assert obj.next is None assert next_list is None assert len(obj) == 0 assert obj.previous is "previous_url" assert len(obj) == 0 assert len(previous_list) == 2 assert sorted([item.attr1 for item in previous_list]) == \ sorted(["value1", "value3"])