~bac/charmworld/tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/tests/test_models.py

  • Committer: Tarmac
  • Author(s): Matthew Scott
  • Date: 2014-03-07 16:13:24 UTC
  • mfrom: (487.3.4 charm-urls)
  • Revision ID: tarmac-20140307161324-8quz1tbpjxvq5all
Normalize charm URLs in bundles

This branch normalizes the charm URLs in bundles for the GUI, which is expecting at least a <schema>:<series>/<name> style URL.  Current proof allows bundles with charms specified only by name, so long as they're in the charmstore already.

Caveats:
* Currently only works on ingest
* May require a GUI branch as well to add -HEAD if no version number (a smart move anyway) depending on API support.


QA:
* Run
* Enqueue and ingest at least mysql and mediawiki
* bin/enqueue --prefix=~bac/charms/bundles
* bin/ingest-queued --prefix=~bac/charms/bundles --limit=100
* Get bac's bundle wiki:wiki - the charms should all have a charm: attribute, and the attributes should all be URLs as specified above.

https://codereview.appspot.com/71070051/

R=benji, rharding.

Approved by Benji York, Juju Gui Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1654
1654
        basket_id = "%s/%d" % (basket_name, basket_rev)
1655
1655
        _id = Bundle.construct_id(owner, basket_name, bundle_name, basket_rev)
1656
1656
        store_bundles(
1657
 
            self.db.bundles, parsed, 'bac', basket_id, None, None, None, None)
 
1657
            self.db.bundles, parsed, 'bac', basket_id, None, None, None, None,
 
1658
            None)
1658
1659
        self.assertEqual(
1659
1660
            {
1660
1661
                '_id': _id,
1704
1705
                   get_flattened_deployment):
1705
1706
            store_bundles(
1706
1707
                self.db.bundles, parsed, 'bac', 'wordpress-basket/5', None,
1707
 
                None, None, None)
 
1708
                None, None, None, None)
1708
1709
        self.assertItemsEqual(['wordpress-stage', 'wordpress-prod'], keys)
1709
1710
 
1710
1711
    def test_storing_a_bundle_includes_indexing_it(self):
1724
1725
                FauxElasticSearchClient):
1725
1726
            store_bundles(
1726
1727
                self.db.bundles, {}, 'owner', 'wordpress-basket/5', None,
1727
 
                None, None, None)
 
1728
                None, None, None, None)
1728
1729
 
1729
1730
        self.assertTrue(FauxElasticSearchClient.index_bundles_called)
1730
1731
 
2091
2092
            'promulgated': True,
2092
2093
        }, doc)
2093
2094
 
 
2095
    def test_bundle_doc_with_services_info(self):
 
2096
        data = {
 
2097
            'services': {
 
2098
                'mysql': {
 
2099
                    'charm': 'mysql',
 
2100
                },
 
2101
                'mediawiki': {
 
2102
                    'branch': 'lp:mediawiki',
 
2103
                },
 
2104
            }
 
2105
        }
 
2106
        expected_data = {
 
2107
            'services': {
 
2108
                'mysql': {
 
2109
                    'charm': 'cs:precise/mysql',
 
2110
                },
 
2111
                'mediawiki': {
 
2112
                    'branch': 'lp:mediawiki',
 
2113
                    'charm': 'cs:precise/mediawiki',
 
2114
                },
 
2115
            }
 
2116
        }
 
2117
        services_info = {
 
2118
            'mysql': {
 
2119
                'store_url': 'cs:precise/mysql-1',
 
2120
            },
 
2121
            'mediawiki': {
 
2122
                'store_url': 'cs:precise/mediawiki-1',
 
2123
            },
 
2124
        }
 
2125
        doc = make_bundle_doc(
 
2126
            data, 'foo', 'bar/9', 'baz', None, None, None,
 
2127
            'fake/branch/spec', True, services_info)
 
2128
        self.assertEqual({
 
2129
            'owner': 'foo',
 
2130
            'basket_name': 'bar',
 
2131
            'basket_revision': 9,
 
2132
            'name': 'baz',
 
2133
            'data': expected_data,
 
2134
            '_id': '~foo/bar/9/baz',
 
2135
            'first_change': None,
 
2136
            'last_change': None,
 
2137
            'changes': None,
 
2138
            'branch_spec': 'fake/branch/spec',
 
2139
            'promulgated': True,
 
2140
        }, doc)
 
2141
 
2094
2142
 
2095
2143
class TestSlurpFiles(MongoTestBase):
2096
2144