~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/tests/test_search.py

  • Committer: Curtis Hovey
  • Date: 2013-08-20 22:05:56 UTC
  • mfrom: (358 charmworld)
  • mto: This revision was merged to the branch mainline in revision 359.
  • Revision ID: curtis@canonical.com-20130820220556-zhm7woolfb0hs81x
Merged tip.

Show diffs side-by-side

added added

removed removed

Lines of Context:
848
848
                    "Character '%s' at the end of a search term causes "
849
849
                    "ElasticHttpError" % char)
850
850
 
 
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)
 
867
 
851
868
 
852
869
class TestIndexingBundles(TestCase):
853
870
 
877
894
                self.index_client.index_bundles([])
878
895
 
879
896
 
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, {
883
900
            CHARM: {
 
901
                'dynamic': dynamic,
884
902
                'properties': {'data': {'properties': properties}}
885
903
            }
886
904
        }
930
948
        self.assertEqual('not_analyzed',
931
949
                         mapping['properties']['name']['index'])
932
950
 
 
951
    def update_to_static_mapping(self, force_reindex):
 
952
        index_client = self.use_index_client(put_mapping=False)
 
953
        put_mapping(
 
954
            index_client,
 
955
            {'box': {'type': 'string', 'index': 'not_analyzed'}},
 
956
            dynamic=True)
 
957
        update(index_client, force_reindex)
 
958
        updated_mapping = index_client.get_mapping()
 
959
        # A property 'files' is not defined in the current mapping.
 
960
        self.assertNotIn(
 
961
            'files',
 
962
            updated_mapping['charm']['properties']['data']['properties'])
 
963
        index_client.index_charm(factory.get_charm_json())
 
964
        return index_client
 
965
 
 
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
 
970
        # still dynamic.
 
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.
 
975
        self.assertIn(
 
976
            'files',
 
977
            updated_mapping['charm']['properties']['data']['properties'])
 
978
 
 
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
 
983
        # still dynamic.
 
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.
 
987
        self.assertNotIn(
 
988
            'files',
 
989
            updated_mapping['charm']['properties']['data']['properties'])
 
990
 
933
991
 
934
992
class TestReindex(TestCase):
935
993