def setUp(self, *args, **kwargs): """Add the test cars.""" # Create 22 cars for i in range(0, 22): datetime_now = datetime.now() # Create a car car = Car(make='Make {}'.format(i), model='Model {}'.format(i), year_manufactured=datetime_now) car.save()
def test_disabling_indexing(self): """Test disabling app search indexing.""" config = DjangoAppSearchConfig( app_name=self.original_config.name, app_module=self.original_config.module, ) # Create 22 cars for i in range(0, 22): datetime_now = datetime.now() # Create a car car = Car( make='Make {}'.format(i), model='Model {}'.format(i), year_manufactured=datetime_now ) car.save() with patch( 'django_elastic_appsearch.orm.apps.get_app_config', autospec=True, return_value=config ): car = Car.objects.first() car.index_to_appsearch() car.delete_from_appsearch() car_queryset = Car.objects.all() car_queryset.index_to_appsearch() car_queryset.delete_from_appsearch() self.assertEqual(self.client_index.call_count, 0) self.assertEqual(self.client_destroy.call_count, 0)
def setUp(self, *args, **kwargs): """Load test data.""" super().setUp(*args, **kwargs) timezone_now = timezone.now() car1 = Car(make='Toyota', model='Corolla', year_manufactured=timezone_now) car1.save() car2 = Car(make='Peugeot', model='307', year_manufactured=timezone_now) car2.save()
def test_app_search_serialiser(self): """Test the `AppSearchSerialiser`.""" datetime_now = datetime.now() # Create a car car = Car(make='Toyota', model='Corolla', year_manufactured=datetime_now) car.save() # Instantiate a serialiser object with the new car object car_serialiser = CarSerialiser(car) data = car_serialiser.data # Test if the Car is serialised as expected self.assertEqual(data.get('id'), car.get_appsearch_document_id()) self.assertEqual(data.get('object_type'), 'Car') self.assertEqual(data.get('make'), 'Toyota') self.assertEqual(data.get('model'), 'Corolla') self.assertEqual(data.get('verbose_name'), 'Toyota Corolla') self.assertEqual(data.get('year_manufactured'), datetime_now)