annotate test/rest_common.py @ 5705:457fc482e6b1

Method PUT: ignore specification of protected properties which can not be set. Filtering them out of the payload list. This lets the result of a get using: class/id?@protected=true&@verbose=0 be used as input to a PUT operation without having to strip the protected properties. Note this does not raise an error if the PUT protected property is different from the value in the db. If the property is different but the etag/if-match passes, the user attempted to set the protected property and this should result in an error, but will not with this patch. Method DELETE class/id/attribute: raise error when trying to delete protected or required attribute/property. Raise UsageError when attribute doesn't exist. Method PATCH class/id: raise error when trying to replace/remove protected attribute/property raise error when trying to remove required attribute/property Catch KeyError at top level and turn into 400 error. If payload has an attribute/property that does not exist, raise UsageError which becomes a 400 error.
author John Rouillard <rouilj@ieee.org>
date Thu, 11 Apr 2019 20:54:39 -0400
parents 4aae822e2cb4
children dfca6136dd7b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
1 import unittest
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
2 import os
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
3 import shutil
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
4 import errno
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
5
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
6 from roundup.cgi.exceptions import *
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
7 from roundup.exceptions import *
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
8 from roundup import password, hyperdb
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
9 from roundup.rest import RestfulInstance, calculate_etag
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
10 from roundup.backends import list_backends
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
11 from roundup.cgi import client
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
12 from roundup.anypy.strings import b2s, s2b
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
13 import random
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
14
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
15 from .db_test_base import setupTracker
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
16
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
17 from .mocknull import MockNull
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
18
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
19 from io import BytesIO
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
20 import json
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
21
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
22 NEEDS_INSTANCE = 1
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
23
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
24
5601
fcbeff272828 Integrate REST tests into db framework
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5600
diff changeset
25 class TestCase():
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
26
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
27 backend = None
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
28 url_pfx = 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/'
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
29
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
30 def setUp(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
31 self.dirname = '_test_rest'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
32 # set up and open a tracker
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
33 self.instance = setupTracker(self.dirname, self.backend)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
34
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
35 # open the database
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
36 self.db = self.instance.open('admin')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
37
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
38 # Get user id (user4 maybe). Used later to get data from db.
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
39 self.joeid = self.db.user.create(
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
40 username='joe',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
41 password=password.Password('random'),
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
42 address='random@home.org',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
43 realname='Joe Random',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
44 roles='User'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
45 )
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
46
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
47 self.db.commit()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
48 self.db.close()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
49 self.db = self.instance.open('joe')
5604
ed02a1e0aa5d Fix actions
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5602
diff changeset
50 # Allow joe to retire
ed02a1e0aa5d Fix actions
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5602
diff changeset
51 p = self.db.security.addPermission(name='Retire', klass='issue')
ed02a1e0aa5d Fix actions
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5602
diff changeset
52 self.db.security.addPermissionToRole('User', p)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
53
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
54 self.db.tx_Source = 'web'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
55
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
56 self.db.issue.addprop(tx_Source=hyperdb.String())
5690
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
57 self.db.issue.addprop(anint=hyperdb.Integer())
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
58 self.db.issue.addprop(afloat=hyperdb.Number())
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
59 self.db.issue.addprop(abool=hyperdb.Boolean())
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
60 self.db.issue.addprop(requireme=hyperdb.String(required=True))
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
61 self.db.msg.addprop(tx_Source=hyperdb.String())
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
62
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
63 self.db.post_init()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
64
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
65 thisdir = os.path.dirname(__file__)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
66 vars = {}
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
67 with open(os.path.join(thisdir, "tx_Source_detector.py")) as f:
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
68 code = compile(f.read(), "tx_Source_detector.py", "exec")
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
69 exec(code, vars)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
70 vars['init'](self.db)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
71
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
72 env = {
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
73 'PATH_INFO': 'http://localhost/rounduptest/rest/',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
74 'HTTP_HOST': 'localhost',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
75 'TRACKER_NAME': 'rounduptest'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
76 }
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
77 self.dummy_client = client.Client(self.instance, MockNull(), env, [], None)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
78 self.dummy_client.request.headers.get = self.get_header
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
79 self.empty_form = cgi.FieldStorage()
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
80 self.terse_form = cgi.FieldStorage()
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
81 self.terse_form.list = [
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
82 cgi.MiniFieldStorage('@verbose', '0'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
83 ]
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
84
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
85 self.server = RestfulInstance(self.dummy_client, self.db)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
86
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
87 def tearDown(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
88 self.db.close()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
89 try:
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
90 shutil.rmtree(self.dirname)
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
91 except OSError as error:
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
92 if error.errno not in (errno.ENOENT, errno.ESRCH):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
93 raise
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
94
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
95 def get_header (self, header, not_found=None):
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
96 try:
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
97 return self.headers[header.lower()]
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
98 except (AttributeError, KeyError, TypeError):
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
99 return not_found
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
100
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
101 def testGet(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
102 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
103 Retrieve all three users
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
104 obtain data for 'joe'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
105 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
106 # Retrieve all three users.
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
107 results = self.server.get_collection('user', self.empty_form)
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
108 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
109 self.assertEqual(len(results['data']['collection']), 3)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
110 self.assertEqual(results['data']['@total_size'], 3)
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
111 print(self.dummy_client.additional_headers["X-Count-Total"])
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
112 self.assertEqual(
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
113 self.dummy_client.additional_headers["X-Count-Total"],
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
114 "3"
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
115 )
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
116
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
117 # Obtain data for 'joe'.
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
118 results = self.server.get_element('user', self.joeid, self.empty_form)
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
119 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
120 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
121 self.assertEqual(results['attributes']['username'], 'joe')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
122 self.assertEqual(results['attributes']['realname'], 'Joe Random')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
123
5678
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
124 # Obtain data for 'joe' via username lookup.
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
125 results = self.server.get_element('user', 'joe', self.empty_form)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
126 results = results['data']
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
127 self.assertEqual(self.dummy_client.response_code, 200)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
128 self.assertEqual(results['attributes']['username'], 'joe')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
129 self.assertEqual(results['attributes']['realname'], 'Joe Random')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
130
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
131 # Obtain data for 'joe' via username lookup (long form).
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
132 key = 'username=joe'
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
133 results = self.server.get_element('user', key, self.empty_form)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
134 results = results['data']
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
135 self.assertEqual(self.dummy_client.response_code, 200)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
136 self.assertEqual(results['attributes']['username'], 'joe')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
137 self.assertEqual(results['attributes']['realname'], 'Joe Random')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
138
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
139 # Obtain data for 'joe'.
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
140 results = self.server.get_attribute(
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
141 'user', self.joeid, 'username', self.empty_form
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
142 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
143 self.assertEqual(self.dummy_client.response_code, 200)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
144 self.assertEqual(results['data']['data'], 'joe')
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
145
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
146 def testOutputFormat(self):
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
147 """ test of @fields and @verbose implementation """
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
148
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
149 self.maxDiff = 4000
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
150 # create sample data
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
151 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
152 self.db.status.create(name='open')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
153 except ValueError:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
154 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
155 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
156 self.db.status.create(name='closed')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
157 except ValueError:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
158 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
159 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
160 self.db.priority.create(name='normal')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
161 except ValueError:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
162 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
163 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
164 self.db.priority.create(name='critical')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
165 except ValueError:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
166 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
167 self.db.issue.create(
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
168 title='foo1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
169 status=self.db.status.lookup('open'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
170 priority=self.db.priority.lookup('normal'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
171 nosy = [ "1", "2" ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
172 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
173 issue_open_norm = self.db.issue.create(
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
174 title='foo2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
175 status=self.db.status.lookup('open'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
176 priority=self.db.priority.lookup('normal'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
177 assignedto = "3"
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
178 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
179 issue_open_crit = self.db.issue.create(
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
180 title='foo5',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
181 status=self.db.status.lookup('open'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
182 priority=self.db.priority.lookup('critical')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
183 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
184 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/issue/'
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
185
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
186
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
187 # Check formating for issues status=open; @fields and verbose tests
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
188 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
189 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
190 cgi.MiniFieldStorage('status', 'open'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
191 cgi.MiniFieldStorage('@fields', 'nosy,status'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
192 cgi.MiniFieldStorage('@verbose', '2')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
193 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
194
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
195 expected={'data':
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
196 {'@total_size': 3,
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
197 'collection': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
198 {'status': {'id': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
199 'name': 'open',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
200 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
201 'id': '1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
202 'nosy': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
203 {'username': 'admin',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
204 'id': '1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
205 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/1'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
206 {'username': 'anonymous',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
207 'id': '2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
208 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2'}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
209 ],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
210 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
211 'title': 'foo1' },
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
212 {'status': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
213 'id': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
214 'name': 'open',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
215 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9' },
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
216 'id': '2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
217 'nosy': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
218 {'username': 'joe',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
219 'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
220 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3'}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
221 ],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
222 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
223 'title': 'foo2'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
224 {'status': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
225 'id': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
226 'name': 'open',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
227 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
228 'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
229 'nosy': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
230 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
231 'title': 'foo5'}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
232 ]}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
233
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
234 results = self.server.get_collection('issue', form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
235 self.assertDictEqual(expected, results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
236
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
237 # Check formating for issues status=open; @fields and verbose tests
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
238 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
239 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
240 cgi.MiniFieldStorage('status', 'open')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
241 # default cgi.MiniFieldStorage('@verbose', '1')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
242 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
243
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
244 expected={'data':
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
245 {'@total_size': 3,
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
246 'collection': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
247 {'id': '1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
248 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1',},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
249 { 'id': '2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
250
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
251 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/2'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
252 {'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
253 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3'} ]}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
254
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
255
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
256 results = self.server.get_collection('issue', form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
257 self.assertDictEqual(expected, results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
258
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
259 # Generate failure case, unknown field.
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
260 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
261 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
262 cgi.MiniFieldStorage('status', 'open'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
263 cgi.MiniFieldStorage('@fields', 'title,foo')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
264 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
265
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
266 expected={'error': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
267 'msg': UsageError("Failed to find property 'foo' "
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
268 "for class issue.",),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
269 'status': 400}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
270
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
271 results = self.server.get_collection('issue', form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
272 # I tried assertDictEqual but seems it can't handle
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
273 # the exception value of 'msg'. So I am using repr to check.
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
274 self.assertEqual(repr(sorted(expected['error'])),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
275 repr(sorted(results['error']))
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
276 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
277
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
278 # Check formating for issues status=open; @fields and verbose tests
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
279 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
280 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
281 cgi.MiniFieldStorage('status', 'open'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
282 cgi.MiniFieldStorage('@fields', 'nosy,status,assignedto'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
283 cgi.MiniFieldStorage('@verbose', '0')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
284 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
285
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
286 expected={'data': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
287 '@total_size': 3,
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
288 'collection': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
289 {'assignedto': None,
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
290 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
291 'status': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
292 'nosy': ['1', '2'],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
293 'id': '1'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
294 {'assignedto': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
295 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
296 'status': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
297 'nosy': ['3'],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
298 'id': '2'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
299 {'assignedto': None,
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
300 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
301 'status': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
302 'nosy': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
303 'id': '3'}]}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
304
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
305 results = self.server.get_collection('issue', form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
306 print(results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
307 self.assertDictEqual(expected, results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
308
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
309 # check users
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
310 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
311 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
312 cgi.MiniFieldStorage('@fields', 'username,queries,password'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
313 cgi.MiniFieldStorage('@verbose', '0')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
314 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
315 # note this is done as user joe, so we only get queries
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
316 # and password for joe.
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
317 expected = {'data': {'collection': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
318 {'id': '1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
319 'username': 'admin',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
320 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/1'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
321 {'id': '2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
322 'username': 'anonymous',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
323 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
324 {'password': '[password hidden scheme PBKDF2]',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
325 'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
326 'queries': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
327 'username': 'joe',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
328 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3'}],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
329 '@total_size': 3}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
330
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
331 results = self.server.get_collection('user', form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
332 self.assertDictEqual(expected, results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
333
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
334 ## Start testing get_element
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
335 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
336 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
337 cgi.MiniFieldStorage('@fields', 'queries,password'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
338 cgi.MiniFieldStorage('@verbose', '2')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
339 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
340 expected = {'data': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
341 'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
342 'type': 'user',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
343 '@etag': '',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
344 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
345 'attributes': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
346 'password': '[password hidden scheme PBKDF2]',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
347 'queries': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
348 'username': 'joe'
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
349 }
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
350 }}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
351
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
352 results = self.server.get_element('user', self.joeid, form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
353 results['data']['@etag'] = '' # etag depends on date, set to empty
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
354 self.assertDictEqual(expected,results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
355
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
356 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
357 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
358 cgi.MiniFieldStorage('@fields', 'status:priority'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
359 cgi.MiniFieldStorage('@verbose', '1')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
360 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
361 expected = {'data': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
362 'type': 'issue',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
363 'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
364 'attributes': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
365 'status': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
366 'id': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
367 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status/9'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
368 'priority': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
369 'id': '1',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
370 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/priority/1'}},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
371 '@etag': '',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
372 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3'}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
373
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
374 results = self.server.get_element('issue', "3", form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
375 results['data']['@etag'] = '' # etag depends on date, set to empty
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
376 self.assertDictEqual(expected,results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
377
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
378 form = cgi.FieldStorage()
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
379 form.list = [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
380 cgi.MiniFieldStorage('@fields', 'status,priority'),
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
381 cgi.MiniFieldStorage('@verbose', '0')
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
382 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
383 expected = {'data': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
384 'type': 'issue',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
385 'id': '3',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
386 'attributes': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
387 'status': '9',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
388 'priority': '1'},
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
389 '@etag': '',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
390 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/3'}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
391
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
392 results = self.server.get_element('issue', "3", form)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
393 results['data']['@etag'] = '' # etag depends on date, set to empty
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
394 self.assertDictEqual(expected,results)
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
395
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
396 def testFilter(self):
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
397 """
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
398 Retrieve all three users
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
399 obtain data for 'joe'
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
400 """
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
401 # create sample data
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
402 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
403 self.db.status.create(name='open')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
404 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
405 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
406 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
407 self.db.status.create(name='closed')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
408 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
409 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
410 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
411 self.db.priority.create(name='normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
412 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
413 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
414 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
415 self.db.priority.create(name='critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
416 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
417 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
418 self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
419 title='foo4',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
420 status=self.db.status.lookup('closed'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
421 priority=self.db.priority.lookup('critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
422 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
423 self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
424 title='foo1',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
425 status=self.db.status.lookup('open'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
426 priority=self.db.priority.lookup('normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
427 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
428 issue_open_norm = self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
429 title='foo2',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
430 status=self.db.status.lookup('open'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
431 priority=self.db.priority.lookup('normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
432 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
433 issue_closed_norm = self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
434 title='foo3',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
435 status=self.db.status.lookup('closed'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
436 priority=self.db.priority.lookup('normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
437 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
438 issue_closed_crit = self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
439 title='foo4',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
440 status=self.db.status.lookup('closed'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
441 priority=self.db.priority.lookup('critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
442 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
443 issue_open_crit = self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
444 title='foo5',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
445 status=self.db.status.lookup('open'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
446 priority=self.db.priority.lookup('critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
447 )
5623
1c4adab65faf use config file setting for creating tracker uri
John Rouillard <rouilj@ieee.org>
parents: 5604
diff changeset
448 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/issue/'
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
449
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
450 # Retrieve all issue status=open
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
451 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
452 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
453 cgi.MiniFieldStorage('status', 'open')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
454 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
455 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
456 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
457 self.assertIn(get_obj(base_path, issue_open_norm),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
458 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
459 self.assertIn(get_obj(base_path, issue_open_crit),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
460 results['data']['collection'])
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
461 self.assertNotIn(
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
462 get_obj(base_path, issue_closed_norm),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
463 results['data']['collection']
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
464 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
465
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
466 # Retrieve all issue status=closed and priority=critical
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
467 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
468 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
469 cgi.MiniFieldStorage('status', 'closed'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
470 cgi.MiniFieldStorage('priority', 'critical')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
471 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
472 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
473 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
474 self.assertIn(get_obj(base_path, issue_closed_crit),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
475 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
476 self.assertNotIn(get_obj(base_path, issue_open_crit),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
477 results['data']['collection'])
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
478 self.assertNotIn(
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
479 get_obj(base_path, issue_closed_norm),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
480 results['data']['collection']
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
481 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
482
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
483 # Retrieve all issue status=closed and priority=normal,critical
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
484 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
485 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
486 cgi.MiniFieldStorage('status', 'closed'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
487 cgi.MiniFieldStorage('priority', 'normal,critical')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
488 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
489 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
490 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
491 self.assertIn(get_obj(base_path, issue_closed_crit),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
492 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
493 self.assertIn(get_obj(base_path, issue_closed_norm),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
494 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
495 self.assertNotIn(get_obj(base_path, issue_open_crit),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
496 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
497 self.assertNotIn(get_obj(base_path, issue_open_norm),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
498 results['data']['collection'])
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
499
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
500 def testPagination(self):
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
501 """
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
502 Test pagination. page_size is required and is an integer
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
503 starting at 1. page_index is optional and is an integer
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
504 starting at 1. Verify that pagination links are present
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
505 if paging, @total_size and X-Count-Total header match
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
506 number of items.
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
507 """
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
508 # create sample data
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
509 for i in range(0, random.randint(8,15)):
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
510 self.db.issue.create(title='foo' + str(i))
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
511
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
512 # Retrieving all the issues
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
513 results = self.server.get_collection('issue', self.empty_form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
514 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
515 total_length = len(results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
516 # Verify no pagination links if paging not used
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
517 self.assertFalse('@links' in results['data'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
518 self.assertEqual(results['data']['@total_size'], total_length)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
519 self.assertEqual(
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
520 self.dummy_client.additional_headers["X-Count-Total"],
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
521 str(total_length)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
522 )
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
523
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
524
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
525 # Pagination will be 45% of the total result
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
526 # So 2 full pages and 1 partial page.
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
527 page_size = total_length * 45 // 100
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
528 page_one_expected = page_size
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
529 page_two_expected = page_size
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
530 page_three_expected = total_length - (2*page_one_expected)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
531 base_url="http://tracker.example/cgi-bin/roundup.cgi/" \
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
532 "bugs/rest/data/issue"
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
533
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
534 # Retrieve page 1
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
535 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
536 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
537 cgi.MiniFieldStorage('@page_size', page_size),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
538 cgi.MiniFieldStorage('@page_index', 1)
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
539 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
540 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
541 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
542 self.assertEqual(len(results['data']['collection']),
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
543 page_one_expected)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
544 self.assertTrue('@links' in results['data'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
545 self.assertTrue('self' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
546 self.assertTrue('next' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
547 self.assertFalse('prev' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
548 self.assertEqual(results['data']['@links']['self'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
549 "%s?@page_index=1&@page_size=%s"%(base_url,page_size))
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
550 self.assertEqual(results['data']['@links']['next'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
551 "%s?@page_index=2&@page_size=%s"%(base_url,page_size))
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
552
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
553 page_one_results = results # save this for later
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
554
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
555 # Retrieve page 2
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
556 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
557 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
558 cgi.MiniFieldStorage('@page_size', page_size),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
559 cgi.MiniFieldStorage('@page_index', 2)
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
560 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
561 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
562 self.assertEqual(self.dummy_client.response_code, 200)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
563 self.assertEqual(len(results['data']['collection']), page_two_expected)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
564 self.assertTrue('@links' in results['data'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
565 self.assertTrue('self' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
566 self.assertTrue('next' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
567 self.assertTrue('prev' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
568 self.assertEqual(results['data']['@links']['self'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
569 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=2&@page_size=%s"%page_size)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
570 self.assertEqual(results['data']['@links']['next'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
571 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=3&@page_size=%s"%page_size)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
572 self.assertEqual(results['data']['@links']['prev'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
573 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=1&@page_size=%s"%page_size)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
574 self.assertEqual(results['data']['@links']['self'][0]['rel'],
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
575 'self')
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
576 self.assertEqual(results['data']['@links']['next'][0]['rel'],
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
577 'next')
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
578 self.assertEqual(results['data']['@links']['prev'][0]['rel'],
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
579 'prev')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
580
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
581 # Retrieve page 3
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
582 form = cgi.FieldStorage()
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
583 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
584 cgi.MiniFieldStorage('@page_size', page_size),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
585 cgi.MiniFieldStorage('@page_index', 3)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
586 ]
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
587 results = self.server.get_collection('issue', form)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
588 self.assertEqual(self.dummy_client.response_code, 200)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
589 self.assertEqual(len(results['data']['collection']), page_three_expected)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
590 self.assertTrue('@links' in results['data'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
591 self.assertTrue('self' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
592 self.assertFalse('next' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
593 self.assertTrue('prev' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
594 self.assertEqual(results['data']['@links']['self'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
595 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=3&@page_size=%s"%page_size)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
596 self.assertEqual(results['data']['@links']['prev'][0]['uri'],
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
597 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue?@page_index=2&@page_size=%s"%page_size)
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
598
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
599 # Verify that page_index is optional
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
600 # Should start at page 1
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
601 form = cgi.FieldStorage()
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
602 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
603 cgi.MiniFieldStorage('@page_size', page_size),
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
604 ]
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
605 results = self.server.get_collection('issue', form)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
606 self.assertEqual(self.dummy_client.response_code, 200)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
607 self.assertEqual(len(results['data']['collection']), page_size)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
608 self.assertTrue('@links' in results['data'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
609 self.assertTrue('self' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
610 self.assertTrue('next' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
611 self.assertFalse('prev' in results['data']['@links'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
612 self.assertEqual(page_one_results, results)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
613
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
614 # FIXME add tests for out of range once we decide what response
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
615 # is needed to:
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
616 # page_size < 0
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
617 # page_index < 0
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
618
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
619 def notestEtagGeneration(self):
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
620 ''' Make sure etag generation is stable
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
621
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
622 FIXME need to mock somehow date.Date() when creating
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
623 the target to be mocked. The differing dates makes
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
624 this test impossible.
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
625 '''
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
626 newuser = self.db.user.create(
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
627 username='john',
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
628 password=password.Password('random1'),
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
629 address='random1@home.org',
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
630 realname='JohnRandom',
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
631 roles='User,Admin'
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
632 )
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
633
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
634 node = self.db.user.getnode(self.joeid)
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
635 etag = calculate_etag(node)
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
636 items = node.items(protected=True) # include every item
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
637 print(repr(items))
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
638 print(etag)
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
639 self.assertEqual(etag, "6adf97f83acf6453d4a6a4b1070f3754")
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
640
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
641 etag = calculate_etag(self.db.issue.getnode("1"))
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
642 print(etag)
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
643 self.assertEqual(etag, "6adf97f83acf6453d4a6a4b1070f3754")
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
644
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
645 def testEtagProcessing(self):
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
646 '''
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
647 Etags can come from two places:
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
648 If-Match http header
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
649 @etags value posted in the form
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
650
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
651 Both will be checked if availble. If either one
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
652 fails, the etag check will fail.
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
653
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
654 Run over header only, etag in form only, both,
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
655 each one broke and no etag. Use the put command
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
656 to trigger the etag checking code.
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
657 '''
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
658 for mode in ('header', 'etag', 'both',
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
659 'brokenheader', 'brokenetag', 'none'):
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
660 try:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
661 # clean up any old header
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
662 del(self.headers)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
663 except AttributeError:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
664 pass
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
665
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
666 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
667 etag = calculate_etag(self.db.user.getnode(self.joeid))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
668 form.list = [
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
669 cgi.MiniFieldStorage('data', 'Joe Doe Doe'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
670 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
671
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
672 if mode == 'header':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
673 print("Mode = %s"%mode)
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
674 self.headers = {'if-match': etag}
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
675 elif mode == 'etag':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
676 print("Mode = %s"%mode)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
677 form.list.append(cgi.MiniFieldStorage('@etag', etag))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
678 elif mode == 'both':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
679 print("Mode = %s"%mode)
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
680 self.headers = {'etag': etag}
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
681 form.list.append(cgi.MiniFieldStorage('@etag', etag))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
682 elif mode == 'brokenheader':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
683 print("Mode = %s"%mode)
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
684 self.headers = {'if-match': 'bad'}
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
685 form.list.append(cgi.MiniFieldStorage('@etag', etag))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
686 elif mode == 'brokenetag':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
687 print("Mode = %s"%mode)
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
688 self.headers = {'if-match': etag}
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
689 form.list.append(cgi.MiniFieldStorage('@etag', 'bad'))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
690 elif mode == 'none':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
691 print( "Mode = %s"%mode)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
692 else:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
693 self.fail("unknown mode found")
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
694
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
695 results = self.server.put_attribute(
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
696 'user', self.joeid, 'realname', form
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
697 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
698 if mode not in ('brokenheader', 'brokenetag', 'none'):
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
699 self.assertEqual(self.dummy_client.response_code, 200)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
700 else:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
701 self.assertEqual(self.dummy_client.response_code, 412)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
702
5690
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
703 def testDispatchPost(self):
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
704 """
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
705 run POST through rest dispatch(). This also tests
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
706 sending json payload through code as dispatch is the
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
707 code that changes json payload into something we can
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
708 process.
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
709 """
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
710
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
711 # TEST #0
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
712 # POST: issue make joe assignee and admin and demo as
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
713 # nosy
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
714 # simulate: /rest/data/issue
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
715 body=b'{ "title": "Joe Doe has problems", \
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
716 "nosy": [ "1", "3" ], \
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
717 "assignedto": "2", \
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
718 "abool": true, \
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
719 "afloat": 2.3, \
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
720 "anint": 567890 \
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
721 }'
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
722 env = { "CONTENT_TYPE": "application/json",
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
723 "CONTENT_LENGTH": len(body),
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
724 "REQUEST_METHOD": "POST"
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
725 }
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
726 headers={"accept": "application/json; version=1",
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
727 "content-type": env['CONTENT_TYPE'],
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
728 "content-length": env['CONTENT_LENGTH'],
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
729 }
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
730 self.headers=headers
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
731 # we need to generate a FieldStorage the looks like
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
732 # FieldStorage(None, None, 'string') rather than
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
733 # FieldStorage(None, None, [])
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
734 body_file=BytesIO(body) # FieldStorage needs a file
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
735 form = client.BinaryFieldStorage(body_file,
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
736 headers=headers,
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
737 environ=env)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
738 self.server.client.request.headers.get=self.get_header
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
739 results = self.server.dispatch(env["REQUEST_METHOD"],
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
740 "/rest/data/issue",
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
741 form)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
742
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
743 print(results)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
744 self.assertEqual(self.server.client.response_code, 201)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
745 json_dict = json.loads(b2s(results))
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
746 self.assertEqual(json_dict['data']['link'],
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
747 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1")
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
748 self.assertEqual(json_dict['data']['id'], "1")
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
749 results = self.server.dispatch('GET',
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
750 "/rest/data/issue/1", self.empty_form)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
751 print(results)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
752 json_dict = json.loads(b2s(results))
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
753 self.assertEqual(json_dict['data']['link'],
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
754 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1")
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
755 self.assertEqual(json_dict['data']['attributes']['abool'], True)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
756 self.assertEqual(json_dict['data']['attributes']['afloat'], 2.3)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
757 self.assertEqual(json_dict['data']['attributes']['anint'], 567890)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
758 self.assertEqual(len(json_dict['data']['attributes']['nosy']), 3)
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
759 self.assertEqual(json_dict['data']['attributes']\
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
760 ['assignedto']['link'],
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
761 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2")
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
762
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
763
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
764 def testDispatch(self):
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
765 """
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
766 run changes through rest dispatch(). This also tests
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
767 sending json payload through code as dispatch is the
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
768 code that changes json payload into something we can
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
769 process.
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
770 """
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
771 # TEST #1
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
772 # PUT: joe's 'realname' using json data.
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
773 # simulate: /rest/data/user/<id>/realname
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
774 # use etag in header
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
775 etag = calculate_etag(self.db.user.getnode(self.joeid))
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
776 body=b'{ "data": "Joe Doe 1" }'
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
777 env = { "CONTENT_TYPE": "application/json",
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
778 "CONTENT_LENGTH": len(body),
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
779 "REQUEST_METHOD": "PUT"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
780 }
5686
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
781 headers={"accept": "application/json; version=1",
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
782 "content-type": env['CONTENT_TYPE'],
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
783 "content-length": env['CONTENT_LENGTH'],
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
784 "if-match": etag
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
785 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
786 self.headers=headers
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
787 # we need to generate a FieldStorage the looks like
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
788 # FieldStorage(None, None, 'string') rather than
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
789 # FieldStorage(None, None, [])
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
790 body_file=BytesIO(body) # FieldStorage needs a file
5656
d26d2590cd8c Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents: 5655
diff changeset
791 form = client.BinaryFieldStorage(body_file,
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
792 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
793 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
794 self.server.client.request.headers.get=self.get_header
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
795 results = self.server.dispatch('PUT',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
796 "/rest/data/user/%s/realname"%self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
797 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
798
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
799 self.assertEqual(self.server.client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
800 results = self.server.get_element('user', self.joeid, self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
801 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
802 self.assertEqual(results['data']['attributes']['realname'],
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
803 'Joe Doe 1')
5686
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
804
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
805
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
806 # substitute the version with an unacceptable version
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
807 # and verify it returns 400 code.
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
808 self.headers["accept"] = "application/json; version=1.1"
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
809 body_file=BytesIO(body) # FieldStorage needs a file
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
810 form = client.BinaryFieldStorage(body_file,
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
811 headers=headers,
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
812 environ=env)
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
813 self.server.client.request.headers.get=self.get_header
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
814 results = self.server.dispatch('PUT',
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
815 "/rest/data/user/%s/realname"%self.joeid,
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
816 form)
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
817 self.assertEqual(self.server.client.response_code, 400)
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
818 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
819
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
820 # TEST #2
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
821 # Set joe's 'realname' using json data.
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
822 # simulate: /rest/data/user/<id>/realname
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
823 # use etag in payload
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
824 etag = calculate_etag(self.db.user.getnode(self.joeid))
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
825 etagb = etag.strip ('"')
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
826 body=s2b('{ "@etag": "\\"%s\\"", "data": "Joe Doe 2" }'%etagb)
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
827 env = { "CONTENT_TYPE": "application/json",
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
828 "CONTENT_LENGTH": len(body),
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
829 "REQUEST_METHOD": "PUT",
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
830 }
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
831 self.headers=None # have FieldStorage get len from env.
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
832 body_file=BytesIO(body) # FieldStorage needs a file
5656
d26d2590cd8c Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents: 5655
diff changeset
833 form = client.BinaryFieldStorage(body_file,
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
834 headers=None,
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
835 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
836 self.server.client.request.headers.get=self.get_header
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
837
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
838 headers={"accept": "application/json",
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
839 "content-type": env['CONTENT_TYPE'],
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
840 "if-match": etag
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
841 }
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
842 self.headers=headers # set for dispatch
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
843
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
844 results = self.server.dispatch('PUT',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
845 "/rest/data/user/%s/realname"%self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
846 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
847
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
848 self.assertEqual(self.server.client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
849 results = self.server.get_element('user', self.joeid, self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
850 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
851 self.assertEqual(results['data']['attributes']['realname'],
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
852 'Joe Doe 2')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
853 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
854
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
855 # TEST #3
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
856 # change Joe's realname via a normal web form
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
857 # This generates a FieldStorage that looks like:
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
858 # FieldStorage(None, None, [])
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
859 # use etag from header
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
860 #
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
861 # Also use GET on the uri via the dispatch to retrieve
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
862 # the results from the db.
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
863 etag = calculate_etag(self.db.user.getnode(self.joeid))
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
864 headers={"if-match": etag,
5686
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
865 "accept": "application/vnd.json.test-v1+json",
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
866 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
867 form = cgi.FieldStorage()
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
868 form.list = [
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
869 cgi.MiniFieldStorage('data', 'Joe Doe'),
5686
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
870 cgi.MiniFieldStorage('@apiver', '1'),
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
871 ]
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
872 self.headers = headers
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
873 self.server.client.request.headers.get = self.get_header
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
874 results = self.server.dispatch('PUT',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
875 "/rest/data/user/%s/realname"%self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
876 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
877 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
878 results = self.server.dispatch('GET',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
879 "/rest/data/user/%s/realname"%self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
880 self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
881 self.assertEqual(self.dummy_client.response_code, 200)
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
882 json_dict = json.loads(b2s(results))
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
883
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
884 self.assertEqual(json_dict['data']['data'], 'Joe Doe')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
885 self.assertEqual(json_dict['data']['link'],
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
886 "http://tracker.example/cgi-bin/"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
887 "roundup.cgi/bugs/rest/data/user/3/realname")
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
888 self.assertIn(json_dict['data']['type'], ("<class 'str'>",
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
889 "<type 'str'>"))
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
890 self.assertEqual(json_dict['data']["id"], "3")
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
891 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
892
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
893
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
894 # TEST #4
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
895 # PATCH: joe's email address with json
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
896 # save address so we can use it later
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
897 stored_results = self.server.get_element('user', self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
898 self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
899 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
900
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
901 etag = calculate_etag(self.db.user.getnode(self.joeid))
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
902 etagb = etag.strip ('"')
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
903 body=s2b('{ "address": "demo2@example.com", "@etag": "\\"%s\\""}'%etagb)
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
904 env = { "CONTENT_TYPE": "application/json",
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
905 "CONTENT_LENGTH": len(body),
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
906 "REQUEST_METHOD": "PATCH"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
907 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
908 headers={"accept": "application/json",
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
909 "content-type": env['CONTENT_TYPE'],
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
910 "content-length": len(body)
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
911 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
912 self.headers=headers
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
913 body_file=BytesIO(body) # FieldStorage needs a file
5656
d26d2590cd8c Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents: 5655
diff changeset
914 form = client.BinaryFieldStorage(body_file,
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
915 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
916 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
917 self.server.client.request.headers.get=self.get_header
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
918 results = self.server.dispatch('PATCH',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
919 "/rest/data/user/%s"%self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
920 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
921
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
922 self.assertEqual(self.server.client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
923 results = self.server.get_element('user', self.joeid, self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
924 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
925 self.assertEqual(results['data']['attributes']['address'],
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
926 'demo2@example.com')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
927
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
928 # and set it back reusing env and headers from last test
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
929 etag = calculate_etag(self.db.user.getnode(self.joeid))
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
930 etagb = etag.strip ('"')
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
931 body=s2b('{ "address": "%s", "@etag": "\\"%s\\""}'%(
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
932 stored_results['data']['attributes']['address'],
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
933 etagb))
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
934 # reuse env and headers from prior test.
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
935 body_file=BytesIO(body) # FieldStorage needs a file
5656
d26d2590cd8c Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents: 5655
diff changeset
936 form = client.BinaryFieldStorage(body_file,
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
937 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
938 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
939 self.server.client.request.headers.get=self.get_header
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
940 results = self.server.dispatch('PATCH',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
941 "/rest/data/user/%s"%self.joeid,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
942 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
943
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
944 self.assertEqual(self.server.client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
945 results = self.server.get_element('user', self.joeid, self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
946 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
947 self.assertEqual(results['data']['attributes']['address'],
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
948 'random@home.org')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
949 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
950
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
951 # TEST #5
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
952 # POST: create new issue
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
953 # no etag needed
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
954 # FIXME at some point we probably want to implement
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
955 # Post Once Only, so we need to add a Post Once Exactly
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
956 # test and a resubmit as well.
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
957 etag = "not needed"
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
958 body=b'{ "title": "foo bar", "priority": "critical" }'
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
959 env = { "CONTENT_TYPE": "application/json",
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
960 "CONTENT_LENGTH": len(body),
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
961 "REQUEST_METHOD": "POST"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
962 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
963 headers={"accept": "application/json",
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
964 "content-type": env['CONTENT_TYPE'],
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
965 "content-length": len(body)
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
966 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
967 self.headers=headers
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
968 body_file=BytesIO(body) # FieldStorage needs a file
5656
d26d2590cd8c Implement different workaround for https://bugs.python.org/issue27777
John Rouillard <rouilj@ieee.org>
parents: 5655
diff changeset
969 form = client.BinaryFieldStorage(body_file,
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
970 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
971 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
972 self.server.client.request.headers.get=self.get_header
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
973 results = self.server.dispatch('POST',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
974 "/rest/data/issue",
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
975 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
976
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
977 self.assertEqual(self.server.client.response_code, 201)
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
978 json_dict = json.loads(b2s(results))
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
979 issue_id=json_dict['data']['id']
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
980 results = self.server.get_element('issue',
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
981 str(issue_id), # must be a string not unicode
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
982 self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
983 self.assertEqual(self.dummy_client.response_code, 200)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
984 self.assertEqual(results['data']['attributes']['title'],
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
985 'foo bar')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
986 del(self.headers)
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
987
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
988 def testPutElement(self):
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
989 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
990 Change joe's 'realname'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
991 Check if we can't change admin's detail
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
992 """
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
993 # fail to change Joe's realname via attribute uri
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
994 # no etag
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
995 form = cgi.FieldStorage()
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
996 form.list = [
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
997 cgi.MiniFieldStorage('data', 'Joe Doe Doe')
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
998 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
999 results = self.server.put_attribute(
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1000 'user', self.joeid, 'realname', form
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1001 )
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1002 self.assertEqual(self.dummy_client.response_code, 412)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1003 results = self.server.get_attribute(
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1004 'user', self.joeid, 'realname', self.empty_form
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1005 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1006 self.assertEqual(self.dummy_client.response_code, 200)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1007 self.assertEqual(results['data']['data'], 'Joe Random')
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1008
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1009 # change Joe's realname via attribute uri - etag in header
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1010 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1011 etag = calculate_etag(self.db.user.getnode(self.joeid))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1012 form.list = [
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1013 cgi.MiniFieldStorage('data', 'Joe Doe Doe'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1014 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1015
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1016 self.headers = {'if-match': etag } # use etag in header
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1017 results = self.server.put_attribute(
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1018 'user', self.joeid, 'realname', form
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1019 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1020 self.assertEqual(self.dummy_client.response_code, 200)
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1021 results = self.server.get_attribute(
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1022 'user', self.joeid, 'realname', self.empty_form
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1023 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1024 self.assertEqual(self.dummy_client.response_code, 200)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1025 self.assertEqual(results['data']['data'], 'Joe Doe Doe')
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1026 del(self.headers)
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1027
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1028 # Reset joe's 'realname'. etag in body
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1029 # Also try to set protected items. The protected items should
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1030 # be ignored on put_element to make it easy to get the item
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1031 # with all fields, change one field and put the result without
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1032 # having to filter out protected items.
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1033 form = cgi.FieldStorage()
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1034 etag = calculate_etag(self.db.user.getnode(self.joeid))
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1035 form.list = [
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1036 cgi.MiniFieldStorage('creator', '3'),
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1037 cgi.MiniFieldStorage('realname', 'Joe Doe'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1038 cgi.MiniFieldStorage('@etag', etag)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1039 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1040 results = self.server.put_element('user', self.joeid, form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1041 self.assertEqual(self.dummy_client.response_code, 200)
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1042 results = self.server.get_element('user', self.joeid, self.empty_form)
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1043 self.assertEqual(self.dummy_client.response_code, 200)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1044 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe')
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1045
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1046 # We are joe, so check we can't change admin's details
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1047 results = self.server.put_element('user', '1', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1048 self.assertEqual(self.dummy_client.response_code, 403)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1049 self.assertEqual(results['error']['status'], 403)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1050
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1051 # Try to reset joe's 'realname' and add a broken prop.
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1052 # This should result in no change to the name and
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1053 # a 400 UsageError stating prop does not exist.
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1054 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1055 etag = calculate_etag(self.db.user.getnode(self.joeid))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1056 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1057 cgi.MiniFieldStorage('JustKidding', '3'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1058 cgi.MiniFieldStorage('realname', 'Joe Doe'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1059 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1060 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1061 results = self.server.put_element('user', self.joeid, form)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1062 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1063 'msg': UsageError('Property JustKidding not '
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1064 'found in class user')}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1065 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1066 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1067 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1068 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1069 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1070 results = self.server.get_element('user', self.joeid, self.empty_form)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1071 self.assertEqual(self.dummy_client.response_code, 200)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1072 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe')
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1073
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1074 def testPutAttribute(self):
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1075 # put protected property
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1076 # make sure we don't have permission issues
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1077 self.db.setCurrentUser('admin')
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1078 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1079 etag = calculate_etag(self.db.user.getnode(self.joeid))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1080 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1081 cgi.MiniFieldStorage('data', '3'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1082 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1083 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1084 results = self.server.put_attribute(
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1085 'user', self.joeid, 'creator', form
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1086 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1087 expected= {'error': {'status': 400, 'msg':
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1088 UsageError('\'"creator", "actor", "creation" and '
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1089 '"activity" are reserved\'')}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1090 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1091 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1092 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1093 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1094 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1095 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1096
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1097 # put invalid property
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1098 # make sure we don't have permission issues
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1099 self.db.setCurrentUser('admin')
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1100 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1101 etag = calculate_etag(self.db.user.getnode(self.joeid))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1102 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1103 cgi.MiniFieldStorage('data', '3'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1104 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1105 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1106 results = self.server.put_attribute(
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1107 'user', self.joeid, 'youMustBeKiddingMe', form
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1108 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1109 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1110 'msg': UsageError("'youMustBeKiddingMe' "
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1111 "is not a property of user")}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1112 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1113 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1114 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1115 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1116 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1117 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1118
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1119 def testPost(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1120 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1121 Post a new issue with title: foo
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1122 Verify the information of the created issue
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1123 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1124 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1125 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1126 cgi.MiniFieldStorage('title', 'foo')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1127 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1128 results = self.server.post_collection('issue', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1129 self.assertEqual(self.dummy_client.response_code, 201)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1130 issueid = results['data']['id']
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1131 results = self.server.get_element('issue', issueid, self.empty_form)
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1132 self.assertEqual(self.dummy_client.response_code, 200)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1133 self.assertEqual(results['data']['attributes']['title'], 'foo')
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1134 self.assertEqual(self.db.issue.get(issueid, "tx_Source"), 'web')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1135
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1136 def testPostFile(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1137 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1138 Post a new file with content: hello\r\nthere
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1139 Verify the information of the created file
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1140 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1141 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1142 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1143 cgi.MiniFieldStorage('content', 'hello\r\nthere')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1144 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1145 results = self.server.post_collection('file', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1146 self.assertEqual(self.dummy_client.response_code, 201)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1147 fileid = results['data']['id']
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1148 results = self.server.get_element('file', fileid, self.empty_form)
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1149 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1150 self.assertEqual(self.dummy_client.response_code, 200)
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1151 self.assertEqual(results['attributes']['content'],
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1152 {'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/file1/'})
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1153
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1154 # File content is only shown with verbose=3
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1155 form = cgi.FieldStorage()
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1156 form.list = [
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1157 cgi.MiniFieldStorage('@verbose', '3')
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1158 ]
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1159 results = self.server.get_element('file', fileid, form)
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1160 results = results['data']
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1161 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1162 self.assertEqual(results['attributes']['content'], 'hello\r\nthere')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1163
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1164 def testAuthDeniedPut(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1165 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1166 Test unauthorized PUT request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1167 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1168 # Wrong permissions (caught by roundup security module).
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1169 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1170 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1171 cgi.MiniFieldStorage('realname', 'someone')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1172 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1173 results = self.server.put_element('user', '1', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1174 self.assertEqual(self.dummy_client.response_code, 403)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1175 self.assertEqual(results['error']['status'], 403)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1176
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1177 def testAuthDeniedPost(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1178 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1179 Test unauthorized POST request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1180 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1181 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1182 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1183 cgi.MiniFieldStorage('username', 'blah')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1184 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1185 results = self.server.post_collection('user', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1186 self.assertEqual(self.dummy_client.response_code, 403)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1187 self.assertEqual(results['error']['status'], 403)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1188
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1189 def testAuthAllowedPut(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1190 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1191 Test authorized PUT request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1192 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1193 self.db.setCurrentUser('admin')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1194 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1195 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1196 cgi.MiniFieldStorage('realname', 'someone')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1197 ]
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1198 try:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1199 self.server.put_element('user', '2', form)
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
1200 except Unauthorised as err:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1201 self.fail('raised %s' % err)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1202 finally:
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1203 self.db.setCurrentUser('joe')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1204
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1205 def testAuthAllowedPost(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1206 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1207 Test authorized POST request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1208 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1209 self.db.setCurrentUser('admin')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1210 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1211 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1212 cgi.MiniFieldStorage('username', 'blah')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1213 ]
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1214 try:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1215 self.server.post_collection('user', form)
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
1216 except Unauthorised as err:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1217 self.fail('raised %s' % err)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1218 finally:
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1219 self.db.setCurrentUser('joe')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1220
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1221 def testDeleteAttributeUri(self):
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1222 """
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1223 Test Delete an attribute
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1224 """
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1225 self.maxDiff = 4000
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1226 # create a new issue with userid 1 in the nosy list
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1227 issue_id = self.db.issue.create(title='foo', nosy=['1'])
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1228
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1229 # No etag, so this should return 412 - Precondition Failed
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1230 # With no changes
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1231 results = self.server.delete_attribute(
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1232 'issue', issue_id, 'nosy', self.empty_form
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1233 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1234 self.assertEqual(self.dummy_client.response_code, 412)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1235 results = self.server.get_element('issue', issue_id, self.empty_form)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1236 results = results['data']
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1237 self.assertEqual(self.dummy_client.response_code, 200)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1238 self.assertEqual(len(results['attributes']['nosy']), 1)
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1239 self.assertListEqual(results['attributes']['nosy'],
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1240 [{'id': '1', 'link': self.url_pfx + 'user/1'}])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1241
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1242 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1243 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1244 form.list.append(cgi.MiniFieldStorage('@etag', etag))
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1245 # remove the title and nosy
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1246 results = self.server.delete_attribute(
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1247 'issue', issue_id, 'title', form
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1248 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1249 self.assertEqual(self.dummy_client.response_code, 200)
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1250
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1251 del(form.list[-1])
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1252 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1253 form.list.append(cgi.MiniFieldStorage('@etag', etag))
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1254 results = self.server.delete_attribute(
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1255 'issue', issue_id, 'nosy', form
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1256 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1257 self.assertEqual(self.dummy_client.response_code, 200)
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1258
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1259 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1260 results = self.server.get_element('issue', issue_id, self.terse_form)
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1261 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1262 self.assertEqual(self.dummy_client.response_code, 200)
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1263 self.assertEqual(len(results['attributes']['nosy']), 0)
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1264 self.assertListEqual(results['attributes']['nosy'], [])
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1265 self.assertEqual(results['attributes']['title'], None)
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1266
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1267 # delete protected property
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1268 etag = calculate_etag(self.db.issue.getnode(issue_id))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1269 form.list.append(cgi.MiniFieldStorage('@etag', etag))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1270 results = self.server.delete_attribute(
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1271 'issue', issue_id, 'creator', form
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1272 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1273 expected= {'error': {
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1274 'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1275 'msg': UsageError("Attribute 'creator' can not be updated for class issue.")
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1276 }}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1277
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1278 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1279 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1280 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1281 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1282 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1283
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1284 # delete required property
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1285 etag = calculate_etag(self.db.issue.getnode(issue_id))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1286 form.list.append(cgi.MiniFieldStorage('@etag', etag))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1287 results = self.server.delete_attribute(
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1288 'issue', issue_id, 'requireme', form
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1289 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1290 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1291 'msg': UsageError("Attribute 'requireme' is "
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1292 "required by class issue and can not be deleted.")}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1293 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1294 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1295 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1296 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1297 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1298 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1299
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1300 def testPatchAdd(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1301 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1302 Test Patch op 'Add'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1303 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1304 # create a new issue with userid 1 in the nosy list
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1305 issue_id = self.db.issue.create(title='foo', nosy=['1'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1306
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1307 # fail to add userid 2 to the nosy list
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1308 # no etag
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1309 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1310 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1311 cgi.MiniFieldStorage('@op', 'add'),
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1312 cgi.MiniFieldStorage('nosy', '2')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1313 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1314 results = self.server.patch_element('issue', issue_id, form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1315 self.assertEqual(self.dummy_client.response_code, 412)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1316
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1317 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1318 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1319 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1320 cgi.MiniFieldStorage('@op', 'add'),
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1321 cgi.MiniFieldStorage('nosy', '2'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1322 cgi.MiniFieldStorage('@etag', etag)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1323 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1324 results = self.server.patch_element('issue', issue_id, form)
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1325 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1326
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1327 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1328 results = self.server.get_element('issue', issue_id, self.terse_form)
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1329 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1330 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1331 self.assertEqual(len(results['attributes']['nosy']), 2)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1332 self.assertListEqual(results['attributes']['nosy'], ['1', '2'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1333
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1334 def testPatchReplace(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1335 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1336 Test Patch op 'Replace'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1337 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1338 # create a new issue with userid 1 in the nosy list and status = 1
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1339 issue_id = self.db.issue.create(title='foo', nosy=['1'], status='1')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1340
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1341 # fail to replace userid 2 to the nosy list and status = 3
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1342 # no etag.
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1343 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1344 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1345 cgi.MiniFieldStorage('@op', 'replace'),
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1346 cgi.MiniFieldStorage('nosy', '2'),
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1347 cgi.MiniFieldStorage('status', '3')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1348 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1349 results = self.server.patch_element('issue', issue_id, form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1350 self.assertEqual(self.dummy_client.response_code, 412)
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1351 results = self.server.get_element('issue', issue_id, self.terse_form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1352 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1353 self.assertEqual(self.dummy_client.response_code, 200)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1354 self.assertEqual(results['attributes']['status'], '1')
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1355 self.assertEqual(len(results['attributes']['nosy']), 1)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1356 self.assertListEqual(results['attributes']['nosy'], ['1'])
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1357
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1358 # replace userid 2 to the nosy list and status = 3
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1359 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1360 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1361 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1362 cgi.MiniFieldStorage('@op', 'replace'),
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1363 cgi.MiniFieldStorage('nosy', '2'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1364 cgi.MiniFieldStorage('status', '3'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1365 cgi.MiniFieldStorage('@etag', etag)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1366 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1367 results = self.server.patch_element('issue', issue_id, form)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1368 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1369 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1370 results = self.server.get_element('issue', issue_id, self.terse_form)
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1371 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1372 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1373 self.assertEqual(results['attributes']['status'], '3')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1374 self.assertEqual(len(results['attributes']['nosy']), 1)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1375 self.assertListEqual(results['attributes']['nosy'], ['2'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1376
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1377 # try to set a protected prop. It should fail.
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1378 etag = calculate_etag(self.db.issue.getnode(issue_id))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1379 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1380 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1381 cgi.MiniFieldStorage('@op', 'replace'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1382 cgi.MiniFieldStorage('creator', '2'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1383 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1384 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1385 results = self.server.patch_element('issue', issue_id, form)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1386 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1387 'msg': KeyError('"creator", "actor", "creation" and "activity" are reserved',)}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1388 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1389 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1390 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1391 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1392 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1393 self.assertEqual(str(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1394 str(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1395 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1396
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1397 def testPatchRemoveAll(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1398 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1399 Test Patch Action 'Remove'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1400 """
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1401 # create a new issue with userid 1 and 2 in the nosy list
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1402 issue_id = self.db.issue.create(title='foo', nosy=['1', '2'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1403
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1404 # fail to remove the nosy list and the title
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1405 # no etag
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1406 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1407 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1408 cgi.MiniFieldStorage('@op', 'remove'),
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1409 cgi.MiniFieldStorage('nosy', ''),
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1410 cgi.MiniFieldStorage('title', '')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1411 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1412 results = self.server.patch_element('issue', issue_id, form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1413 self.assertEqual(self.dummy_client.response_code, 412)
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1414 results = self.server.get_element('issue', issue_id, self.terse_form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1415 results = results['data']
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1416 self.assertEqual(self.dummy_client.response_code, 200)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1417 self.assertEqual(results['attributes']['title'], 'foo')
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1418 self.assertEqual(len(results['attributes']['nosy']), 2)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1419 self.assertEqual(results['attributes']['nosy'], ['1', '2'])
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1420
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1421 # remove the nosy list and the title
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1422 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1423 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1424 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1425 cgi.MiniFieldStorage('@op', 'remove'),
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1426 cgi.MiniFieldStorage('nosy', ''),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1427 cgi.MiniFieldStorage('title', ''),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1428 cgi.MiniFieldStorage('@etag', etag)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1429 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1430 results = self.server.patch_element('issue', issue_id, form)
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1431 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1432
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1433 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1434 results = self.server.get_element('issue', issue_id, self.terse_form)
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1435 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1436 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1437 self.assertEqual(results['attributes']['title'], None)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1438 self.assertEqual(len(results['attributes']['nosy']), 0)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1439 self.assertEqual(results['attributes']['nosy'], [])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1440
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1441 # try to remove a protected prop. It should fail.
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1442 etag = calculate_etag(self.db.issue.getnode(issue_id))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1443 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1444 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1445 cgi.MiniFieldStorage('@op', 'remove'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1446 cgi.MiniFieldStorage('creator', '2'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1447 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1448 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1449 results = self.server.patch_element('issue', issue_id, form)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1450 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1451 'msg': KeyError('"creator", "actor", "creation" and "activity" are reserved',)}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1452 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1453 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1454 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1455 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1456 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1457 self.assertEqual(str(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1458 str(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1459 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1460
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1461 # try to remove a required prop. it should fail
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1462 etag = calculate_etag(self.db.issue.getnode(issue_id))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1463 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1464 cgi.MiniFieldStorage('@op', 'remove'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1465 cgi.MiniFieldStorage('requireme', ''),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1466 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1467 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1468 results = self.server.patch_element('issue', issue_id, form)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1469 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1470 'msg': UsageError("Attribute 'requireme' is required by class issue and can not be removed.")
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1471 }}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1472 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1473 self.assertEqual(results['error']['status'],
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1474 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1475 self.assertEqual(type(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1476 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1477 self.assertEqual(str(results['error']['msg']),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1478 str(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1479 self.assertEqual(self.dummy_client.response_code, 400)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1480
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1481 def testPatchAction(self):
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1482 """
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1483 Test Patch Action 'Action'
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1484 """
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1485 # create a new issue with userid 1 and 2 in the nosy list
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1486 issue_id = self.db.issue.create(title='foo')
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1487
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1488 # fail to execute action retire
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1489 # no etag
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1490 form = cgi.FieldStorage()
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1491 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1492 cgi.MiniFieldStorage('@op', 'action'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1493 cgi.MiniFieldStorage('@action_name', 'retire')
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1494 ]
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1495 results = self.server.patch_element('issue', issue_id, form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1496 self.assertEqual(self.dummy_client.response_code, 412)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1497 self.assertFalse(self.db.issue.is_retired(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1498
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1499 # execute action retire
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1500 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1501 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1502 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1503 cgi.MiniFieldStorage('@op', 'action'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1504 cgi.MiniFieldStorage('@action_name', 'retire'),
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1505 cgi.MiniFieldStorage('@etag', etag)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1506 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1507 results = self.server.patch_element('issue', issue_id, form)
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1508 self.assertEqual(self.dummy_client.response_code, 200)
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1509
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1510 # verify the result
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1511 self.assertTrue(self.db.issue.is_retired(issue_id))
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
1512
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1513 def testPatchRemove(self):
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1514 """
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1515 Test Patch Action 'Remove' only some element from a list
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1516 """
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1517 # create a new issue with userid 1, 2, 3 in the nosy list
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1518 issue_id = self.db.issue.create(title='foo', nosy=['1', '2', '3'])
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1519
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1520 # fail to remove the nosy list and the title
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1521 # no etag
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1522 form = cgi.FieldStorage()
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1523 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1524 cgi.MiniFieldStorage('@op', 'remove'),
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1525 cgi.MiniFieldStorage('nosy', '1, 2'),
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1526 ]
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1527 results = self.server.patch_element('issue', issue_id, form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1528 self.assertEqual(self.dummy_client.response_code, 412)
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1529 results = self.server.get_element('issue', issue_id, self.terse_form)
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1530 results = results['data']
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1531 self.assertEqual(self.dummy_client.response_code, 200)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1532 self.assertEqual(len(results['attributes']['nosy']), 3)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1533 self.assertEqual(results['attributes']['nosy'], ['1', '2', '3'])
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1534
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1535 # remove the nosy list and the title
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1536 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1537 etag = calculate_etag(self.db.issue.getnode(issue_id))
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1538 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1539 cgi.MiniFieldStorage('@op', 'remove'),
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1540 cgi.MiniFieldStorage('nosy', '1, 2'),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1541 cgi.MiniFieldStorage('@etag', etag)
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1542 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1543 results = self.server.patch_element('issue', issue_id, form)
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1544 self.assertEqual(self.dummy_client.response_code, 200)
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1545
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1546 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
1547 results = self.server.get_element('issue', issue_id, self.terse_form)
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1548 results = results['data']
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1549 self.assertEqual(self.dummy_client.response_code, 200)
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1550 self.assertEqual(len(results['attributes']['nosy']), 1)
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1551 self.assertEqual(results['attributes']['nosy'], ['3'])
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
1552
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
1553
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
1554 def get_obj(path, id):
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
1555 return {
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
1556 'id': id,
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
1557 'link': path + id
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
1558 }
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
1559
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1560 if __name__ == '__main__':
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1561 runner = unittest.TextTestRunner()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1562 unittest.main(testRunner=runner)

Roundup Issue Tracker: http://roundup-tracker.org/