def test_filtered_query(self, mock_request): """ Arguments passed to .filter() are stored on new (copied) Query instance and are not supposed to be cleared when that query is evaluated. """ # Create a basic filter query for PPP... query = Query(self.client, Tour).filter(tour_dossier_code='PPP') self.assertEqual(len(query._filters), 1) # ... then chain on another filter argument... query = query.filter(order_by__asc='departures_start_date') self.assertEqual(len(query._filters), 2) # ... and force query evaluation, before checking... list(query) # ... our request was made with the appropriate query args, and... mock_request.assert_called_once_with('/tours', 'GET', params={ 'tour_dossier_code': 'PPP', 'order_by__asc': 'departures_start_date', }) mock_request.reset_mock() # ... our stored filter args remain for the current instance. self.assertEqual(len(query._filters), 2) # .count() should remain the query filters and # respond from a new instance with the count value: query.count() self.assertEqual(len(query._filters), 2)
def test_filtered_query(self, mock_request): """ Arguments passed to .filter() are stored on the Query instance but are cleared when that query is evaluated. """ # Create a basic filter query for PPP... query = Query(self.client, Tour).filter(tour_dossier_code='PPP') self.assertEqual(len(query._filters), 1) # ... then chain on another filter argument... query = query.filter(order_by__asc='departures_start_date') self.assertEqual(len(query._filters), 2) # ... and force query evaluation, before checking... list(query) # ... our request was made with the appropriate query args, and... mock_request.assert_called_once_with('/tours', 'GET', params={ 'tour_dossier_code': 'PPP', 'order_by__asc': 'departures_start_date', }) mock_request.reset_mock() # ... our stored filter args got reset. self.assertEqual(len(query._filters), 0) # Check .count() also clears stored filter args appropriately: query.filter(tour_dossier_code='PPP', order_by__desc='departures_start_date').count() mock_request.assert_called_once_with('/tours', 'GET', params={ 'tour_dossier_code': 'PPP', 'order_by__desc': 'departures_start_date', }) mock_request.reset_mock() self.assertEqual(len(query._filters), 0)
def test_filtered_query(self, mock_request): """ Arguments passed to .filter() are stored on the Query instance but are cleared when that query is evaluated. """ # Create a basic filter query for PPP... query = Query(self.client, Tour).filter(tour_dossier_code='PPP') self.assertEqual(len(query._filters), 1) # ... then chain on another filter argument... query = query.filter(order_by__asc='departures_start_date') self.assertEqual(len(query._filters), 2) # ... and force query evaluation, before checking... list(query) # ... our request was made with the appropriate query args, and... mock_request.assert_called_once_with( '/tours', 'GET', params={ 'tour_dossier_code': 'PPP', 'order_by__asc': 'departures_start_date', }) mock_request.reset_mock() # ... our stored filter args got reset. self.assertEqual(len(query._filters), 0) # Check .count() also clears stored filter args appropriately: query.filter( tour_dossier_code='PPP', order_by__desc='departures_start_date').count() mock_request.assert_called_once_with( '/tours', 'GET', params={ 'tour_dossier_code': 'PPP', 'order_by__desc': 'departures_start_date', }) mock_request.reset_mock() self.assertEqual(len(query._filters), 0)
def test_query_persist_filter_on_count(self, mock_request): query = Query(self.client, Tour) my_query = query.filter(tour_dossier_code='PPP') my_query.count() self.assertEqual(my_query._filters, {'tour_dossier_code': 'PPP'})
def test_query_reset_filter(self, mock_request): query = Query(self.client, Tour) query.filter(tour_dossier_code='PPP').count() self.assertEqual(query._filters, {})