Merge lp:~thisfred/desktopcouch/fix-deletion-migration-view into lp:desktopcouch

Proposed by Eric Casteleijn
Status: Merged
Approved by: Vincenzo Di Somma
Approved revision: 247
Merged at revision: 246
Proposed branch: lp:~thisfred/desktopcouch/fix-deletion-migration-view
Merge into: lp:desktopcouch
Diff against target: 139 lines (+42/-9)
3 files modified
desktopcouch/application/migration/__init__.py (+1/-2)
desktopcouch/application/migration/tests/test_migration.py (+41/-5)
po/POTFILES.in (+0/-2)
To merge this branch: bzr merge lp:~thisfred/desktopcouch/fix-deletion-migration-view
Reviewer Review Type Date Requested Status
Vincenzo Di Somma (community) Approve
Martin Albisetti (community) Approve
Review via email: mp+45270@code.launchpad.net

Commit message

Fixes the view for the deletion migration so it does not break on couchdb documents with no record_type.

Description of the change

Fixes the view for the deletion migration so it does not break on couchdb documents with no record_type.

To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) :
review: Approve
Revision history for this message
Vincenzo Di Somma (vds) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/application/migration/__init__.py'
2--- desktopcouch/application/migration/__init__.py 2010-11-26 22:06:03 +0000
3+++ desktopcouch/application/migration/__init__.py 2011-01-05 17:49:15 +0000
4@@ -58,7 +58,6 @@
5 if not dbs:
6 dbs = all_dbs
7 for db_name in dbs:
8- print db_name
9 db = server.DesktopDatabase(database=db_name, ctx=ctx)
10 try:
11 migration['method'](db)
12@@ -71,7 +70,7 @@
13 DELETION_VIEW_CODE = """
14 function(doc) {
15 if (doc['application_annotations']['Ubuntu One']
16- ['private_application_annotations']['deleted']) {
17+ ['private_application_annotations']['deleted'] && doc.record_type) {
18 emit(doc.id, doc.id);
19 }
20 }"""
21
22=== modified file 'desktopcouch/application/migration/tests/test_migration.py'
23--- desktopcouch/application/migration/tests/test_migration.py 2010-12-08 19:59:58 +0000
24+++ desktopcouch/application/migration/tests/test_migration.py 2011-01-05 17:49:15 +0000
25@@ -25,12 +25,13 @@
26 import testtools
27
28 from couchdb.http import ResourceNotFound
29+from uuid import uuid4
30
31 from desktopcouch.application import migration
32 import desktopcouch.application.tests as test_environment
33 from desktopcouch.application.server import DesktopDatabase
34 from desktopcouch.records import Record, NoRecordTypeSpecified
35-from desktopcouch.records.database import DCTRASH
36+from desktopcouch.records.database import DCTRASH, base_n
37 from desktopcouch.application.stop_local_couchdb import stop_couchdb
38
39
40@@ -49,6 +50,7 @@
41
42 def setUp(self):
43 """setup each test"""
44+ self.old_registry = migration.MIGRATIONS_REGISTRY[:]
45 super(MigrationBase, self).setUp()
46 self.ctx = get_test_context()
47 self.dbname = self._testMethodName
48@@ -66,6 +68,7 @@
49 if this_context != test_environment.test_context:
50 stop_couchdb(ctx=this_context)
51 super(MigrationBase, self).tearDown()
52+ migration.MIGRATIONS_REGISTRY = self.old_registry[:]
53
54
55 class TestRegistration(MigrationBase):
56@@ -88,11 +91,11 @@
57
58 def test_register_migration_is_added_to_the_registry(self):
59 """Test that the migration script is correctly registered."""
60- size = len(migration.MIGRATIONS_REGISTRY)
61+ migration.MIGRATIONS_REGISTRY = []
62 migration.register(migration_method=fake_migration, dbs=[self.dbname])
63 self.assertEqual([{'method': fake_migration, 'dbs': [self.dbname]}],
64 migration.MIGRATIONS_REGISTRY)
65- self.assertEqual(size + 1, len(migration.MIGRATIONS_REGISTRY))
66+ self.assertEqual(1, len(migration.MIGRATIONS_REGISTRY))
67
68
69 class TestMigration(MigrationBase):
70@@ -113,7 +116,6 @@
71 def tearDown(self):
72 """tear down each test"""
73 super(TestMigration, self).tearDown()
74- migration.MIGRATIONS_REGISTRY = []
75 try:
76 del self.database._server[DCTRASH]
77 except ResourceNotFound:
78@@ -127,7 +129,6 @@
79 # just asserting something to check this code is run
80 # and get the right db as argument
81 self.assertEqual(self.dbname, database.db.name)
82-
83 migration.register(
84 migration_method=simple_migration, dbs=[self.dbname])
85 migration.run_needed_migrations(ctx=self.ctx)
86@@ -180,6 +181,7 @@
87 Record({
88 'key1_1': 'val1_1',
89 'record_type': 'test.com'}))
90+
91 migration.run_needed_migrations(ctx=self.ctx)
92 # Record no longer exists in database
93 self.assertIs(None, self.database.get_record(record_id))
94@@ -197,3 +199,37 @@
95 'private_application_annotations']
96 self.assertEqual(self.dbname, private['original_database_name'])
97 self.assertEqual(record_id, private['original_id'])
98+
99+ def test_migration_in_face_of_broken_records(self):
100+ """Test that the migration does not break when we have a
101+ 'record' without a record_type.
102+
103+ """
104+ # pylint: disable=E1101
105+ record_id = base_n(uuid4().int, 62)
106+ self.database.db[record_id] = {
107+ "results": [],
108+ "last_seq": 1973,
109+ "application_annotations": {
110+ "Ubuntu One": {
111+ "private_application_annotations": {
112+ "deleted": True}}}}
113+ undeleted_record_id1 = base_n(uuid4().int, 62)
114+ self.database.db[undeleted_record_id1] = {
115+ 'key1_1': 'val1_1',
116+ 'application_annotations': {
117+ 'Ubuntu One': {
118+ 'private_application_annotations': {
119+ 'deleted': False}}}}
120+ undeleted_record_id2 = base_n(uuid4().int, 62)
121+ self.database.db[undeleted_record_id2] = {
122+ 'key1_1': 'val1_1'}
123+ # pylint: enable=E1101
124+ migration.run_needed_migrations(ctx=self.ctx)
125+ # None of them are deleted, since they are not records
126+ self.assertIn(record_id, self.database.db)
127+ self.assertIn(undeleted_record_id1, self.database.db)
128+ self.assertIn(undeleted_record_id2, self.database.db)
129+ self.assertNotIn(record_id, self.trash.db)
130+ self.assertNotIn(undeleted_record_id1, self.trash.db)
131+ self.assertNotIn(undeleted_record_id2, self.trash.db)
132
133=== removed directory 'po'
134=== removed file 'po/POTFILES.in'
135--- po/POTFILES.in 2009-08-19 19:14:24 +0000
136+++ po/POTFILES.in 1970-01-01 00:00:00 +0000
137@@ -1,2 +0,0 @@
138-desktopcouch-pair.desktop.in
139-bin/desktopcouch-pair

Subscribers

People subscribed via source and target branches