212
212
charm_id, charm = factory.makeCharm(self.db, *args, **kwargs)
213
213
self.index_client.index_charm(charm)
215
FeaturedSource.from_db(self.db).set_featured(charm, 'charm')
215
FeaturedSource.from_db(self.db).set_featured(charm, CHARM)
216
216
return charm_id, charm
218
218
def test_remote_friendly_headers(self):
1766
1765
self.assertItemsEqual(expected, list_names(result['new']))
1767
1766
self.assertItemsEqual(expected, list_names(result['featured']))
1768
def test_search_interesting_contains_annotations(self):
1769
self.use_index_client()
1770
self.enable_routes()
1771
charm = self.make_indexed_charm(name='cat')
1772
FeaturedSource.from_db(self.db).set_featured(charm, CHARM)
1782
u'branch': charm['branch_spec'],
1783
u'charm': charm['name'],
1786
services['charm'].update(extra_data)
1787
bundle = self.make_indexed_bundle(name='bat', services=services)
1788
FeaturedSource.from_db(self.db).set_featured(
1789
bundle._representation, BUNDLE)
1790
result = self.get_response(
1791
self.search_endpoint, 'interesting').json_body['result']
1792
self.assertEqual(3, len(result))
1793
expected = [charm['name'], bundle.name]
1794
self.assertItemsEqual(expected, list_names(result['popular']))
1795
self.assertItemsEqual(expected, list_names(result['new']))
1796
self.assertItemsEqual(expected, list_names(result['featured']))
1797
# Bundles have annotations.
1798
for item in result.itervalues():
1799
items = sorted(item, key=lambda x: x['metadata'])
1800
bundle_result = items[0]['bundle']
1802
extra_data['annotations'],
1803
bundle_result['data']['services']['charm']['annotations'])
1805
def test_text_search_contains_annotations(self):
1806
self.use_index_client()
1807
self.enable_routes()
1808
charm = self.make_indexed_charm(name='cat')
1818
u'branch': charm['branch_spec'],
1819
u'charm': charm['name'],
1822
services['charm'].update(extra_data)
1823
bundle = self.make_indexed_bundle(name='bat', services=services)
1824
result = self.get_response(
1825
self.search_endpoint, text=bundle.name).json_body['result']
1826
self.assertEqual(1, len(result))
1827
expected = [bundle.name]
1828
self.assertItemsEqual(expected, list_names(result))
1829
# Bundles have annotations.
1830
bundle_result = result[0]['bundle']
1832
extra_data['annotations'],
1833
bundle_result['data']['services']['charm']['annotations'])
1770
1836
class TestAPI2(TestAPI, API2Mixin):
1771
1837
"""Test API 2."""