Merge lp:~vds/desktopcouch/add_record_type_version_field_to_record into lp:desktopcouch

Proposed by Vincenzo Di Somma
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 185
Merged at revision: 185
Proposed branch: lp:~vds/desktopcouch/add_record_type_version_field_to_record
Merge into: lp:desktopcouch
Diff against target: 88 lines (+19/-10)
2 files modified
desktopcouch/records/record.py (+12/-10)
desktopcouch/records/tests/test_record.py (+7/-0)
To merge this branch: bzr merge lp:~vds/desktopcouch/add_record_type_version_field_to_record
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+39710@code.launchpad.net

Commit message

Add record type version.

Description of the change

Add record type version.

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote :

+1

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/record.py'
2--- desktopcouch/records/record.py 2010-07-02 15:32:25 +0000
3+++ desktopcouch/records/record.py 2010-10-31 16:15:57 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd.
6+# Copyright 2009-2010 Canonical Ltd.
7 #
8 # This file is part of desktopcouch.
9 #
10@@ -17,6 +17,7 @@
11 # Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
12 # Nicola Larosa <nicola.larosa@canonical.com>
13 # Mark G. Saye <mark.saye@canonical.com>
14+# Vincenzo Di Somma <vincenzo.di.somma@canonical.com>
15
16 """A dictionary based record representation."""
17
18@@ -85,15 +86,9 @@
19 return "Record type must be specified and should be a URL"
20
21
22-# XXX: the doc string for this class makes no sense at all.
23-
24 class Attachment(object):
25 """This represents the value of the attachment. The name is
26- stored as the key that points to this name, and the
27-
28- We have a new BLOB to attach. Attachment(file_object, str_mime_type)
29- We know the traits of a BLOB. Attachment()
30- """
31+ stored as the key that points to this name."""
32 def __init__(self, content=None, content_type=None):
33 super(Attachment, self).__init__()
34 if content is not None:
35@@ -352,7 +347,8 @@
36 class Record(RecordDict):
37 """An object that represents a Desktop CouchDB record."""
38
39- def __init__(self, data=None, record_type=None, record_id=None):
40+ def __init__(self, data=None, record_type=None,
41+ record_id=None, record_type_version=None):
42 if data is None:
43 data = {}
44 if record_type is None:
45@@ -360,7 +356,6 @@
46 record_type = data['record_type']
47 else:
48 raise NoRecordTypeSpecified
49-
50 super(Record, self).__init__(data)
51 self._data['record_type'] = record_type
52
53@@ -373,6 +368,8 @@
54 # _id already set. Verify that the explicit value agrees.
55 if self._data['_id'] != record_id:
56 raise ValueError("record_id doesn't match value in data.")
57+ if record_type_version:
58+ self._record_type_version = record_type_version
59
60 def __getitem__(self, key):
61 if is_internal(key):
62@@ -441,3 +438,8 @@
63 def record_revision(self):
64 """Get the record revision."""
65 return self._data.get('_rev', None) # Retreive only; comes from DB.
66+
67+ @property
68+ def record_type_version(self):
69+ """Get the record type version if it's there."""
70+ return getattr(self, '_record_type_version', None)
71
72=== modified file 'desktopcouch/records/tests/test_record.py'
73--- desktopcouch/records/tests/test_record.py 2010-02-10 16:09:49 +0000
74+++ desktopcouch/records/tests/test_record.py 2010-10-31 16:15:57 +0000
75@@ -308,6 +308,13 @@
76 self.assertRaises(ValueError,
77 Record, data, record_id=record_id, record_type="url")
78
79+ def test_record_type_version(self):
80+ data = {"_id":"recordid"}
81+ record1 = Record(data, record_type="url")
82+ self.assertIs(None, record1.record_type_version)
83+ record2 = Record(data, record_type="url", record_type_version=1)
84+ self.assertEqual(record2.record_type_version, 1)
85+
86
87 class TestRecordFactory(TestCase):
88 """Test Record/Mergeable List factories."""

Subscribers

People subscribed via source and target branches