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