~reedobrien/charmworld/027test-fails

« back to all changes in this revision

Viewing changes to charmworld/views/tests/test_api.py

  • Committer: Tarmac
  • Author(s): Brad Crittenden
  • Date: 2014-05-07 14:01:57 UTC
  • mfrom: (507.1.2 annotation-dos)
  • Revision ID: tarmac-20140507140157-sr36ao5d25irvupo
Include annotations in bundle search results.

The previous attempt at this problem was flawed in that API call for
getting bundles directly pulls from Mongo while search?text= and
search/interesting get results from ElasticSearch.

QA:

Load up some bundles with annotations:

bin/ingest-queued --prefix="~charmers/charms/precise/ntp"
bin/ingest-queued --prefix="~bac"

Change juju-gui to point to locally running charmworld:

diff --git a/app/config-debug.js b/app/config-debug.js
index 39daca6..f2c86b6 100644
--- a/app/config-debug.js
+++ b/app/config-debug.js
@@ -32,7 +32,10 @@ var juju_config = {
   // These are the main application config items used and passed down into all
   // SubApps.
   consoleEnabled: true,
+  //charmworldURL: 'https://manage.jujucharms.com/',
+  charmworldURL: 'http://127.0.0.1:2464/',

Run charmworld and juju-gui.  In the GUI wait for the initial results to
load.  These are the Featured charms and bundles.

Select the rails-scalable bundle.  Note the layout in the inspector.  Close
the inspector and then drag the bundle (using the name not the icon) to the
canvas.  Note that the layout is the same as the preview.

https://codereview.appspot.com/91140045/

R=jcsackett.

Approved by Juju Gui Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
212
212
        charm_id, charm = factory.makeCharm(self.db, *args, **kwargs)
213
213
        self.index_client.index_charm(charm)
214
214
        if is_featured:
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
217
217
 
218
218
    def test_remote_friendly_headers(self):
1669
1669
        _id, charm = factory.makeCharm(self.db, promulgated=True)
1670
1670
        services = {
1671
1671
            u'charm': {
1672
 
                u'charm': charm['name']
 
1672
                u'charm': charm['name'],
1673
1673
            }
1674
1674
        }
1675
1675
        bundle = self.make_indexed_bundle(
1685
1685
        self.assertTrue(found_bundle['charm_metadata']['charm'])
1686
1686
        self.assertEqual(
1687
1687
            charm['name'],
1688
 
            found_bundle['charm_metadata']['charm']['name']
1689
 
        )
 
1688
            found_bundle['charm_metadata']['charm']['name'])
1690
1689
 
1691
1690
    def test_charm_wrong_revision(self):
1692
1691
        # Retrieving a charm does not work if the revision is wrong.
1766
1765
        self.assertItemsEqual(expected, list_names(result['new']))
1767
1766
        self.assertItemsEqual(expected, list_names(result['featured']))
1768
1767
 
 
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)
 
1773
        extra_data = {
 
1774
            u'annotations': {
 
1775
                'gui-x': '98.6',
 
1776
                'gui-y': '32',
 
1777
            },
 
1778
        }
 
1779
 
 
1780
        services = {
 
1781
            u'charm': {
 
1782
                u'branch': charm['branch_spec'],
 
1783
                u'charm': charm['name'],
 
1784
            }
 
1785
        }
 
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']
 
1801
            self.assertEqual(
 
1802
                extra_data['annotations'],
 
1803
                bundle_result['data']['services']['charm']['annotations'])
 
1804
 
 
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')
 
1809
        extra_data = {
 
1810
            u'annotations': {
 
1811
                'gui-x': '98.6',
 
1812
                'gui-y': '32',
 
1813
            },
 
1814
        }
 
1815
 
 
1816
        services = {
 
1817
            u'charm': {
 
1818
                u'branch': charm['branch_spec'],
 
1819
                u'charm': charm['name'],
 
1820
            }
 
1821
        }
 
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']
 
1831
        self.assertEqual(
 
1832
            extra_data['annotations'],
 
1833
            bundle_result['data']['services']['charm']['annotations'])
 
1834
 
1769
1835
 
1770
1836
class TestAPI2(TestAPI, API2Mixin):
1771
1837
    """Test API 2."""