def test_index_objects_public(self, get_es_mock): user_1 = UserFactory.create() user_2 = UserFactory.create() model = MagicMock() model.objects.privacy_level().filter.return_value = [ user_1.userprofile, user_2.userprofile ] index_objects(model, [user_1.userprofile.id, user_2.userprofile.id], True) model.objects.assert_has_calls([ call.filter(id__in=[user_1.userprofile.id, user_2.userprofile.id]), call.privacy_level(PUBLIC) ]) model.index.assert_has_calls([ call(model.extract_document(), bulk=True, id_=user_1.userprofile.id, es=get_es_mock(), public_index=True), call(model.extract_document(), bulk=True, id_=user_2.userprofile.id, es=get_es_mock(), public_index=True) ]) model.refresh_index.assert_has_calls( [call(es=get_es_mock()), call(es=get_es_mock())])
def test_index_objects(self, get_es_mock): user_1 = UserFactory.create() user_2 = UserFactory.create() mapping_type = MagicMock() model = MagicMock() mapping_type.get_model.return_value = model model.objects.filter.return_value = [user_1.userprofile, user_2.userprofile] mapping_type.extract_document.return_value = 'foo' index_objects(mapping_type, [user_1.userprofile.id, user_2.userprofile.id], public_index=False) mapping_type.bulk_index.assert_has_calls([ call(['foo', 'foo'], id_field='id', es=get_es_mock(), index=mapping_type.get_index(False))])
def test_index_objects(self, get_es_mock): user_1 = UserFactory.create() user_2 = UserFactory.create() model = MagicMock() model.objects.filter.return_value = [user_1.userprofile, user_2.userprofile] index_objects(model, [user_1.userprofile.id, user_2.userprofile.id], False) model.objects.assert_has_calls([call.filter(id__in=[user_1.userprofile.id, user_2.userprofile.id])]) model.index.assert_has_calls( [ call( model.extract_document(), bulk=True, id_=user_1.userprofile.id, es=get_es_mock(), public_index=False ), call( model.extract_document(), bulk=True, id_=user_2.userprofile.id, es=get_es_mock(), public_index=False ), ] ) model.refresh_index.assert_has_calls([call(es=get_es_mock()), call(es=get_es_mock())])
def test_index_objects_public(self, get_es_mock): user_1 = UserFactory.create() user_2 = UserFactory.create() mapping_type = MagicMock() model = MagicMock() mapping_type.get_model.return_value = model qs = model.objects.filter().public_indexable().privacy_level qs.return_value = [user_1.userprofile, user_2.userprofile] mapping_type.extract_document.return_value = 'foo' index_objects(mapping_type, [user_1.userprofile.id, user_2.userprofile.id], public_index=True) model.objects.assert_has_calls([ call.filter(id__in=(user_1.userprofile.id, user_2.userprofile.id)), call.filter().public_indexable(), call.filter().public_indexable().privacy_level(PUBLIC), ]) mapping_type.bulk_index.assert_has_calls([ call(['foo', 'foo'], id_field='id', es=get_es_mock(), index=mapping_type.get_index(True))])