~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/migrations/versions/tests/test_migrations.py

[r=sinzui][bug=][author=benji] - Remove useless try/except accidentally left in store_bundles from last
  branch
- add migration 018 which removes all bundles from the DB and ES (they
  will be repopulated at the next ingestion)
- add an explicit construct_search_id so it is easier to see the
  semantics of ID creation when reading the code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright 2012, 2013 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
 
4
import textwrap
 
5
import yaml
 
6
 
4
7
from charmworld.models import (
5
8
    Bundle,
6
9
    CharmSource,
7
10
    construct_charm_id,
8
11
    FeaturedSource,
9
12
    QADataSource,
 
13
    store_bundles,
10
14
)
11
15
from charmworld.search import (
12
16
    BUNDLE,
272
276
        new_mapping = self.index_client.get_mapping()
273
277
        self.assertNotIn(
274
278
            'files', new_mapping['charm']['properties']['data']['properties'])
 
279
 
 
280
class TestMigration018(MigrationTestBase):
 
281
 
 
282
    def setUp(self):
 
283
        super(TestMigration018, self).setUp()
 
284
        self.use_index_client()
 
285
        self.store_some_bundles()
 
286
 
 
287
    def store_some_bundles(self):
 
288
        deployer_config = textwrap.dedent("""\
 
289
            wordpress-stage:
 
290
                series: precise
 
291
                services:
 
292
                    blog:
 
293
                        charm: cs:precise/wordpress
 
294
                        constraints: mem=2
 
295
                        options:
 
296
                            tuning: optimized
 
297
                            engine: apache
 
298
        """)
 
299
        parsed = yaml.safe_load(deployer_config)
 
300
        owner = 'owner'
 
301
        bundle_name = 'wordpress-stage'
 
302
        basket_id = 'wordpress-basket/5'
 
303
        self.search_id = Bundle.construct_search_id(
 
304
            owner, basket_id, bundle_name)
 
305
        store_bundles(self.db.bundles, parsed, owner, basket_id, 
 
306
            index_client=self.index_client)
 
307
 
 
308
    def test_bundles_are_removed_from_elastic_search(self):
 
309
        assert self.index_client.get(self.search_id, BUNDLE), (
 
310
            'the test bundle is missing')
 
311
        self.versions.run_migration(
 
312
            self.db, self.index_client, '018_delete_all_bundles.py')
 
313
        self.assertIsNone(self.index_client.get(self.search_id, BUNDLE))
 
314
 
 
315
    def test_bundles_are_removed_from_mongo(self):
 
316
        assert self.index_client.get(self.search_id, BUNDLE), (
 
317
            'the test bundle is missing')
 
318
        self.versions.run_migration(
 
319
            self.db, self.index_client, '018_delete_all_bundles.py')
 
320
        self.assertIsNone(self.db.bundles.find_one({}))