Merge lp:~statik/desktopcouch/add-contacts into lp:desktopcouch

Proposed by Elliot Murphy
Status: Merged
Approved by: Elliot Murphy
Approved revision: 36
Merged at revision: not available
Proposed branch: lp:~statik/desktopcouch/add-contacts
Merge into: lp:desktopcouch
Diff against target: None lines
To merge this branch: bzr merge lp:~statik/desktopcouch/add-contacts
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Review via email: mp+10280@code.launchpad.net

Commit message

Adding the desktopcouch.contacts module.

To post a comment you must log in.
Revision history for this message
Elliot Murphy (statik) wrote :

Add the contacts module.

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

Looks good, the tests are run and pass with trial desktopcouch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'desktopcouch/contacts'
2=== added file 'desktopcouch/contacts/__init__.py'
3--- desktopcouch/contacts/__init__.py 1970-01-01 00:00:00 +0000
4+++ desktopcouch/contacts/__init__.py 2009-08-17 21:39:48 +0000
5@@ -0,0 +1,20 @@
6+# Copyright 2009 Canonical Ltd.
7+#
8+# This file is part of desktopcouch-contacts.
9+#
10+# desktopcouch is free software: you can redistribute it and/or modify
11+# it under the terms of the GNU Lesser General Public License version 3
12+# as published by the Free Software Foundation.
13+#
14+# desktopcouch is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU Lesser General Public License for more details.
18+#
19+# You should have received a copy of the GNU Lesser General Public License
20+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
21+#
22+# Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
23+# Nicola Larosa <nicola.larosa@canonical.com>
24+
25+"""UbuntuOne Contacts API"""
26
27=== added file 'desktopcouch/contacts/record.py'
28--- desktopcouch/contacts/record.py 1970-01-01 00:00:00 +0000
29+++ desktopcouch/contacts/record.py 2009-08-17 21:39:48 +0000
30@@ -0,0 +1,34 @@
31+# Copyright 2009 Canonical Ltd.
32+#
33+# This file is part of desktopcouch-contacts.
34+#
35+# desktopcouch is free software: you can redistribute it and/or modify
36+# it under the terms of the GNU Lesser General Public License version 3
37+# as published by the Free Software Foundation.
38+#
39+# desktopcouch is distributed in the hope that it will be useful,
40+# but WITHOUT ANY WARRANTY; without even the implied warranty of
41+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42+# GNU Lesser General Public License for more details.
43+#
44+# You should have received a copy of the GNU Lesser General Public License
45+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
46+#
47+# Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
48+# Nicola Larosa <nicola.larosa@canonical.com>
49+# Mark G. Saye <mark.saye@canonical.com>
50+
51+
52+"""A dictionary based contact record representation."""
53+
54+from desktopcouch.records.record import Record
55+
56+CONTACT_RECORD_TYPE = 'http://api.ubuntuone.com/schema/contact/0.1'
57+
58+
59+class Contact(Record):
60+ """An Ubuntuone Contact Record."""
61+
62+ def __init__(self, data=None, record_id=None):
63+ super(Contact, self).__init__(
64+ record_id=record_id, data=data, record_type=CONTACT_RECORD_TYPE)
65
66=== added file 'desktopcouch/contacts/schema.txt'
67--- desktopcouch/contacts/schema.txt 1970-01-01 00:00:00 +0000
68+++ desktopcouch/contacts/schema.txt 2009-08-17 21:39:48 +0000
69@@ -0,0 +1,50 @@
70+# Copyright 2009 Canonical Ltd.
71+#
72+# This file is part of desktopcouch-contacts.
73+#
74+# desktopcouch is free software: you can redistribute it and/or modify
75+# it under the terms of the GNU Lesser General Public License version 3
76+# as published by the Free Software Foundation.
77+#
78+# desktopcouch is distributed in the hope that it will be useful,
79+# but WITHOUT ANY WARRANTY; without even the implied warranty of
80+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81+# GNU Lesser General Public License for more details.
82+#
83+# You should have received a copy of the GNU Lesser General Public License
84+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
85+
86+Schema
87+
88+The proposed CouchDB contact schema is as follows:
89+
90+Core fields
91+
92+ * record_type 'http://api.ubuntuone.com/schema/contact/0.1'
93+ * first_name (string)
94+ * last_name (string)
95+ * birth_date (string, "YYYY-MM-DD")
96+ * addresses (MergeableList of "address" dictionaries)
97+ o city (string)
98+ o address1 (string)
99+ o address2 (string)
100+ o pobox (string)
101+ o state (string)
102+ o country (string)
103+ o postalcode (string)
104+ o description (string, e.g., "Home")
105+ * email_addresses (MergeableList of "emailaddress" dictionaries)
106+ o address (string),
107+ o description (string)
108+ * phone_numbers (MergeableList of "phone number" dictionaries)
109+ o number (string)
110+ o description (string)
111+ * application_annotations Everything else, organized per application.
112+
113+Note: None of the core fields are mandatory, but applications should
114+not add any other fields at the top level of the record. Any fields
115+needed not defined here should be put under application_annotations in
116+the namespace of the application there. So for Ubuntu One:
117+
118+ "application_annotations": {
119+ "Ubuntu One": {<Ubuntu One specific fields here>}}
120
121=== added directory 'desktopcouch/contacts/testing'
122=== added file 'desktopcouch/contacts/testing/__init__.py'
123--- desktopcouch/contacts/testing/__init__.py 1970-01-01 00:00:00 +0000
124+++ desktopcouch/contacts/testing/__init__.py 2009-08-17 21:39:48 +0000
125@@ -0,0 +1,20 @@
126+# Copyright 2009 Canonical Ltd.
127+#
128+# This file is part of desktopcouch-contacts.
129+#
130+# desktopcouch is free software: you can redistribute it and/or modify
131+# it under the terms of the GNU Lesser General Public License version 3
132+# as published by the Free Software Foundation.
133+#
134+# desktopcouch is distributed in the hope that it will be useful,
135+# but WITHOUT ANY WARRANTY; without even the implied warranty of
136+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137+# GNU Lesser General Public License for more details.
138+#
139+# You should have received a copy of the GNU Lesser General Public License
140+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
141+#
142+# Authors: Stuart Langridge <stuart.langridge@canonical.com>
143+# Nicola Larosa <nicola.larosa@canonical.com>
144+
145+"""Support code for tests"""
146
147=== added file 'desktopcouch/contacts/testing/create.py'
148--- desktopcouch/contacts/testing/create.py 1970-01-01 00:00:00 +0000
149+++ desktopcouch/contacts/testing/create.py 2009-08-17 21:39:48 +0000
150@@ -0,0 +1,113 @@
151+# Copyright 2009 Canonical Ltd.
152+#
153+# This file is part of desktopcouch-contacts.
154+#
155+# desktopcouch is free software: you can redistribute it and/or modify
156+# it under the terms of the GNU Lesser General Public License version 3
157+# as published by the Free Software Foundation.
158+#
159+# desktopcouch is distributed in the hope that it will be useful,
160+# but WITHOUT ANY WARRANTY; without even the implied warranty of
161+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
162+# GNU Lesser General Public License for more details.
163+#
164+# You should have received a copy of the GNU Lesser General Public License
165+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
166+#
167+# Authors: Stuart Langridge <stuart.langridge@canonical.com>
168+# Nicola Larosa <nicola.larosa@canonical.com>
169+
170+"""Creating CouchDb-stored contacts for testing"""
171+
172+import random, string, uuid
173+
174+from couchdb import Server
175+
176+CONTACT_DOCTYPE = 'http://api.ubuntuone.com/schema/contact/0.1'
177+COUCHDB_SYS_PORT = 5984
178+
179+FIRST_NAMES = ('Jack', 'Thomas', 'Oliver', 'Joshua', 'Harry', 'Charlie',
180+ 'Daniel', 'William', 'James', 'Alfie', 'Grace', 'Ruby', 'Olivia',
181+ 'Emily', 'Jessica', 'Sophie', 'Chloe', 'Lily', 'Ella', 'Amelia')
182+LAST_NAMES = ('Dalglish', 'Grobbelaar', 'Lawrenson', 'Beglin', 'Nicol',
183+ 'Whelan', 'Hansen', 'Johnston', 'Rush', 'Molby', 'MacDonald', 'McMahon')
184+CITIES = ('Scunthorpe', 'Birmingham', 'Cambridge', 'Durham', 'Bedford')
185+COUNTRIES = ('England', 'Ireland', 'Scotland', 'Wales')
186+
187+def random_string(length=10):
188+ """Return a string of random lowercase letters and of specified length"""
189+ return ''.join(random.sample(string.lowercase, length))
190+
191+def random_postal_address():
192+ """Return something that looks like a postal address"""
193+ return '%s Street' % random.choice(LAST_NAMES)
194+
195+def random_email_address(first_name, last_name):
196+ """Return something that looks like an email address"""
197+ return '%s.%s@%s.com' % (first_name, last_name, random_string(3))
198+
199+def random_postal_code():
200+ """Return something that looks like a postal code"""
201+ return '%s12 3%s' % (random_string(2), random_string(2))
202+
203+def random_phone_number():
204+ """Return something that looks like a phone number"""
205+ return '+%s %s %s %s' % (random.randint(10, 99), random.randint(10, 99),
206+ random.randint(1000, 9999), random.randint(1000, 9999))
207+
208+def random_birth_date():
209+ """Return something that looks like a birth date"""
210+ return '%04d-%02d-%02d' % (random.randint(1900, 2006),
211+ random.randint(1, 12), random.randint(1, 28))
212+
213+def make_one_contact(maincount, doctype, app_annots):
214+ """Make up one contact randomly"""
215+ # Record schema
216+ fielddict = {'record_type': doctype, 'record_type_version': '1.0'}
217+ # Names
218+ first_name = random.choice(FIRST_NAMES) + str(maincount)
219+ last_name = random.choice(LAST_NAMES)
220+ # Addresses
221+ addresses = {}
222+ for address_type in ('home', 'work', 'other'):
223+ addresses[str(uuid.uuid4())] = {
224+ 'address1': random_postal_address(), 'address2': '',
225+ 'pobox': '', 'city': random.choice(CITIES),
226+ 'state': '', 'postalcode': random_postal_code(),
227+ 'country': random.choice(COUNTRIES), 'description': address_type}
228+ # Email addresses
229+ email_addresses = {}
230+ for email_address_type in ('home', 'work', 'other'):
231+ email_addresses[str(uuid.uuid4())] = {
232+ 'address': random_email_address(first_name, last_name),
233+ 'description': email_address_type}
234+ # Phone numbers
235+ phone_numbers = {}
236+ for phone_number_type in ('home', 'work', 'other'):
237+ phone_numbers[str(uuid.uuid4())] = {
238+ 'priority': 0, 'number': random_phone_number(),
239+ 'description': phone_number_type}
240+ # Store data in fielddict
241+ fielddict.update({'first_name': first_name, 'last_name': last_name,
242+ 'addresses': addresses, 'email_addresses': email_addresses,
243+ 'phone_numbers': phone_numbers, 'birth_date': random_birth_date()})
244+ # Possibly add example application annotations
245+ if app_annots:
246+ fielddict['application_annotations'] = app_annots
247+ return fielddict
248+
249+def create_many_contacts(
250+ num_contacts=10, host='localhost', port=COUCHDB_SYS_PORT,
251+ db_name='contacts', doctype=CONTACT_DOCTYPE, app_annots=None):
252+ """Make many contacts and create their records"""
253+ server_url = 'http://%s:%s/' % (host, port)
254+ server = Server(server_url)
255+ db = server[db_name] if db_name in server else server.create(db_name)
256+ record_ids = []
257+ for maincount in range(1, num_contacts + 1):
258+ # Make the contact
259+ fielddict = make_one_contact(maincount, doctype, app_annots)
260+ # Store data in CouchDB
261+ record_id = db.create(fielddict)
262+ record_ids.append(record_id)
263+ return record_ids
264
265=== added directory 'desktopcouch/contacts/tests'
266=== added file 'desktopcouch/contacts/tests/__init__.py'
267--- desktopcouch/contacts/tests/__init__.py 1970-01-01 00:00:00 +0000
268+++ desktopcouch/contacts/tests/__init__.py 2009-08-17 21:39:48 +0000
269@@ -0,0 +1,17 @@
270+# Copyright 2009 Canonical Ltd.
271+#
272+# This file is part of desktopcouch-contacts.
273+#
274+# desktopcouch is free software: you can redistribute it and/or modify
275+# it under the terms of the GNU Lesser General Public License version 3
276+# as published by the Free Software Foundation.
277+#
278+# desktopcouch is distributed in the hope that it will be useful,
279+# but WITHOUT ANY WARRANTY; without even the implied warranty of
280+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
281+# GNU Lesser General Public License for more details.
282+#
283+# You should have received a copy of the GNU Lesser General Public License
284+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
285+
286+"Tests for Contacts API"
287
288=== added file 'desktopcouch/contacts/tests/test_record.py'
289--- desktopcouch/contacts/tests/test_record.py 1970-01-01 00:00:00 +0000
290+++ desktopcouch/contacts/tests/test_record.py 2009-08-17 21:39:48 +0000
291@@ -0,0 +1,31 @@
292+# Copyright 2009 Canonical Ltd.
293+#
294+# This file is part of desktopcouch-contacts.
295+#
296+# desktopcouch is free software: you can redistribute it and/or modify
297+# it under the terms of the GNU Lesser General Public License version 3
298+# as published by the Free Software Foundation.
299+#
300+# desktopcouch is distributed in the hope that it will be useful,
301+# but WITHOUT ANY WARRANTY; without even the implied warranty of
302+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
303+# GNU Lesser General Public License for more details.
304+#
305+# You should have received a copy of the GNU Lesser General Public License
306+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
307+#
308+# Authors: Nicola Larosa <nicola.larosa@canonical.com>
309+
310+"""Tests for the ContactDocument class"""
311+
312+import testtools
313+from desktopcouch.contacts.record import Contact, CONTACT_RECORD_TYPE
314+
315+class TestContactRecord(testtools.TestCase):
316+ """Test the Contact Record object."""
317+
318+ def test_contact_record(self):
319+ """Test that we get the correct record type."""
320+ contact = Contact()
321+ self.assertEqual(CONTACT_RECORD_TYPE, contact.record_type)
322+
323
324=== modified file 'setup.py'
325--- setup.py 2009-08-09 17:37:35 +0000
326+++ setup.py 2009-08-17 21:39:48 +0000
327@@ -30,6 +30,6 @@
328 packages=find_packages(),
329 data_files = [('/usr/lib/desktopcouch/', ['bin/desktopcouch-service',
330 'bin/desktopcouch-stop']),
331- ('/usr/share/doc/python-desktopcouch-records/api/',
332+ ('/usr/share/doc/python-desktopcouch-records/api/',
333 ['desktopcouch/records/doc/records.txt'])],
334 )

Subscribers

People subscribed via source and target branches