Merge lp:~cjohnston/ubuntu-ci-services-itself/ts-people into lp:ubuntu-ci-services-itself

Proposed by Chris Johnston
Status: Merged
Approved by: Chris Johnston
Approved revision: 20
Merged at revision: 18
Proposed branch: lp:~cjohnston/ubuntu-ci-services-itself/ts-people
Merge into: lp:ubuntu-ci-services-itself
Prerequisite: lp:~cjohnston/ubuntu-ci-services-itself/ticket-system
Diff against target: 289 lines (+217/-2)
9 files modified
ticket_system/people/__init__.py (+15/-0)
ticket_system/people/admin.py (+26/-0)
ticket_system/people/api.py (+30/-0)
ticket_system/people/migrations/0001_initial.py (+36/-0)
ticket_system/people/models.py (+29/-0)
ticket_system/people/tests.py (+72/-0)
ticket_system/setup.py (+4/-0)
ticket_system/ticket_system/settings.py (+0/-2)
ticket_system/ticket_system/urls.py (+5/-0)
To merge this branch: bzr merge lp:~cjohnston/ubuntu-ci-services-itself/ts-people
Reviewer Review Type Date Requested Status
Andy Doan (community) Approve
Chris Johnston (community) Needs Resubmitting
Review via email: mp+198297@code.launchpad.net

Commit message

Add people app to ticket-system with read api

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

157 + email = models.EmailField(max_length=200)

Can you document why that's a shorter length than the name field?

Since this is a "get-only" api, should we add a unit-test to confirm that or will this become a read-write very soon?

Revision history for this message
Chris Johnston (cjohnston) wrote :

It will become read-write soon.

review: Needs Resubmitting
Revision history for this message
Andy Doan (doanac) wrote :

LGTM

