]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/tests/person.py
d94809619d73ad5e18bf87fe5aa21d04bce519a5
[patchwork] / apps / patchwork / tests / person.py
1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2013 Jeremy Kerr <jk@ozlabs.org>
3 #
4 # This file is part of the Patchwork package.
5 #
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 import unittest
21 from django.test import TestCase
22 from django.test.client import Client
23 from patchwork.models import EmailConfirmation, Person, Bundle
24 import json
25
26 class SubmitterCompletionTest(TestCase):
27     def setUp(self):
28         self.people = [
29             Person(name = "Test Name", email = "test1@example.com"),
30             Person(email = "test2@example.com"),
31         ]
32         map(lambda p: p.save(), self.people)
33
34     def testNameComplete(self):
35         response = self.client.get('/submitter/', {'q': 'name'})
36         self.assertEquals(response.status_code, 200)
37         data = json.loads(response.content)
38         self.assertEquals(len(data), 1)
39         self.assertEquals(data[0]['fields']['name'], 'Test Name')
40
41     def testEmailComplete(self):
42         response = self.client.get('/submitter/', {'q': 'test2'})
43         self.assertEquals(response.status_code, 200)
44         data = json.loads(response.content)
45         self.assertEquals(len(data), 1)
46         self.assertEquals(data[0]['fields']['email'], 'test2@example.com')
47
48     def testCompleteLimit(self):
49         for i in range(3,10):
50             person = Person(email = 'test%d@example.com' % i)
51             person.save()
52         response = self.client.get('/submitter/', {'q': 'test', 'l': 5})
53         self.assertEquals(response.status_code, 200)
54         data = json.loads(response.content)
55         self.assertEquals(len(data), 5)