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_count(self, mock_request): query = Query(self.client, TourDossier) count = query.count() self.assertIsInstance(count, int) self.assertEqual(count, 3)
def test_count(self, mock_request): query = Query(self.client, TourDossier) count = query.count() self.assertIsInstance(count, int) self.assertEqual(count, 3)