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
=== added directory 'desktopcouch/contacts'
=== added file 'desktopcouch/contacts/__init__.py'
--- desktopcouch/contacts/__init__.py 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/__init__.py 2009-08-17 21:39:48 +0000
@@ -0,0 +1,20 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16#
17# Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
18# Nicola Larosa <nicola.larosa@canonical.com>
19
20"""UbuntuOne Contacts API"""
021
=== added file 'desktopcouch/contacts/record.py'
--- desktopcouch/contacts/record.py 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/record.py 2009-08-17 21:39:48 +0000
@@ -0,0 +1,34 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16#
17# Authors: Eric Casteleijn <eric.casteleijn@canonical.com>
18# Nicola Larosa <nicola.larosa@canonical.com>
19# Mark G. Saye <mark.saye@canonical.com>
20
21
22"""A dictionary based contact record representation."""
23
24from desktopcouch.records.record import Record
25
26CONTACT_RECORD_TYPE = 'http://api.ubuntuone.com/schema/contact/0.1'
27
28
29class Contact(Record):
30 """An Ubuntuone Contact Record."""
31
32 def __init__(self, data=None, record_id=None):
33 super(Contact, self).__init__(
34 record_id=record_id, data=data, record_type=CONTACT_RECORD_TYPE)
035
=== added file 'desktopcouch/contacts/schema.txt'
--- desktopcouch/contacts/schema.txt 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/schema.txt 2009-08-17 21:39:48 +0000
@@ -0,0 +1,50 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16
17Schema
18
19The proposed CouchDB contact schema is as follows:
20
21Core fields
22
23 * record_type 'http://api.ubuntuone.com/schema/contact/0.1'
24 * first_name (string)
25 * last_name (string)
26 * birth_date (string, "YYYY-MM-DD")
27 * addresses (MergeableList of "address" dictionaries)
28 o city (string)
29 o address1 (string)
30 o address2 (string)
31 o pobox (string)
32 o state (string)
33 o country (string)
34 o postalcode (string)
35 o description (string, e.g., "Home")
36 * email_addresses (MergeableList of "emailaddress" dictionaries)
37 o address (string),
38 o description (string)
39 * phone_numbers (MergeableList of "phone number" dictionaries)
40 o number (string)
41 o description (string)
42 * application_annotations Everything else, organized per application.
43
44Note: None of the core fields are mandatory, but applications should
45not add any other fields at the top level of the record. Any fields
46needed not defined here should be put under application_annotations in
47the namespace of the application there. So for Ubuntu One:
48
49 "application_annotations": {
50 "Ubuntu One": {<Ubuntu One specific fields here>}}
051
=== added directory 'desktopcouch/contacts/testing'
=== added file 'desktopcouch/contacts/testing/__init__.py'
--- desktopcouch/contacts/testing/__init__.py 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/testing/__init__.py 2009-08-17 21:39:48 +0000
@@ -0,0 +1,20 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16#
17# Authors: Stuart Langridge <stuart.langridge@canonical.com>
18# Nicola Larosa <nicola.larosa@canonical.com>
19
20"""Support code for tests"""
021
=== added file 'desktopcouch/contacts/testing/create.py'
--- desktopcouch/contacts/testing/create.py 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/testing/create.py 2009-08-17 21:39:48 +0000
@@ -0,0 +1,113 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16#
17# Authors: Stuart Langridge <stuart.langridge@canonical.com>
18# Nicola Larosa <nicola.larosa@canonical.com>
19
20"""Creating CouchDb-stored contacts for testing"""
21
22import random, string, uuid
23
24from couchdb import Server
25
26CONTACT_DOCTYPE = 'http://api.ubuntuone.com/schema/contact/0.1'
27COUCHDB_SYS_PORT = 5984
28
29FIRST_NAMES = ('Jack', 'Thomas', 'Oliver', 'Joshua', 'Harry', 'Charlie',
30 'Daniel', 'William', 'James', 'Alfie', 'Grace', 'Ruby', 'Olivia',
31 'Emily', 'Jessica', 'Sophie', 'Chloe', 'Lily', 'Ella', 'Amelia')
32LAST_NAMES = ('Dalglish', 'Grobbelaar', 'Lawrenson', 'Beglin', 'Nicol',
33 'Whelan', 'Hansen', 'Johnston', 'Rush', 'Molby', 'MacDonald', 'McMahon')
34CITIES = ('Scunthorpe', 'Birmingham', 'Cambridge', 'Durham', 'Bedford')
35COUNTRIES = ('England', 'Ireland', 'Scotland', 'Wales')
36
37def random_string(length=10):
38 """Return a string of random lowercase letters and of specified length"""
39 return ''.join(random.sample(string.lowercase, length))
40
41def random_postal_address():
42 """Return something that looks like a postal address"""
43 return '%s Street' % random.choice(LAST_NAMES)
44
45def random_email_address(first_name, last_name):
46 """Return something that looks like an email address"""
47 return '%s.%s@%s.com' % (first_name, last_name, random_string(3))
48
49def random_postal_code():
50 """Return something that looks like a postal code"""
51 return '%s12 3%s' % (random_string(2), random_string(2))
52
53def random_phone_number():
54 """Return something that looks like a phone number"""
55 return '+%s %s %s %s' % (random.randint(10, 99), random.randint(10, 99),
56 random.randint(1000, 9999), random.randint(1000, 9999))
57
58def random_birth_date():
59 """Return something that looks like a birth date"""
60 return '%04d-%02d-%02d' % (random.randint(1900, 2006),
61 random.randint(1, 12), random.randint(1, 28))
62
63def make_one_contact(maincount, doctype, app_annots):
64 """Make up one contact randomly"""
65 # Record schema
66 fielddict = {'record_type': doctype, 'record_type_version': '1.0'}
67 # Names
68 first_name = random.choice(FIRST_NAMES) + str(maincount)
69 last_name = random.choice(LAST_NAMES)
70 # Addresses
71 addresses = {}
72 for address_type in ('home', 'work', 'other'):
73 addresses[str(uuid.uuid4())] = {
74 'address1': random_postal_address(), 'address2': '',
75 'pobox': '', 'city': random.choice(CITIES),
76 'state': '', 'postalcode': random_postal_code(),
77 'country': random.choice(COUNTRIES), 'description': address_type}
78 # Email addresses
79 email_addresses = {}
80 for email_address_type in ('home', 'work', 'other'):
81 email_addresses[str(uuid.uuid4())] = {
82 'address': random_email_address(first_name, last_name),
83 'description': email_address_type}
84 # Phone numbers
85 phone_numbers = {}
86 for phone_number_type in ('home', 'work', 'other'):
87 phone_numbers[str(uuid.uuid4())] = {
88 'priority': 0, 'number': random_phone_number(),
89 'description': phone_number_type}
90 # Store data in fielddict
91 fielddict.update({'first_name': first_name, 'last_name': last_name,
92 'addresses': addresses, 'email_addresses': email_addresses,
93 'phone_numbers': phone_numbers, 'birth_date': random_birth_date()})
94 # Possibly add example application annotations
95 if app_annots:
96 fielddict['application_annotations'] = app_annots
97 return fielddict
98
99def create_many_contacts(
100 num_contacts=10, host='localhost', port=COUCHDB_SYS_PORT,
101 db_name='contacts', doctype=CONTACT_DOCTYPE, app_annots=None):
102 """Make many contacts and create their records"""
103 server_url = 'http://%s:%s/' % (host, port)
104 server = Server(server_url)
105 db = server[db_name] if db_name in server else server.create(db_name)
106 record_ids = []
107 for maincount in range(1, num_contacts + 1):
108 # Make the contact
109 fielddict = make_one_contact(maincount, doctype, app_annots)
110 # Store data in CouchDB
111 record_id = db.create(fielddict)
112 record_ids.append(record_id)
113 return record_ids
0114
=== added directory 'desktopcouch/contacts/tests'
=== added file 'desktopcouch/contacts/tests/__init__.py'
--- desktopcouch/contacts/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/tests/__init__.py 2009-08-17 21:39:48 +0000
@@ -0,0 +1,17 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16
17"Tests for Contacts API"
018
=== added file 'desktopcouch/contacts/tests/test_record.py'
--- desktopcouch/contacts/tests/test_record.py 1970-01-01 00:00:00 +0000
+++ desktopcouch/contacts/tests/test_record.py 2009-08-17 21:39:48 +0000
@@ -0,0 +1,31 @@
1# Copyright 2009 Canonical Ltd.
2#
3# This file is part of desktopcouch-contacts.
4#
5# desktopcouch is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 3
7# as published by the Free Software Foundation.
8#
9# desktopcouch is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
16#
17# Authors: Nicola Larosa <nicola.larosa@canonical.com>
18
19"""Tests for the ContactDocument class"""
20
21import testtools
22from desktopcouch.contacts.record import Contact, CONTACT_RECORD_TYPE
23
24class TestContactRecord(testtools.TestCase):
25 """Test the Contact Record object."""
26
27 def test_contact_record(self):
28 """Test that we get the correct record type."""
29 contact = Contact()
30 self.assertEqual(CONTACT_RECORD_TYPE, contact.record_type)
31
032
=== modified file 'setup.py'
--- setup.py 2009-08-09 17:37:35 +0000
+++ setup.py 2009-08-17 21:39:48 +0000
@@ -30,6 +30,6 @@
30 packages=find_packages(),30 packages=find_packages(),
31 data_files = [('/usr/lib/desktopcouch/', ['bin/desktopcouch-service',31 data_files = [('/usr/lib/desktopcouch/', ['bin/desktopcouch-service',
32 'bin/desktopcouch-stop']),32 'bin/desktopcouch-stop']),
33 ('/usr/share/doc/python-desktopcouch-records/api/', 33 ('/usr/share/doc/python-desktopcouch-records/api/',
34 ['desktopcouch/records/doc/records.txt'])],34 ['desktopcouch/records/doc/records.txt'])],
35)35)

Subscribers

People subscribed via source and target branches