848
848
"Character '%s' at the end of a search term causes "
849
849
"ElasticHttpError" % char)
851
def test_mapping_changes_during_indexing(self):
852
# When a charm is indexed, only the mappings for the properties
853
# "requires" and "provides" change.
854
before = self.index_client.get_mapping()['charm']['properties']
855
before = before['data']['properties']
856
charm = factory.get_charm_json()
857
self.index_client.index_charm(charm)
858
after = self.index_client.get_mapping()['charm']['properties']
859
after = after['data']['properties']
860
before_provides = before.pop('provides')
861
before_requires = before.pop('requires')
862
after_provides = after.pop('provides')
863
after_requires = after.pop('requires')
864
self.assertEqual(before, after)
865
self.assertNotEqual(before_provides, after_provides)
866
self.assertNotEqual(before_requires, after_requires)
852
869
class TestIndexingBundles(TestCase):
877
894
self.index_client.index_bundles([])
880
def put_mapping(client, properties):
897
def put_mapping(client, properties, dynamic=True):
881
898
client._client.put_mapping(
882
899
client.index_name, CHARM, {
884
902
'properties': {'data': {'properties': properties}}
930
948
self.assertEqual('not_analyzed',
931
949
mapping['properties']['name']['index'])
951
def update_to_static_mapping(self, force_reindex):
952
index_client = self.use_index_client(put_mapping=False)
955
{'box': {'type': 'string', 'index': 'not_analyzed'}},
957
update(index_client, force_reindex)
958
updated_mapping = index_client.get_mapping()
959
# A property 'files' is not defined in the current mapping.
962
updated_mapping['charm']['properties']['data']['properties'])
963
index_client.index_charm(factory.get_charm_json())
966
def test_simple_change_dynamic_to_static_mapping(self):
967
# If an existing mapping is dynamic (the default for ElasticSearch)
968
# and if a new mapping is specified as static, the two mappings
969
# are considered compatible, but the resulting mapping is
971
index_client = self.update_to_static_mapping(force_reindex=False)
972
updated_mapping = index_client.get_mapping()
973
# charm['files'] is not supposed to be included in the new
974
# mapping, but it still exists if force_reindex is not used.
977
updated_mapping['charm']['properties']['data']['properties'])
979
def test_dynamic_to_static_mapping_forced_reindex(self):
980
# If an existing mapping is dynamic (the defult) and if a
981
# new mapping is specified as static, the two mappings
982
# are considered compatible, but the resulting mapping is
984
index_client = self.update_to_static_mapping(force_reindex=True)
985
updated_mapping = index_client.get_mapping()
986
# The mapping is indeed static; charm['files'] is not indexed.
989
updated_mapping['charm']['properties']['data']['properties'])
934
992
class TestReindex(TestCase):