~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/tests/test_search.py

[r=sinzui][bug=1208477][author=abentley] Remove doctype attribute.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    BUNDLE,
28
28
    CHARM,
29
29
    ElasticSearchClient,
30
 
    charm_exact_fields,
31
 
    charm_free_text_fields,
 
30
    exact_fields,
 
31
    free_text_fields,
32
32
    IncompatibleMapping,
33
33
    IndexMissing,
34
34
    IndexNotReady,
145
145
    def test_search_bundle(self):
146
146
        bundle = Bundle(self.makeBundle())
147
147
        client = self.index_client
148
 
        results = client.search(bundle.name)['results']
149
 
        self.assertEqual(1, len(results['bundle']))
150
 
        self.assertEqual(bundle, results['bundle'][0]['data'])
 
148
        results = client.search(bundle.name)['results']['bundle']
 
149
        self.assertEqual(1, len(results))
 
150
        self.assertEqual(bundle, results[0]['data'])
151
151
 
152
152
    def test_store_bundles(self):
153
153
        # Ensure that bundles stored into the index via the `store_bundles`
238
238
        return [hit['data']._id for hit in hits]
239
239
 
240
240
    def test_search_matches_on_search_terms(self):
241
 
        fields = charm_free_text_fields.keys() + charm_exact_fields
 
241
        fields = free_text_fields.keys() + exact_fields
242
242
        fields = [field.split('.')[0] for field in fields]
243
243
        charm = factory.get_charm_json(categories=['unknown'])
244
244
        # Ensure all fields have unique values.
397
397
    def test_autocomplete_matches_on_names(self):
398
398
        matching_charm = self.makeCharm(name='foo')
399
399
        differing_charm = self.makeCharm(name='bar')
400
 
        for field in charm_free_text_fields:
 
400
        for field in free_text_fields:
401
401
            if '.' in field or field == 'name':
402
402
                continue
403
403
            differing_charm[field] = 'foo'
404
 
        for field in charm_exact_fields:
 
404
        for field in exact_fields:
405
405
            differing_charm[field] = 'foo'
406
406
        self.index_client.index_charm(differing_charm)
407
407
        ids = [charm['_id'] for charm in self.index_client.api_search('foo',
634
634
        alias.update_aliased('bar', alias.get_aliased())
635
635
        self.assertEqual(['bar'], alias.get_aliased())
636
636
 
637
 
    def test_create_replacement_charm_indexed_in_place(self):
 
637
    def test_create_replacement(self):
638
638
        charm_data = {'_id': 'a', 'name': 'foo', 'owner': 'bar',
639
639
                      'series': 'baz'}
640
640
        self.index_client.index_charm(charm_data)
644
644
        self.assertIn('series', copy.get_mapping()[CHARM]['properties'])
645
645
        self.assertEqual(charm_data, copy.get('a'))
646
646
 
647
 
    def test_create_replacement_bundle_indexed_in_place(self):
648
 
        bundle_data = {'_id': 'a', 'name': 'foo', 'owner': 'bar',
649
 
                       'data': {'series': 'baz'}}
650
 
        self.index_client.index_bundle(bundle_data)
651
 
        copy = self.index_client.create_replacement('index-copy')
652
 
        self.addCleanup(copy.delete_index)
653
 
        copy.wait_for_startup()
654
 
        self.assertIn('series',
655
 
                      copy.get_mapping(doctype=BUNDLE)[BUNDLE]['properties'])
656
 
        self.assertEqual(bundle_data, copy.get('a', BUNDLE))
657
 
 
658
 
    def test_create_replacement_charms_replacing_old(self):
 
647
    def test_create_replacement_charms(self):
659
648
        charm_data = {'_id': 'a', 'name': 'foo', 'owner': 'bar',
660
649
                      'series': 'baz'}
661
650
        charm_data2 = {'_id': 'a', 'name': 'bar', 'owner': 'bar',
668
657
        self.assertIn('series', copy.get_mapping()[CHARM]['properties'])
669
658
        self.assertEqual(charm_data2, copy.get('a'))
670
659
 
671
 
    def test_create_replacement_bundles_replacing_old(self):
672
 
        bundle_data = {'_id': 'a', 'name': 'foo', 'owner': 'bar',
673
 
                       'series': 'baz'}
674
 
        bundle_data2 = {'_id': 'a', 'name': 'bar', 'owner': 'bar',
675
 
                        'series': 'baz'}
676
 
        self.index_client.index_bundle(bundle_data)
677
 
        copy = self.index_client.create_replacement(
678
 
            bundles=[bundle_data2])
679
 
        self.addCleanup(copy.delete_index)
680
 
        copy.wait_for_startup()
681
 
        self.assertIn('series',
682
 
                      copy.get_mapping(doctype=BUNDLE)[BUNDLE]['properties'])
683
 
        self.assertEqual(bundle_data2, copy.get('a', BUNDLE))
684
 
 
685
 
    def test_create_replacement_missing(self):
 
660
    def test_create_replacement_misssing(self):
686
661
        client = ElasticSearchClient.from_settings(get_ini(), 'temp-index')
687
662
        # This should not raise an exception, even though the index has not
688
663
        # been created.