review: Approve
Revision history for this message
Chris Johnston (cjohnston) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'ticket_system/people'
2=== added file 'ticket_system/people/__init__.py'
3--- ticket_system/people/__init__.py 1970-01-01 00:00:00 +0000
4+++ ticket_system/people/__init__.py 2013-12-09 18:58:11 +0000
5@@ -0,0 +1,15 @@
6+# Houston
7+# Ubuntu Continuous Integration Engine
8+# Copyright 2013 Canonical Ltd.
9+
10+# This program is free software: you can redistribute it and/or modify it
11+# under the terms of the GNU Affero General Public License version 3, as
12+# published by the Free Software Foundation.
13+
14+# This program is distributed in the hope that it will be useful, but
15+# WITHOUT ANY WARRANTY; without even the implied warranties of
16+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17+# PURPOSE. See the GNU Affero General Public License for more details.
18+
19+# You should have received a copy of the GNU Affero General Public License
20+# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22=== added file 'ticket_system/people/admin.py'
23--- ticket_system/people/admin.py 1970-01-01 00:00:00 +0000
24+++ ticket_system/people/admin.py 2013-12-09 18:58:11 +0000
25@@ -0,0 +1,26 @@
26+# Houston
27+# Ubuntu Continuous Integration Engine
28+# Copyright 2013 Canonical Ltd.
29+
30+# This program is free software: you can redistribute it and/or modify it
31+# under the terms of the GNU Affero General Public License version 3, as
32+# published by the Free Software Foundation.
33+
34+# This program is distributed in the hope that it will be useful, but
35+# WITHOUT ANY WARRANTY; without even the implied warranties of
36+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
37+# PURPOSE. See the GNU Affero General Public License for more details.
38+
39+# You should have received a copy of the GNU Affero General Public License
40+# along with this program. If not, see <http://www.gnu.org/licenses/>.
41+
42+from django.contrib import admin
43+from people.models import Person
44+
45+
46+class PersonAdmin(admin.ModelAdmin):
47+ list_filter = ['is_team']
48+ search_fields = ['name', 'email']
49+ list_display = ('name', 'email', 'is_team')
50+
51+admin.site.register(Person, PersonAdmin)
52
53=== added file 'ticket_system/people/api.py'
54--- ticket_system/people/api.py 1970-01-01 00:00:00 +0000
55+++ ticket_system/people/api.py 2013-12-09 18:58:11 +0000
56@@ -0,0 +1,30 @@
57+# Houston
58+# Ubuntu Continuous Integration Engine
59+# Copyright 2013 Canonical Ltd.
60+
61+# This program is free software: you can redistribute it and/or modify it
62+# under the terms of the GNU Affero General Public License version 3, as
63+# published by the Free Software Foundation.
64+
65+# This program is distributed in the hope that it will be useful, but
66+# WITHOUT ANY WARRANTY; without even the implied warranties of
67+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
68+# PURPOSE. See the GNU Affero General Public License for more details.
69+
70+# You should have received a copy of the GNU Affero General Public License
71+# along with this program. If not, see <http://www.gnu.org/licenses/>.
72+
73+from tastypie.resources import ModelResource
74+from tastypie.constants import ALL
75+from people.models import Person
76+
77+
78+class PersonResource(ModelResource):
79+ class Meta:
80+ queryset = Person.objects.all()
81+ allowed_methods = ['get']
82+ filtering = {
83+ "name": ('exact', 'startswith'),
84+ "email": ('exact', 'startswith'),
85+ "is_team": ALL,
86+ }
87
88=== added directory 'ticket_system/people/migrations'
89=== added file 'ticket_system/people/migrations/0001_initial.py'
90--- ticket_system/people/migrations/0001_initial.py 1970-01-01 00:00:00 +0000
91+++ ticket_system/people/migrations/0001_initial.py 2013-12-09 18:58:11 +0000
92@@ -0,0 +1,36 @@
93+# -*- coding: utf-8 -*-
94+import datetime
95+from south.db import db
96+from south.v2 import SchemaMigration
97+from django.db import models
98+
99+
100+class Migration(SchemaMigration):
101+
102+ def forwards(self, orm):
103+ # Adding model 'Person'
104+ db.create_table('person', (
105+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
106+ ('name', self.gf('django.db.models.fields.CharField')(max_length=4096)),
107+ ('email', self.gf('django.db.models.fields.EmailField')(max_length=4096)),
108+ ('is_team', self.gf('django.db.models.fields.BooleanField')(default=False)),
109+ ))
110+ db.send_create_signal(u'people', ['Person'])
111+
112+
113+ def backwards(self, orm):
114+ # Deleting model 'Person'
115+ db.delete_table('person')
116+
117+
118+ models = {
119+ u'people.person': {
120+ 'Meta': {'object_name': 'Person', 'db_table': "'person'"},
121+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '4096'}),
122+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
123+ 'is_team': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
124+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '4096'})
125+ }
126+ }
127+
128+ complete_apps = ['people']
129\ No newline at end of file
130
131=== added file 'ticket_system/people/migrations/__init__.py'
132=== added file 'ticket_system/people/models.py'
133--- ticket_system/people/models.py 1970-01-01 00:00:00 +0000
134+++ ticket_system/people/models.py 2013-12-09 18:58:11 +0000
135@@ -0,0 +1,29 @@
136+# Houston
137+# Ubuntu Continuous Integration Engine
138+# Copyright 2013 Canonical Ltd.
139+
140+# This program is free software: you can redistribute it and/or modify it
141+# under the terms of the GNU Affero General Public License version 3, as
142+# published by the Free Software Foundation.
143+
144+# This program is distributed in the hope that it will be useful, but
145+# WITHOUT ANY WARRANTY; without even the implied warranties of
146+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
147+# PURPOSE. See the GNU Affero General Public License for more details.
148+
149+# You should have received a copy of the GNU Affero General Public License
150+# along with this program. If not, see <http://www.gnu.org/licenses/>.
151+
152+from django.db import models
153+
154+
155+class Person(models.Model):
156+ class Meta:
157+ db_table = 'person'
158+
159+ name = models.CharField(max_length=4096)
160+ email = models.EmailField(max_length=4096)
161+ is_team = models.BooleanField(default=False)
162+
163+ def __unicode__(self):
164+ return self.name
165
166=== added file 'ticket_system/people/tests.py'
167--- ticket_system/people/tests.py 1970-01-01 00:00:00 +0000
168+++ ticket_system/people/tests.py 2013-12-09 18:58:11 +0000
169@@ -0,0 +1,72 @@
170+# Houston
171+# Ubuntu Continuous Integration Engine
172+# Copyright 2013 Canonical Ltd.
173+
174+# This program is free software: you can redistribute it and/or modify it
175+# under the terms of the GNU Affero General Public License version 3, as
176+# published by the Free Software Foundation.
177+
178+# This program is distributed in the hope that it will be useful, but
179+# WITHOUT ANY WARRANTY; without even the implied warranties of
180+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
181+# PURPOSE. See the GNU Affero General Public License for more details.
182+
183+# You should have received a copy of the GNU Affero General Public License
184+# along with this program. If not, see <http://www.gnu.org/licenses/>.
185+
186+from django.test import TestCase
187+from tastypie.test import ResourceTestCase
188+from people.models import Person
189+
190+
191+def create_person(name="Chris Johnston",
192+ email="chris.johnston@canonical.com", is_team=False):
193+ person = Person()
194+ person.name = name
195+ person.email = email
196+ person.is_team = is_team
197+ person.save()
198+ return person
199+
200+
201+class PersonModelTest(TestCase):
202+
203+ def test_creating_a_person(self):
204+ person = create_person()
205+ people_in_database = Person.objects.all()
206+ self.assertEquals(len(people_in_database), 1)
207+ only_person_in_database = people_in_database[0]
208+ self.assertEquals(only_person_in_database, person)
209+
210+ self.assertEquals(only_person_in_database.name, "Chris Johnston")
211+ self.assertEquals(only_person_in_database.email,
212+ "chris.johnston@canonical.com")
213+
214+
215+class PersonResourceTest(ResourceTestCase):
216+
217+ def setUp(self):
218+ super(PersonResourceTest, self).setUp()
219+ create_person()
220+ self.person_1 = Person.objects.get(name='Chris Johnston')
221+ self.detail_url = '/api/v1/person/{0}/'.format(self.person_1.pk)
222+
223+ def test_get_person_list_json(self):
224+ resp = self.api_client.get('/api/v1/person/', format='json')
225+ self.assertValidJSONResponse(resp)
226+ self.assertEqual(len(self.deserialize(resp)['objects']), 1)
227+ self.assertEqual(self.deserialize(resp)['objects'][0], {
228+ u'email': u'chris.johnston@canonical.com',
229+ u'id': self.person_1.pk,
230+ u'is_team': False,
231+ u'name': u'Chris Johnston',
232+ u'resource_uri': u'/api/v1/person/{0}/'.format(self.person_1.pk)
233+ })
234+
235+ def test_get_person_detail_json(self):
236+ resp = self.api_client.get(self.detail_url)
237+ self.assertValidJSONResponse(resp)
238+
239+ self.assertKeys(self.deserialize(resp),
240+ ['email', 'id', 'is_team', 'name', 'resource_uri'])
241+ self.assertEqual(self.deserialize(resp)['name'], 'Chris Johnston')
242
243=== modified file 'ticket_system/setup.py'
244--- ticket_system/setup.py 2013-12-09 18:58:11 +0000
245+++ ticket_system/setup.py 2013-12-09 18:58:11 +0000
246@@ -14,6 +14,10 @@
247 # You should have received a copy of the GNU Affero General Public License
248 # along with this program. If not, see <http://www.gnu.org/licenses/>.
249
250+
251+# TODO make this probe from changelog or bzr
252+__version__ = '0.1'
253+
254 import os
255 import sys
256
257
258=== modified file 'ticket_system/ticket_system/settings.py'
259--- ticket_system/ticket_system/settings.py 2013-12-09 18:58:11 +0000
260+++ ticket_system/ticket_system/settings.py 2013-12-09 18:58:11 +0000
261@@ -140,8 +140,6 @@
262
263 LOCAL_APPS = (
264 'people',
265- 'project',
266- 'ticket',
267 )
268
269 INSTALLED_APPS = LOCAL_APPS + INSTALLED_APPS
270
271=== modified file 'ticket_system/ticket_system/urls.py'
272--- ticket_system/ticket_system/urls.py 2013-12-09 18:58:11 +0000
273+++ ticket_system/ticket_system/urls.py 2013-12-09 18:58:11 +0000
274@@ -15,10 +15,15 @@
275
276 from django.conf.urls import patterns, include, url
277 from django.contrib import admin
278+from tastypie.api import Api
279+from people.api import PersonResource
280
281 admin.autodiscover()
282+v1_api = Api(api_name='v1')
283+v1_api.register(PersonResource())
284
285 urlpatterns = patterns(
286 '',
287+ (r'^api/', include(v1_api.urls)),
288 url(r'^admin/', include(admin.site.urls)),
289 )

Subscribers

People subscribed via source and target branches