annotate test/rest_common.py @ 5842:9c6617857032

Support use of duplicate rest filters keys. So URL's like: issues?title=foo&title=bar will find titles with the words foo and bar but not just foo and not just bar. Url like: issues?status=open,resolved&status=closed will find any issue with open, closed or resolved status. Original code would only use the last title or status filter erasing the earlier one.
author John Rouillard <rouilj@ieee.org>
date Wed, 10 Jul 2019 20:49:41 -0400
parents bcb894bc9740
children 04deafac71ab
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
5801
ddb553d5618c Add import of cgi since import cgi was removed from exceptions
John Rouillard <rouilj@ieee.org>
parents: 5747
diff changeset
5 import cgi
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
6
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
7 from time import sleep
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
8 from datetime import datetime
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
9
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
10 from roundup.cgi.exceptions import *
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
11 from roundup.hyperdb import HyperdbValueError
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
12 from roundup.exceptions import *
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
13 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
14 from roundup.rest import RestfulInstance, calculate_etag
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
15 from roundup.backends import list_backends
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
16 from roundup.cgi import client
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
17 from roundup.anypy.strings import b2s, s2b
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
18 import random
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
19
5733
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
20 from roundup.backends.sessions_dbm import OneTimeKeys
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
21 from roundup.anypy.dbm_ import anydbm, whichdb
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
22
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
23 from .db_test_base import setupTracker
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
24
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
25 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
26
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
27 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
28 import json
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
29
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
30 NEEDS_INSTANCE = 1
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
31
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
32
5601
fcbeff272828 Integrate REST tests into db framework
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5600
diff changeset
33 class TestCase():
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 backend = None
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
36 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
37
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
38 def setUp(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
39 self.dirname = '_test_rest'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
40 # set up and open a tracker
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
41 self.instance = setupTracker(self.dirname, self.backend)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
42
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
43 # open the database
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
44 self.db = self.instance.open('admin')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
45
5733
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
46 # Create the Otk db.
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
47 # This allows a test later on to open the existing db and
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
48 # set a class attribute to test the open retry loop
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
49 # just as though this process was using a pre-existing db
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
50 # rather then the new one we create.
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
51 otk = OneTimeKeys(self.db)
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
52 otk.set('key', key="value")
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
53
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
54 # 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
55 self.joeid = self.db.user.create(
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
56 username='joe',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
57 password=password.Password('random'),
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
58 address='random@home.org',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
59 realname='Joe Random',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
60 roles='User'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
61 )
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.commit()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
64 self.db.close()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
65 self.db = self.instance.open('joe')
5604
ed02a1e0aa5d Fix actions
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5602
diff changeset
66 # Allow joe to retire
ed02a1e0aa5d Fix actions
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5602
diff changeset
67 p = self.db.security.addPermission(name='Retire', klass='issue')
ed02a1e0aa5d Fix actions
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5602
diff changeset
68 self.db.security.addPermissionToRole('User', p)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
69
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
70 self.db.tx_Source = 'web'
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 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
73 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
74 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
75 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
76 self.db.issue.addprop(requireme=hyperdb.String(required=True))
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
77 self.db.msg.addprop(tx_Source=hyperdb.String())
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
78
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
79 self.db.post_init()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
80
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
81 thisdir = os.path.dirname(__file__)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
82 vars = {}
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
83 with open(os.path.join(thisdir, "tx_Source_detector.py")) as f:
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
84 code = compile(f.read(), "tx_Source_detector.py", "exec")
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
85 exec(code, vars)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
86 vars['init'](self.db)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
87
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
88 env = {
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
89 'PATH_INFO': 'http://localhost/rounduptest/rest/',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
90 'HTTP_HOST': 'localhost',
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
91 'TRACKER_NAME': 'rounduptest'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
92 }
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
93 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
94 self.dummy_client.request.headers.get = self.get_header
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
95 self.empty_form = cgi.FieldStorage()
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
96 self.terse_form = cgi.FieldStorage()
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
97 self.terse_form.list = [
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
98 cgi.MiniFieldStorage('@verbose', '0'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
99 ]
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
100
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
101 self.server = RestfulInstance(self.dummy_client, self.db)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
102
5710
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
103 self.db.Otk = self.db.getOTKManager()
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
104
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
105 self.db.config['WEB_SECRET_KEY'] = "XyzzykrnKm45Sd"
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
106
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
107 def tearDown(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
108 self.db.close()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
109 try:
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
110 shutil.rmtree(self.dirname)
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
111 except OSError as error:
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
112 if error.errno not in (errno.ENOENT, errno.ESRCH):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
113 raise
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
114
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
115 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
116 try:
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
117 return self.headers[header.lower()]
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
118 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
119 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
120
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
121 def testGet(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
122 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
123 Retrieve all three users
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
124 obtain data for 'joe'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
125 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
126 # Retrieve all three users.
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
127 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
128 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
129 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
130 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
131 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
132 self.assertEqual(
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
133 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
134 "3"
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
135 )
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
136
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
137 # Obtain data for 'joe'.
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
138 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
139 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
140 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
141 self.assertEqual(results['attributes']['username'], 'joe')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
142 self.assertEqual(results['attributes']['realname'], 'Joe Random')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
143
5678
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
144 # Obtain data for 'joe' via username lookup.
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
145 results = self.server.get_element('user', 'joe', self.empty_form)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
146 results = results['data']
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
147 self.assertEqual(self.dummy_client.response_code, 200)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
148 self.assertEqual(results['attributes']['username'], 'joe')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
149 self.assertEqual(results['attributes']['realname'], 'Joe Random')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
150
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
151 # Obtain data for 'joe' via username lookup (long form).
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
152 key = 'username=joe'
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
153 results = self.server.get_element('user', key, self.empty_form)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
154 results = results['data']
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
155 self.assertEqual(self.dummy_client.response_code, 200)
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
156 self.assertEqual(results['attributes']['username'], 'joe')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
157 self.assertEqual(results['attributes']['realname'], 'Joe Random')
b8e8b1b3ec77 REST: Add key lookup
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5674
diff changeset
158
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
159 # Obtain data for 'joe'.
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
160 results = self.server.get_attribute(
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
161 '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
162 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
163 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
164 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
165
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
166 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
167 """ 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
168
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
169 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
170 # 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
171 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
172 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
173 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
174 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
175 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
176 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
177 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
178 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
179 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
180 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
181 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
182 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
183 try:
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
184 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
185 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
186 pass
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
187 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
188 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
189 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
190 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
191 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
192 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
193 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
194 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
195 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
196 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
197 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
198 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
199 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
200 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
201 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
202 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
203 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
204 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
205
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
206
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
207 # 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
208 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
209 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
210 cgi.MiniFieldStorage('status', 'open'),
5825
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
211 cgi.MiniFieldStorage('@fields', 'nosy,status,creator'),
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
212 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
213 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
214
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
215 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
216 {'@total_size': 3,
5825
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
217 'collection': [ {
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
218 'creator': {'id': '3',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
219 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
220 'username': 'joe'},
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
221 'status': {'id': '9',
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
222 '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
223 '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
224 '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
225 'nosy': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
226 {'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
227 '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
228 '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
229 {'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
230 '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
231 '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
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 '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
234 'title': 'foo1' },
5825
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
235 { 'creator': {'id': '3',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
236 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
237 'username': 'joe'},
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
238 'status': {
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
239 '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
240 '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
241 '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
242 '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
243 'nosy': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
244 {'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
245 '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
246 '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
247 ],
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/2',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
249 'title': 'foo2'},
5825
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
250 {'creator': {'id': '3',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
251 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/3',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
252 'username': 'joe'},
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
253 'status': {
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
254 '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
255 '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
256 '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
257 '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
258 'nosy': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
259 '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
260 '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
261 ]}}
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
262
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
263 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
264 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
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 # 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
267 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
268 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
269 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
270 # 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
271 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
272
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
273 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
274 {'@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
275 'collection': [
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
276 {'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
277 '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
278 { '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
279
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
280 '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
281 {'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
282 '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
283
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 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
286 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
287
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
288 # 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
289 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
290 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
291 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
292 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
293 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
294
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
295 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
296 '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
297 "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
298 '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
299
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
300 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
301 # 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
302 # 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
303 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
304 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
305 )
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
306
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
307 # 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
308 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
309 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
310 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
311 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
312 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
313 ]
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 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
316 '@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
317 '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 {'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
319 '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
320 '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
321 '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
322 '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
323 {'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
324 '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
325 '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
326 '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
327 '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
328 {'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
329 '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
330 '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
331 'nosy': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
332 '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
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 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
335 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
336 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
337
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
338 # 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
339 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
340 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
341 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
342 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
343 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
344 # 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
345 # 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
346 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
347 {'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
348 '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
349 '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
350 {'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
351 '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
352 '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
353 {'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
354 '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
355 'queries': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
356 '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
357 '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
358 '@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
359
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
360 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
361 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
362
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
363 ## 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
364 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
365 form.list = [
5825
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
366 cgi.MiniFieldStorage('@fields', 'queries,password,creator'),
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
367 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
368 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
369 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
370 '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
371 '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
372 '@etag': '',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
373 '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
374 'attributes': {
5825
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
375 'creator': {'id': '1',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
376 'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/1',
bcb894bc9740 Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents: 5801
diff changeset
377 'username': 'admin'},
5682
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
378 '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
379 'queries': [],
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
380 '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
381 }
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
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
384 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
385 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
386 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
387
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
388 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
389 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
390 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
391 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
392 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
393 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
394 '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
395 '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
396 'attributes': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
397 'status': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
398 '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
399 '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
400 'priority': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
401 '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
402 '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
403 '@etag': '',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
404 '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
405
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
406 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
407 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
408 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
409
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
410 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
411 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
412 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
413 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
414 ]
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
415 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
416 '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
417 '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
418 'attributes': {
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
419 '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
420 '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
421 '@etag': '',
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
422 '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
423
e8ac82b8d074 Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents: 5678
diff changeset
424 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
425 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
426 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
427
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
428 def testFilter(self):
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
429 """
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
430 Retrieve all three users
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
431 obtain data for 'joe'
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 # create sample data
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
434 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
435 self.db.status.create(name='open')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
436 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
437 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
438 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
439 self.db.status.create(name='closed')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
440 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
441 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
442 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
443 self.db.priority.create(name='normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
444 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
445 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
446 try:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
447 self.db.priority.create(name='critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
448 except ValueError:
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
449 pass
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
450 self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
451 title='foo4',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
452 status=self.db.status.lookup('closed'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
453 priority=self.db.priority.lookup('critical')
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 self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
456 title='foo1',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
457 status=self.db.status.lookup('open'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
458 priority=self.db.priority.lookup('normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
459 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
460 issue_open_norm = self.db.issue.create(
5842
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
461 title='foo2 normal',
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
462 status=self.db.status.lookup('open'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
463 priority=self.db.priority.lookup('normal')
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 issue_closed_norm = self.db.issue.create(
5842
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
466 title='foo3 closed normal',
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
467 status=self.db.status.lookup('closed'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
468 priority=self.db.priority.lookup('normal')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
469 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
470 issue_closed_crit = self.db.issue.create(
5842
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
471 title='foo4 closed',
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
472 status=self.db.status.lookup('closed'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
473 priority=self.db.priority.lookup('critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
474 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
475 issue_open_crit = self.db.issue.create(
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
476 title='foo5',
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
477 status=self.db.status.lookup('open'),
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
478 priority=self.db.priority.lookup('critical')
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
479 )
5623
1c4adab65faf use config file setting for creating tracker uri
John Rouillard <rouilj@ieee.org>
parents: 5604
diff changeset
480 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
481
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
482 # Retrieve all issue status=open
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
483 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
484 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
485 cgi.MiniFieldStorage('status', 'open')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
486 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
487 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
488 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
489 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
490 results['data']['collection'])
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_open_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'])
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
493 self.assertNotIn(
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
494 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
495 results['data']['collection']
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
496 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
497
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
498 # Retrieve all issue status=closed and priority=critical
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
499 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
500 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
501 cgi.MiniFieldStorage('status', 'closed'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
502 cgi.MiniFieldStorage('priority', 'critical')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
503 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
504 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
505 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
506 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
507 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
508 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
509 results['data']['collection'])
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
510 self.assertNotIn(
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
511 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
512 results['data']['collection']
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
513 )
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
514
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
515 # 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
516 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
517 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
518 cgi.MiniFieldStorage('status', 'closed'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
519 cgi.MiniFieldStorage('priority', 'normal,critical')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
520 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
521 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
522 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
523 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
524 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
525 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
526 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
527 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
528 results['data']['collection'])
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
529 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
530 results['data']['collection'])
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
531
5842
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
532 # Retrieve all issue status=closed and priority=normal,critical
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
533 # using duplicate priority key's.
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
534 form = cgi.FieldStorage()
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
535 form.list = [
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
536 cgi.MiniFieldStorage('status', 'closed'),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
537 cgi.MiniFieldStorage('priority', 'normal'),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
538 cgi.MiniFieldStorage('priority', 'critical')
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
539 ]
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
540 results = self.server.get_collection('issue', form)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
541 self.assertEqual(self.dummy_client.response_code, 200)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
542 self.assertIn(get_obj(base_path, issue_closed_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
543 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
544 self.assertIn(get_obj(base_path, issue_closed_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
545 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
546 self.assertNotIn(get_obj(base_path, issue_open_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
547 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
548 self.assertNotIn(get_obj(base_path, issue_open_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
549 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
550
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
551 # Retrieve all issues with title containing
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
552 # closed, normal and 3 using duplicate title filterkeys
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
553 form = cgi.FieldStorage()
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
554 form.list = [
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
555 cgi.MiniFieldStorage('title', 'closed'),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
556 cgi.MiniFieldStorage('title', 'normal'),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
557 cgi.MiniFieldStorage('title', '3')
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
558 ]
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
559 results = self.server.get_collection('issue', form)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
560 self.assertEqual(self.dummy_client.response_code, 200)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
561 self.assertNotIn(get_obj(base_path, issue_closed_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
562 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
563 self.assertIn(get_obj(base_path, issue_closed_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
564 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
565 self.assertNotIn(get_obj(base_path, issue_open_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
566 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
567 self.assertNotIn(get_obj(base_path, issue_open_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
568 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
569 self.assertEqual(len(results['data']['collection']), 1)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
570
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
571 # Retrieve all issues (no hits) with title containing
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
572 # closed, normal and foo3 in this order using title filter
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
573 form = cgi.FieldStorage()
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
574 form.list = [
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
575 cgi.MiniFieldStorage('title', 'closed normal foo3')
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
576 ]
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
577 results = self.server.get_collection('issue', form)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
578 self.assertEqual(self.dummy_client.response_code, 200)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
579 self.assertNotIn(get_obj(base_path, issue_closed_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
580 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
581 self.assertNotIn(get_obj(base_path, issue_closed_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
582 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
583 self.assertNotIn(get_obj(base_path, issue_open_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
584 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
585 self.assertNotIn(get_obj(base_path, issue_open_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
586 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
587 self.assertEqual(len(results['data']['collection']), 0)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
588
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
589 # Retrieve all issues with title containing
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
590 # foo3, closed and normal in this order using title filter
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
591 form = cgi.FieldStorage()
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
592 form.list = [
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
593 cgi.MiniFieldStorage('title', 'foo3 closed normal')
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
594 ]
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
595 results = self.server.get_collection('issue', form)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
596 self.assertEqual(self.dummy_client.response_code, 200)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
597 self.assertNotIn(get_obj(base_path, issue_closed_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
598 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
599 self.assertIn(get_obj(base_path, issue_closed_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
600 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
601 self.assertNotIn(get_obj(base_path, issue_open_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
602 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
603 self.assertNotIn(get_obj(base_path, issue_open_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
604 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
605 self.assertEqual(len(results['data']['collection']), 1)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
606
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
607 # Retrieve all issues with word closed in title
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
608 form = cgi.FieldStorage()
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
609 form.list = [
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
610 cgi.MiniFieldStorage('title', 'closed'),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
611 ]
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
612 results = self.server.get_collection('issue', form)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
613 self.assertEqual(self.dummy_client.response_code, 200)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
614 self.assertIn(get_obj(base_path, issue_closed_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
615 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
616 self.assertIn(get_obj(base_path, issue_closed_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
617 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
618 self.assertNotIn(get_obj(base_path, issue_open_crit),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
619 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
620 self.assertNotIn(get_obj(base_path, issue_open_norm),
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
621 results['data']['collection'])
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
622 self.assertEqual(len(results['data']['collection']), 2)
9c6617857032 Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents: 5825
diff changeset
623
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
624 def testPagination(self):
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
625 """
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
626 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
627 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
628 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
629 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
630 number of items.
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
631 """
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
632 # 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
633 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
634 self.db.issue.create(title='foo' + str(i))
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
635
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
636 # Retrieving all the issues
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
637 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
638 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
639 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
640 # 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
641 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
642 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
643 self.assertEqual(
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
644 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
645 str(total_length)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
646 )
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
647
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
648
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
649 # 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
650 # 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
651 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
652 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
653 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
654 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
655 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
656 "bugs/rest/data/issue"
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
657
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
658 # Retrieve page 1
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
659 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
660 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
661 cgi.MiniFieldStorage('@page_size', page_size),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
662 cgi.MiniFieldStorage('@page_index', 1)
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
663 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
664 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
665 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
666 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
667 page_one_expected)
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
668 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
669 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
670 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
671 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
672 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
673 "%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
674 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
675 "%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
676
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
677 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
678
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
679 # Retrieve page 2
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
680 form = cgi.FieldStorage()
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
681 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
682 cgi.MiniFieldStorage('@page_size', page_size),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
683 cgi.MiniFieldStorage('@page_index', 2)
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
684 ]
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
685 results = self.server.get_collection('issue', form)
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
686 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
687 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
688 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
689 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
690 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
691 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
692 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
693 "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
694 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
695 "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
696 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
697 "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
698 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
699 'self')
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
700 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
701 'next')
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
702 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
703 'prev')
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
704
5639
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
705 # Retrieve page 3
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
706 form = cgi.FieldStorage()
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
707 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
708 cgi.MiniFieldStorage('@page_size', page_size),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
709 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
710 ]
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
711 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
712 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
713 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
714 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
715 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
716 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
717 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
718 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
719 "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
720 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
721 "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
722
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
723 # 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
724 # 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
725 form = cgi.FieldStorage()
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
726 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
727 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
728 ]
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
729 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
730 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
731 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
732 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
733 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
734 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
735 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
736 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
737
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
738 # 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
739 # is needed to:
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
740 # page_size < 0
f576957cbb1f Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents: 5630
diff changeset
741 # 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
742
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
743 def testRestRateLimit(self):
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
744
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
745 self.db.config['WEB_API_CALLS_PER_INTERVAL'] = 20
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
746 self.db.config['WEB_API_INTERVAL_IN_SEC'] = 60
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
747
5733
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
748 # Otk code never passes through the
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
749 # retry loop. Not sure why but I can force it
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
750 # through the loop by setting the internal _db_type
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
751 # setting once the db is created by the previous command.
5734
5cd9ac3daed7 Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents: 5733
diff changeset
752 try:
5cd9ac3daed7 Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents: 5733
diff changeset
753 self.db.Otk._db_type = whichdb("%s/%s"%(self.db.Otk.dir, self.db.Otk.name))
5cd9ac3daed7 Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents: 5733
diff changeset
754 except AttributeError:
5cd9ac3daed7 Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents: 5733
diff changeset
755 # if dir attribute doesn't exist the primary db is not
5cd9ac3daed7 Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents: 5733
diff changeset
756 # sqlite or anydbm. So don't need to exercise code.
5cd9ac3daed7 Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents: 5733
diff changeset
757 pass
5733
62bdcb874433 Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents: 5732
diff changeset
758
5732
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
759 print("Now realtime start:", datetime.utcnow())
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
760 # don't set an accept header; json should be the default
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
761 # use up all our allowed api calls
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
762 for i in range(20):
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
763 # i is 0 ... 19
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
764 self.client_error_message = []
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
765 results = self.server.dispatch('GET',
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
766 "/rest/data/user/%s/realname"%self.joeid,
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
767 self.empty_form)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
768
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
769 # is successful
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
770 self.assertEqual(self.server.client.response_code, 200)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
771 # does not have Retry-After header as we have
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
772 # suceeded with this query
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
773 self.assertFalse("Retry-After" in
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
774 self.server.client.additional_headers)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
775 # remaining count is correct
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
776 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
777 self.server.client.additional_headers["X-RateLimit-Remaining"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
778 self.db.config['WEB_API_CALLS_PER_INTERVAL'] -1 - i
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
779 )
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
780
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
781 # trip limit
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
782 self.server.client.additional_headers.clear()
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
783 results = self.server.dispatch('GET',
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
784 "/rest/data/user/%s/realname"%self.joeid,
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
785 self.empty_form)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
786 print(results)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
787 self.assertEqual(self.server.client.response_code, 429)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
788
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
789 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
790 self.server.client.additional_headers["X-RateLimit-Limit"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
791 self.db.config['WEB_API_CALLS_PER_INTERVAL'])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
792 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
793 self.server.client.additional_headers["X-RateLimit-Limit-Period"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
794 self.db.config['WEB_API_INTERVAL_IN_SEC'])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
795 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
796 self.server.client.additional_headers["X-RateLimit-Remaining"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
797 0)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
798 # value will be almost 60. Allow 1-2 seconds for all 20 rounds.
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
799 self.assertAlmostEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
800 self.server.client.additional_headers["X-RateLimit-Reset"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
801 59, delta=1)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
802 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
803 str(self.server.client.additional_headers["Retry-After"]),
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
804 "3.0") # check as string
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
805
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
806 print("Reset:", self.server.client.additional_headers["X-RateLimit-Reset"])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
807 print("Now realtime pre-sleep:", datetime.utcnow())
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
808 sleep(3.1) # sleep as requested so we can do another login
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
809 print("Now realtime post-sleep:", datetime.utcnow())
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
810
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
811 # this should succeed
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
812 self.server.client.additional_headers.clear()
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
813 results = self.server.dispatch('GET',
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
814 "/rest/data/user/%s/realname"%self.joeid,
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
815 self.empty_form)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
816 print(results)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
817 print("Reset:", self.server.client.additional_headers["X-RateLimit-Reset-date"])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
818 print("Now realtime:", datetime.utcnow())
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
819 print("Now ts header:", self.server.client.additional_headers["Now"])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
820 print("Now date header:", self.server.client.additional_headers["Now-date"])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
821
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
822 self.assertEqual(self.server.client.response_code, 200)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
823
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
824 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
825 self.server.client.additional_headers["X-RateLimit-Limit"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
826 self.db.config['WEB_API_CALLS_PER_INTERVAL'])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
827 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
828 self.server.client.additional_headers["X-RateLimit-Limit-Period"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
829 self.db.config['WEB_API_INTERVAL_IN_SEC'])
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
830 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
831 self.server.client.additional_headers["X-RateLimit-Remaining"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
832 0)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
833 self.assertFalse("Retry-After" in
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
834 self.server.client.additional_headers)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
835 # we still need to wait a minute for everything to clear
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
836 self.assertAlmostEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
837 self.server.client.additional_headers["X-RateLimit-Reset"],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
838 59, delta=1)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
839
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
840 # and make sure we need to wait another three seconds
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
841 # as we consumed the last api call
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
842 results = self.server.dispatch('GET',
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
843 "/rest/data/user/%s/realname"%self.joeid,
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
844 self.empty_form)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
845
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
846 self.assertEqual(self.server.client.response_code, 429)
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
847 self.assertEqual(
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
848 str(self.server.client.additional_headers["Retry-After"]),
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
849 "3.0") # check as string
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
850
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
851 json_dict = json.loads(b2s(results))
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
852 self.assertEqual(json_dict['error']['msg'],
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
853 "Api rate limits exceeded. Please wait: 3 seconds.")
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
854
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
855 # reset rest params
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
856 self.db.config['WEB_API_CALLS_PER_INTERVAL'] = 0
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
857 self.db.config['WEB_API_INTERVAL_IN_SEC'] = 3600
0e6ed3d72f92 Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents: 5729
diff changeset
858
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
859 def testEtagGeneration(self):
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
860 ''' 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
861
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
862 This mocks date.Date() when creating the target to be
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
863 etagged. Differing dates make this test impossible.
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
864 '''
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
865 from roundup import date
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
866
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
867 originalDate = date.Date
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
868
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
869 dummy=date.Date('2000-06-26.00:34:02.0')
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
870
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
871 # is a closure the best way to return a static Date object??
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
872 def dummyDate(adate=None):
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
873 def dummyClosure(adate=None, translator=None):
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
874 return dummy
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
875 return dummyClosure
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
876
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
877 date.Date = dummyDate()
5728
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
878 try:
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
879 newuser = self.db.user.create(
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
880 username='john',
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
881 password=password.Password('random1', scheme='plaintext'),
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
882 address='random1@home.org',
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
883 realname='JohnRandom',
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
884 roles='User,Admin'
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
885 )
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
886
5728
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
887 # verify etag matches what we calculated in the past
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
888 node = self.db.user.getnode(newuser)
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
889 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'])
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
890 items = node.items(protected=True) # include every item
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
891 print(repr(sorted(items)))
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
892 print(etag)
5729
9ea2ce9d10cf A few internet references report that etags for the same underlying
John Rouillard <rouilj@ieee.org>
parents: 5728
diff changeset
893 self.assertEqual(etag, '"0433784660a141e8262835171e70fd2f"')
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
894
5728
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
895 # modify key and verify we have a different etag
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
896 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'] + "a")
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
897 items = node.items(protected=True) # include every item
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
898 print(repr(sorted(items)))
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
899 print(etag)
5729
9ea2ce9d10cf A few internet references report that etags for the same underlying
John Rouillard <rouilj@ieee.org>
parents: 5728
diff changeset
900 self.assertNotEqual(etag, '"0433784660a141e8262835171e70fd2f"')
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
901
5728
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
902 # change data and verify we have a different etag
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
903 node.username="Paul"
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
904 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'])
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
905 items = node.items(protected=True) # include every item
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
906 print(repr(sorted(items)))
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
907 print(etag)
5729
9ea2ce9d10cf A few internet references report that etags for the same underlying
John Rouillard <rouilj@ieee.org>
parents: 5728
diff changeset
908 self.assertEqual(etag, '"8abeacd284d58655c620d60389e29d4d"')
5728
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
909 finally:
bfd28644fe43 In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents: 5727
diff changeset
910 date.Date = originalDate
5668
a4bb88a1a643 A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents: 5656
diff changeset
911
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
912 def testEtagProcessing(self):
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
913 '''
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
914 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
915 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
916 @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
917
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
918 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
919 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
920
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
921 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
922 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
923 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
924 '''
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
925 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
926 'brokenheader', 'brokenetag', 'none'):
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
927 try:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
928 # 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
929 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
930 except AttributeError:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
931 pass
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
932
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
933 form = cgi.FieldStorage()
5726
e199d0ae4a25 issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents: 5711
diff changeset
934 etag = calculate_etag(self.db.user.getnode(self.joeid),
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
935 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
936 form.list = [
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
937 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
938 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
939
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
940 if mode == 'header':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
941 print("Mode = %s"%mode)
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
942 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
943 elif mode == 'etag':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
944 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
945 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
946 elif mode == 'both':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
947 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
948 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
949 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
950 elif mode == 'brokenheader':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
951 print("Mode = %s"%mode)
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
952 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
953 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
954 elif mode == 'brokenetag':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
955 print("Mode = %s"%mode)
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
956 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
957 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
958 elif mode == 'none':
5645
7f4d19867123 Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents: 5643
diff changeset
959 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
960 else:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
961 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
962
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
963 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
964 '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
965 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
966 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
967 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
968 else:
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
969 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
970
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
971 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
972 """
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
973 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
974 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
975 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
976 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
977 """
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
978
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
979 # 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
980 # 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
981 # 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
982 # 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
983 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
984 "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
985 "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
986 "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
987 "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
988 "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
989 }'
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
990 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
991 "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
992 "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
993 }
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
994 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
995 "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
996 "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
997 }
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
998 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
999 # 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
1000 # 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
1001 # 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
1002 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
1003 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
1004 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
1005 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
1006 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
1007 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
1008 "/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
1009 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
1010
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
1011 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
1012 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
1013 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
1014 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
1015 "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
1016 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
1017 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
1018 "/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
1019 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
1020 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
1021 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
1022 "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
1023 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
1024 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
1025 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
1026 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
1027 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
1028 ['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
1029 "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
1030
4aae822e2cb4 Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents: 5686
diff changeset
1031
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1032 def testDispatch(self):
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1033 """
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1034 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
1035 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
1036 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
1037 process.
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1038 """
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1039 # TEST #1
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1040 # 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
1041 # 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
1042 # use etag in header
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1043 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1044 self.db.config['WEB_SECRET_KEY'])
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
1045 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
1046 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
1047 "CONTENT_LENGTH": len(body),
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1048 "REQUEST_METHOD": "PUT"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1049 }
5686
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
1050 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
1051 "content-type": env['CONTENT_TYPE'],
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1052 "content-length": env['CONTENT_LENGTH'],
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1053 "if-match": etag
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1054 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1055 self.headers=headers
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1056 # 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
1057 # 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
1058 # FieldStorage(None, None, [])
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
1059 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
1060 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
1061 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1062 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
1063 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
1064 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
1065 "/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
1066 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1067
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1068 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
1069 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
1070 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
1071 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
1072 '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
1073
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
1074
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
1075 # 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
1076 # 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
1077 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
1078 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
1079 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
1080 headers=headers,
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
1081 environ=env)
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
1082 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
1083 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
1084 "/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
1085 form)
eb51c0d9c9bf Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents: 5682
diff changeset
1086 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
1087 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1088
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1089 # TEST #2
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1090 # 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
1091 # 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
1092 # use etag in payload
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1093 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1094 self.db.config['WEB_SECRET_KEY'])
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1095 etagb = etag.strip ('"')
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1096 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
1097 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
1098 "CONTENT_LENGTH": len(body),
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1099 "REQUEST_METHOD": "PUT",
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1100 }
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1101 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
1102 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
1103 form = client.BinaryFieldStorage(body_file,
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1104 headers=None,
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1105 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
1106 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
1107
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1108 headers={"accept": "application/json",
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1109 "content-type": env['CONTENT_TYPE'],
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1110 "if-match": etag
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1111 }
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1112 self.headers=headers # set for dispatch
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1113
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1114 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
1115 "/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
1116 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1117
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1118 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
1119 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
1120 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
1121 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
1122 'Joe Doe 2')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1123 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1124
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1125 # TEST #3
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1126 # 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
1127 # 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
1128 # FieldStorage(None, None, [])
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1129 # use etag from header
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1130 #
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1131 # 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
1132 # the results from the db.
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1133 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1134 self.db.config['WEB_SECRET_KEY'])
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1135 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
1136 "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
1137 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1138 form = cgi.FieldStorage()
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1139 form.list = [
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1140 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
1141 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
1142 ]
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1143 self.headers = headers
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
1144 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
1145 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
1146 "/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
1147 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1148 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
1149 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
1150 "/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
1151 self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1152 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
1153 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
1154
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1155 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
1156 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
1157 "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
1158 "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
1159 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
1160 "<type 'str'>"))
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1161 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
1162 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1163
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1164
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1165 # TEST #4
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1166 # 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
1167 # 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
1168 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
1169 self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1170 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
1171
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1172 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1173 self.db.config['WEB_SECRET_KEY'])
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1174 etagb = etag.strip ('"')
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1175 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
1176 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
1177 "CONTENT_LENGTH": len(body),
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1178 "REQUEST_METHOD": "PATCH"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1179 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1180 headers={"accept": "application/json",
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1181 "content-type": env['CONTENT_TYPE'],
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1182 "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
1183 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1184 self.headers=headers
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
1185 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
1186 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
1187 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1188 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
1189 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
1190 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
1191 "/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
1192 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1193
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1194 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
1195 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
1196 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
1197 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
1198 'demo2@example.com')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1199
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1200 # and set it back reusing env and headers from last test
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1201 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1202 self.db.config['WEB_SECRET_KEY'])
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1203 etagb = etag.strip ('"')
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1204 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
1205 stored_results['data']['attributes']['address'],
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1206 etagb))
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1207 # 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
1208 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
1209 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
1210 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1211 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
1212 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
1213 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
1214 "/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
1215 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1216
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1217 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
1218 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
1219 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
1220 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
1221 'random@home.org')
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1222 del(self.headers)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1223
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1224 # TEST #5
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1225 # POST: create new issue
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1226 # no etag needed
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1227 etag = "not needed"
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
1228 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
1229 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
1230 "CONTENT_LENGTH": len(body),
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1231 "REQUEST_METHOD": "POST"
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1232 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1233 headers={"accept": "application/json",
5655
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1234 "content-type": env['CONTENT_TYPE'],
207e0f5d551c Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
parents: 5651 5653
diff changeset
1235 "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
1236 }
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1237 self.headers=headers
5651
a02ef29b4242 Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5650
diff changeset
1238 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
1239 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
1240 headers=headers,
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1241 environ=env)
5650
e8ca7072c629 Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5647
diff changeset
1242 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
1243 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
1244 "/rest/data/issue",
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1245 form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1246
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1247 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
1248 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
1249 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
1250 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
1251 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
1252 self.empty_form)
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1253 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
1254 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
1255 'foo bar')
5653
ba67e397f063 Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents: 5647
diff changeset
1256
5711
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1257 # TEST #6
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1258 # POST: an invalid class
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1259 # no etag needed
5710
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1260 etag = "not needed"
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1261 body=b'{ "title": "foo bar", "priority": "critical" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1262 env = { "CONTENT_TYPE": "application/json",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1263 "CONTENT_LENGTH": len(body),
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1264 "REQUEST_METHOD": "POST"
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1265 }
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1266 headers={"accept": "application/json",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1267 "content-type": env['CONTENT_TYPE'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1268 "content-length": len(body)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1269 }
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1270 self.headers=headers
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1271 body_file=BytesIO(body) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1272 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1273 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1274 environ=env)
5711
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1275 self.server.client.request.headers.get=self.get_header
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1276 results = self.server.dispatch('POST',
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1277 "/rest/data/nonissue",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1278 form)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1279
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1280 self.assertEqual(self.server.client.response_code, 404)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1281 json_dict = json.loads(b2s(results))
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1282 status=json_dict['error']['status']
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1283 msg=json_dict['error']['msg']
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1284 self.assertEqual(status, 404)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1285 self.assertEqual(msg, 'Class nonissue not found')
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1286
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1287 # TEST #7
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1288 # POST: status without key field of name
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1289 # also test that version spec in accept header is accepted
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1290 # no etag needed
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1291 etag = "not needed"
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1292 body=b'{ "order": 5 }'
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1293 env = { "CONTENT_TYPE": "application/json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1294 "CONTENT_LENGTH": len(body),
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1295 "REQUEST_METHOD": "POST"
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1296 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1297 headers={"accept": "application/json; version=1",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1298 "content-type": env['CONTENT_TYPE'],
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1299 "content-length": len(body)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1300 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1301 self.headers=headers
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1302 body_file=BytesIO(body) # FieldStorage needs a file
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1303 form = client.BinaryFieldStorage(body_file,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1304 headers=headers,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1305 environ=env)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1306 self.server.client.request.headers.get=self.get_header
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1307 self.db.setCurrentUser('admin') # must be admin to create status
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1308 results = self.server.dispatch('POST',
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1309 "/rest/data/status",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1310 form)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1311
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1312 self.assertEqual(self.server.client.response_code, 400)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1313 json_dict = json.loads(b2s(results))
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1314 status=json_dict['error']['status']
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1315 msg=json_dict['error']['msg']
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1316 self.assertEqual(status, 400)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1317 self.assertEqual(msg, "Must provide the 'name' property.")
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1318
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1319
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1320 # TEST #8
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1321 # DELETE: delete issue 1
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1322 etag = calculate_etag(self.db.issue.getnode("1"),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1323 self.db.config['WEB_SECRET_KEY'])
5711
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1324 etagb = etag.strip ('"')
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1325 env = {"CONTENT_TYPE": "application/json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1326 "CONTENT_LEN": 0,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1327 "REQUEST_METHOD": "DELETE" }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1328 # use text/plain header and request json output by appending
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1329 # .json to the url.
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1330 headers={"accept": "text/plain",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1331 "content-type": env['CONTENT_TYPE'],
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1332 "if-match": '"%s"'%etagb,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1333 "content-length": 0,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1334 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1335 self.headers=headers
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1336 body_file=BytesIO(b'') # FieldStorage needs a file
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1337 form = client.BinaryFieldStorage(body_file,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1338 headers=headers,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1339 environ=env)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1340 self.server.client.request.headers.get=self.get_header
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1341 self.db.setCurrentUser('admin') # must be admin to delete issue
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1342 results = self.server.dispatch('DELETE',
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1343 "/rest/data/issue/1.json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1344 form)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1345 self.assertEqual(self.server.client.response_code, 200)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1346 json_dict = json.loads(b2s(results))
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1347 print(results)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1348 status=json_dict['data']['status']
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1349 self.assertEqual(status, 'ok')
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1350
5741
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1351 # TEST #9
5742
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1352 # GET: test that version can be set with accept:
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1353 # ... ; version=z
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1354 # or
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1355 # application/vnd.x.y-vz+json
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1356 # or
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1357 # @apiver
5741
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1358 # simulate: /rest/data/issue
5742
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1359 form = cgi.FieldStorage()
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1360 form.list = [
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1361 cgi.MiniFieldStorage('@apiver', 'L'),
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1362 ]
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1363 headers={"accept": "application/json; notversion=z" }
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1364 self.headers=headers
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1365 self.server.client.request.headers.get=self.get_header
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1366 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1367 "/rest/data/issue/1", form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1368 print(results)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1369 json_dict = json.loads(b2s(results))
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1370 self.assertEqual(json_dict['error']['status'], 400)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1371 self.assertEqual(json_dict['error']['msg'],
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1372 "Unrecognized version: L. See /rest without "
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1373 "specifying version for supported versions.")
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1374
5741
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1375 headers={"accept": "application/json; version=z" }
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1376 self.headers=headers
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1377 self.server.client.request.headers.get=self.get_header
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1378 results = self.server.dispatch('GET',
5742
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1379 "/rest/data/issue/1", form)
5741
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1380 print(results)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1381 json_dict = json.loads(b2s(results))
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1382 self.assertEqual(json_dict['error']['status'], 400)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1383 self.assertEqual(json_dict['error']['msg'],
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1384 "Unrecognized version: z. See /rest without "
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1385 "specifying version for supported versions.")
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1386
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1387 headers={"accept": "application/vnd.roundup.test-vz+json" }
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1388 self.headers=headers
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1389 self.server.client.request.headers.get=self.get_header
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1390 results = self.server.dispatch('GET',
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1391 "/rest/data/issue/1", self.empty_form)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1392 print(results)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1393 self.assertEqual(self.server.client.response_code, 400)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1394 json_dict = json.loads(b2s(results))
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1395 self.assertEqual(json_dict['error']['status'], 400)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1396 self.assertEqual(json_dict['error']['msg'],
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1397 "Unrecognized version: z. See /rest without "
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1398 "specifying version for supported versions.")
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1399
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1400 # verify that version priority is correct; should be version=...
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1401 headers={"accept": "application/vnd.roundup.test-vz+json; version=a"
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1402 }
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1403 self.headers=headers
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1404 self.server.client.request.headers.get=self.get_header
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1405 results = self.server.dispatch('GET',
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1406 "/rest/data/issue/1", self.empty_form)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1407 print(results)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1408 self.assertEqual(self.server.client.response_code, 400)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1409 json_dict = json.loads(b2s(results))
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1410 self.assertEqual(json_dict['error']['status'], 400)
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1411 self.assertEqual(json_dict['error']['msg'],
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1412 "Unrecognized version: a. See /rest without "
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1413 "specifying version for supported versions.")
9c2e51aae18a Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents: 5734
diff changeset
1414
5742
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1415 # TEST #10
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1416 # check /rest and /rest/summary and /rest/notthere
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1417 expected_rest = {
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1418 "data": {
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1419 "supported_versions": [
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1420 1
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1421 ],
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1422 "default_version": 1,
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1423 "links": [
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1424 {
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1425 "rel": "summary",
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1426 "uri": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/summary"
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1427 },
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1428 {
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1429 "rel": "self",
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1430 "uri": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest"
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1431 },
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1432 {
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1433 "rel": "data",
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1434 "uri": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data"
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1435 }
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1436 ]
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1437 }
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1438 }
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1439
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1440 self.headers={}
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1441 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1442 "/rest", self.empty_form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1443 print(results)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1444 self.assertEqual(self.server.client.response_code, 200)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1445 results_dict = json.loads(b2s(results))
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1446 self.assertEqual(results_dict, expected_rest)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1447
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1448
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1449 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1450 "/rest/", self.empty_form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1451 print(results)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1452 self.assertEqual(self.server.client.response_code, 200)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1453 results_dict = json.loads(b2s(results))
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1454 self.assertEqual(results_dict, expected_rest)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1455
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1456 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1457 "/rest/summary", self.empty_form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1458 print(results)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1459 self.assertEqual(self.server.client.response_code, 200)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1460
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1461 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1462 "/rest/summary/", self.empty_form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1463 print(results)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1464 self.assertEqual(self.server.client.response_code, 200)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1465
5746
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1466 expected_data = {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1467 "data": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1468 "issue": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1469 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1470 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1471 "priority": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1472 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/priority"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1473 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1474 "user": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1475 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1476 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1477 "query": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1478 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/query"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1479 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1480 "status": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1481 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1482 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1483 "keyword": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1484 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/keyword"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1485 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1486 "msg": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1487 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/msg"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1488 },
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1489 "file": {
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1490 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/file"
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1491 }
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1492 }
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1493 }
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1494
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1495 results = self.server.dispatch('GET',
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1496 "/rest/data", self.empty_form)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1497 print(results)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1498 self.assertEqual(self.server.client.response_code, 200)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1499 results_dict = json.loads(b2s(results))
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1500 self.assertEqual(results_dict, expected_data)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1501
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1502 results = self.server.dispatch('GET',
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1503 "/rest/data/", self.empty_form)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1504 print(results)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1505 self.assertEqual(self.server.client.response_code, 200)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1506 results_dict = json.loads(b2s(results))
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1507 self.assertEqual(results_dict, expected_data)
fea2b6e54492 Check /rest/data.
John Rouillard <rouilj@ieee.org>
parents: 5744
diff changeset
1508
5742
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1509 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1510 "/rest/notthere", self.empty_form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1511 self.assertEqual(self.server.client.response_code, 404)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1512
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1513 results = self.server.dispatch('GET',
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1514 "/rest/notthere/", self.empty_form)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1515 self.assertEqual(self.server.client.response_code, 404)
97d7faebef0a Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents: 5741
diff changeset
1516
5711
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1517 del(self.headers)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1518
5744
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1519 def testAcceptHeaderParsing(self):
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1520 # TEST #1
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1521 # json highest priority
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1522 self.server.client.request.headers.get=self.get_header
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1523 headers={"accept": "application/json; version=1,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1524 "application/xml; q=0.5; version=2,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1525 "text/plain; q=0.75; version=2"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1526 }
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1527 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1528 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1529 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1530 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1531 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1532 self.assertEqual(self.server.client.response_code, 200)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1533 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1534 "application/json")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1535
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1536 # TEST #2
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1537 # text highest priority
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1538 headers={"accept": "application/json; q=0.5; version=1,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1539 "application/xml; q=0.25; version=2,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1540 "text/plain; q=1.0; version=3"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1541 }
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1542 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1543 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1544 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1545 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1546 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1547 self.assertEqual(self.server.client.response_code, 200)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1548 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1549 "application/json")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1550
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1551 # TEST #3
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1552 # no acceptable type
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1553 headers={"accept": "text/plain; q=1.0; version=2"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1554 }
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1555 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1556 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1557 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1558 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1559 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1560 self.assertEqual(self.server.client.response_code, 406)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1561 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1562 "application/json")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1563
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1564 # TEST #4
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1565 # no accept header, should use default json
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1566 headers={}
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1567 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1568 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1569 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1570 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1571 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1572 self.assertEqual(self.server.client.response_code, 200)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1573 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1574 "application/json")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1575
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1576 # TEST #5
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1577 # wildcard accept header, should use default json
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1578 headers={ "accept": "*/*"}
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1579 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1580 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1581 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1582 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1583 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1584 self.assertEqual(self.server.client.response_code, 200)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1585 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1586 "application/json")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1587
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1588 # TEST #6
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1589 # invalid q factor if not ignored/demoted
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1590 # application/json is selected with invalid version
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1591 # and errors.
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1592 # this ends up choosing */* which triggers json.
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1593 self.server.client.request.headers.get=self.get_header
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1594 headers={"accept": "application/json; q=1.5; version=99,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1595 "*/*; q=0.9; version=1,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1596 "text/plain; q=3.75; version=2"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1597 }
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1598 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1599 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1600 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1601 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1602 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1603 self.assertEqual(self.server.client.response_code, 200)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1604 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1605 "application/json")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1606
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1607
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1608 '''
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1609 # only works if dicttoxml.py is installed.
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1610 # not installed for testing
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1611 # TEST #7
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1612 # xml wins
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1613 headers={"accept": "application/json; q=0.5; version=2,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1614 "application/xml; q=0.75; version=1,"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1615 "text/plain; q=1.0; version=2"
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1616 }
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1617 self.headers=headers
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1618 results = self.server.dispatch('GET',
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1619 "/rest/data/status/1",
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1620 self.empty_form)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1621 print(results)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1622 self.assertEqual(self.server.client.response_code, 200)
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1623 self.assertEqual(self.server.client.additional_headers['Content-Type'],
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1624 "application/xml")
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1625 '''
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1626
5743
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1627 def testMethodOverride(self):
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1628 # TEST #1
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1629 # Use GET, PUT, PATCH to tunnel DELETE expect error
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1630
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1631 body=b'{ "order": 5 }'
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1632 env = { "CONTENT_TYPE": "application/json",
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1633 "CONTENT_LENGTH": len(body),
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1634 "REQUEST_METHOD": "POST"
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1635 }
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1636 body_file=BytesIO(body) # FieldStorage needs a file
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1637 self.server.client.request.headers.get=self.get_header
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1638 for method in ( "GET", "PUT", "PATCH" ):
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1639 headers={"accept": "application/json; version=1",
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1640 "content-type": env['CONTENT_TYPE'],
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1641 "content-length": len(body),
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1642 "x-http-method-override": "DElETE",
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1643 }
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1644 self.headers=headers
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1645 form = client.BinaryFieldStorage(body_file,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1646 headers=headers,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1647 environ=env)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1648 self.db.setCurrentUser('admin') # must be admin to create status
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1649 results = self.server.dispatch(method,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1650 "/rest/data/status",
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1651 form)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1652
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1653 self.assertEqual(self.server.client.response_code, 400)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1654 json_dict = json.loads(b2s(results))
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1655 status=json_dict['error']['status']
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1656 msg=json_dict['error']['msg']
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1657 self.assertEqual(status, 400)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1658 self.assertEqual(msg, "X-HTTP-Method-Override: DElETE must be "
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1659 "used with POST method not %s."%method)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1660
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1661 # TEST #2
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1662 # DELETE: delete issue 1 via post tunnel
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1663 self.assertFalse(self.db.status.is_retired("1"))
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1664 etag = calculate_etag(self.db.status.getnode("1"),
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1665 self.db.config['WEB_SECRET_KEY'])
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1666 etagb = etag.strip ('"')
5744
d4de45cde106 Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents: 5743
diff changeset
1667 headers={"accept": "application/json; q=1.0, application/xml; q=0.75",
5743
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1668 "if-match": '"%s"'%etagb,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1669 "content-length": 0,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1670 "x-http-method-override": "DElETE"
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1671 }
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1672 self.headers=headers
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1673 body_file=BytesIO(b'') # FieldStorage needs a file
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1674 form = client.BinaryFieldStorage(body_file,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1675 headers=headers,
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1676 environ=env)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1677 self.server.client.request.headers.get=self.get_header
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1678 self.db.setCurrentUser('admin') # must be admin to delete issue
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1679 results = self.server.dispatch('POST',
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1680 "/rest/data/status/1",
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1681 form)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1682 print(results)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1683 self.assertEqual(self.server.client.response_code, 200)
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1684 json_dict = json.loads(b2s(results))
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1685 status=json_dict['data']['status']
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1686 self.assertEqual(status, 'ok')
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1687 self.assertTrue(self.db.status.is_retired("1"))
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1688
60299cd36670 Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents: 5742
diff changeset
1689
5711
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1690 def testPostPOE(self):
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1691 ''' test post once exactly: get POE url, create issue
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1692 using POE url. Use dispatch entry point.
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1693 '''
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1694 import time
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1695 # setup environment
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1696 etag = "not needed"
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1697 empty_body=b''
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1698 env = { "CONTENT_TYPE": "application/json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1699 "CONTENT_LENGTH": len(empty_body),
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1700 "REQUEST_METHOD": "POST"
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1701 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1702 headers={"accept": "application/json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1703 "content-type": env['CONTENT_TYPE'],
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1704 "content-length": len(empty_body)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1705 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1706 self.headers=headers
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1707 # use empty_body to test code path for missing/empty json
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1708 body_file=BytesIO(empty_body) # FieldStorage needs a file
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1709 form = client.BinaryFieldStorage(body_file,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1710 headers=headers,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1711 environ=env)
5710
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1712
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1713 ## Obtain the POE url.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1714 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1715 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1716 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1717 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1718
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1719 self.assertEqual(self.server.client.response_code, 200)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1720 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1721 url=json_dict['data']['link']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1722
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1723 # strip tracker web prefix leaving leading /.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1724 url = url[len(self.db.config['TRACKER_WEB'])-1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1725
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1726 ## create an issue using poe url.
5711
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1727 body=b'{ "title": "foo bar", "priority": "critical" }'
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1728 env = { "CONTENT_TYPE": "application/json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1729 "CONTENT_LENGTH": len(body),
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1730 "REQUEST_METHOD": "POST"
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1731 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1732 headers={"accept": "application/json",
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1733 "content-type": env['CONTENT_TYPE'],
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1734 "content-length": len(body)
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1735 }
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1736 self.headers=headers
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1737 body_file=BytesIO(body) # FieldStorage needs a file
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1738 form = client.BinaryFieldStorage(body_file,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1739 headers=headers,
aea2cc142c1b Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents: 5710
diff changeset
1740 environ=env)
5710
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1741 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1742 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1743 url,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1744 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1745
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1746 self.assertEqual(self.server.client.response_code, 201)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1747 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1748 issue_id=json_dict['data']['id']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1749 results = self.server.get_element('issue',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1750 str(issue_id), # must be a string not unicode
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1751 self.empty_form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1752 self.assertEqual(self.dummy_client.response_code, 200)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1753 self.assertEqual(results['data']['attributes']['title'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1754 'foo bar')
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1755
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1756 ## Reuse POE url. It will fail.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1757 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1758 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1759 url,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1760 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1761 # get the last component stripping the trailing /
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1762 poe=url[url.rindex('/')+1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1763 self.assertEqual(self.server.client.response_code, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1764 results = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1765 self.assertEqual(results['error']['status'], 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1766 self.assertEqual(results['error']['msg'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1767 "POE token \'%s\' not valid."%poe)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1768
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1769 ## Try using GET on POE url. Should fail with method not
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1770 ## allowed (405)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1771 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1772 results = self.server.dispatch('GET',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1773 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1774 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1775 self.assertEqual(self.server.client.response_code, 405)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1776
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1777
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1778 ## Try creating generic POE url.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1779 body_poe=b'{"generic": "null", "lifetime": "100" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1780 body_file=BytesIO(body_poe) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1781 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1782 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1783 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1784 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1785 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1786 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1787 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1788 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1789 url=json_dict['data']['link']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1790
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1791 # strip tracker web prefix leaving leading /.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1792 url = url[len(self.db.config['TRACKER_WEB'])-1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1793 url = url.replace('/issue/', '/keyword/')
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1794
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1795 body_keyword=b'{"name": "keyword"}'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1796 body_file=BytesIO(body_keyword) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1797 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1798 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1799 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1800 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1801 url,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1802 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1803 self.assertEqual(self.server.client.response_code, 201)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1804 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1805 url=json_dict['data']['link']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1806 id=json_dict['data']['id']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1807 self.assertEqual(id, "1")
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1808 self.assertEqual(url, "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/keyword/1")
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1809
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1810 ## Create issue POE url and try to use for keyword.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1811 ## This should fail.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1812 body_poe=b'{"lifetime": "100" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1813 body_file=BytesIO(body_poe) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1814 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1815 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1816 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1817 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1818 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1819 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1820 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1821 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1822 url=json_dict['data']['link']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1823
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1824 # strip tracker web prefix leaving leading /.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1825 url = url[len(self.db.config['TRACKER_WEB'])-1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1826 url = url.replace('/issue/', '/keyword/')
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1827
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1828 body_keyword=b'{"name": "keyword"}'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1829 body_file=BytesIO(body_keyword) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1830 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1831 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1832 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1833 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1834 url,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1835 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1836 poe=url[url.rindex('/')+1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1837 self.assertEqual(self.server.client.response_code, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1838 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1839 stat=json_dict['error']['status']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1840 msg=json_dict['error']['msg']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1841 self.assertEqual(stat, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1842 self.assertEqual(msg, "POE token '%s' not valid for keyword, was generated for class issue"%poe)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1843
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1844
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1845 ## Create POE with 10 minute lifetime and verify
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1846 ## expires is within 10 minutes.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1847 body_poe=b'{"lifetime": "30" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1848 body_file=BytesIO(body_poe) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1849 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1850 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1851 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1852 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1853 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1854 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1855 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1856 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1857 expires=int(json_dict['data']['expires'])
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1858 # allow up to 3 seconds between time stamp creation
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1859 # done under dispatch and this point.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1860 expected=int(time.time() + 30)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1861 print("expected=%d, expires=%d"%(expected,expires))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1862 self.assertTrue((expected - expires) < 3 and (expected - expires) >= 0)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1863
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1864
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1865 ## Use a token created above as joe by a different user.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1866 self.db.setCurrentUser('admin')
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1867 url=json_dict['data']['link']
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1868 # strip tracker web prefix leaving leading /.
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1869 url = url[len(self.db.config['TRACKER_WEB'])-1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1870 body_file=BytesIO(body_keyword) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1871 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1872 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1873 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1874 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1875 url,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1876 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1877 print(results)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1878 self.assertEqual(self.server.client.response_code, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1879 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1880 # get the last component stripping the trailing /
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1881 poe=url[url.rindex('/')+1:]
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1882 self.assertEqual(json_dict['error']['msg'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1883 "POE token '%s' not valid."%poe)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1884
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1885 ## Create POE with bogus lifetime
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1886 body_poe=b'{"lifetime": "10.2" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1887 body_file=BytesIO(body_poe) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1888 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1889 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1890 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1891 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1892 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1893 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1894 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1895 self.assertEqual(self.server.client.response_code, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1896 print(results)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1897 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1898 self.assertEqual(json_dict['error']['msg'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1899 "Value \'lifetime\' must be an integer specify "
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1900 "lifetime in seconds. Got 10.2.")
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1901
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1902 ## Create POE with lifetime > 1 hour
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1903 body_poe=b'{"lifetime": "3700" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1904 body_file=BytesIO(body_poe) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1905 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1906 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1907 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1908 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1909 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1910 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1911 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1912 self.assertEqual(self.server.client.response_code, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1913 print(results)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1914 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1915 self.assertEqual(json_dict['error']['msg'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1916 "Value 'lifetime' must be between 1 second and 1 "
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1917 "hour (3600 seconds). Got 3700.")
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1918
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1919 ## Create POE with lifetime < 1 second
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1920 body_poe=b'{"lifetime": "-1" }'
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1921 body_file=BytesIO(body_poe) # FieldStorage needs a file
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1922 form = client.BinaryFieldStorage(body_file,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1923 headers=headers,
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1924 environ=env)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1925 self.server.client.request.headers.get=self.get_header
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1926 results = self.server.dispatch('POST',
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1927 "/rest/data/issue/@poe",
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1928 form)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1929 self.assertEqual(self.server.client.response_code, 400)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1930 print(results)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1931 json_dict = json.loads(b2s(results))
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1932 self.assertEqual(json_dict['error']['msg'],
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1933 "Value 'lifetime' must be between 1 second and 1 "
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1934 "hour (3600 seconds). Got -1.")
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1935 del(self.headers)
0b79bfcb3312 Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents: 5708
diff changeset
1936
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1937 def testPutElement(self):
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1938 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1939 Change joe's 'realname'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1940 Check if we can't change admin's detail
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1941 """
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1942 # 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
1943 # no etag
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1944 form = cgi.FieldStorage()
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1945 form.list = [
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1946 cgi.MiniFieldStorage('data', 'Joe Doe Doe')
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1947 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1948 results = self.server.put_attribute(
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1949 'user', self.joeid, 'realname', form
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1950 )
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1951 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
1952 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
1953 '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
1954 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1955 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
1956 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
1957
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1958 # 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
1959 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1960 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1961 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1962 form.list = [
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1963 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
1964 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1965
5674
6dc4dba1c225 REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5673
diff changeset
1966 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
1967 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
1968 '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
1969 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
1970 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
1971 results = self.server.get_attribute(
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1972 '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
1973 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1974 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
1975 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
1976 del(self.headers)
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
1977
5643
a60cbbcc9309 Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents: 5639
diff changeset
1978 # 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
1979 # 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
1980 # 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
1981 # 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
1982 # having to filter out protected items.
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1983 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1984 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
1985 self.db.config['WEB_SECRET_KEY'])
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1986 form.list = [
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1987 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
1988 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
1989 cgi.MiniFieldStorage('@etag', etag)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1990 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
1991 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
1992 self.assertEqual(self.dummy_client.response_code, 200)
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
1993 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
1994 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
1995 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe')
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
1996
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
1997 # 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
1998 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
1999 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
2000 self.assertEqual(results['error']['status'], 403)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2001
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2002 # 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
2003 # 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
2004 # 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
2005 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2006 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2007 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2008 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2009 cgi.MiniFieldStorage('JustKidding', '3'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2010 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
2011 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2012 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2013 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
2014 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2015 '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
2016 'found in class user')}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2017 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
2018 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2019 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
2020 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2021 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
2022 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
2023 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
2024 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
2025
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2026 def testPutAttribute(self):
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2027 # put protected property
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2028 # 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
2029 self.db.setCurrentUser('admin')
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2030 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2031 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2032 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2033 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2034 cgi.MiniFieldStorage('data', '3'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2035 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2036 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2037 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
2038 '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
2039 )
5707
f9a762678af6 Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents: 5706
diff changeset
2040 expected= {'error': {'status': 405, 'msg':
f9a762678af6 Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents: 5706
diff changeset
2041 AttributeError('\'"creator", "actor", "creation" and '
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2042 '"activity" are reserved\'')}}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2043 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2044 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
2045 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2046 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
2047 type(expected['error']['msg']))
5707
f9a762678af6 Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents: 5706
diff changeset
2048 self.assertEqual(self.dummy_client.response_code, 405)
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2049
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2050 # put invalid property
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2051 # 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
2052 self.db.setCurrentUser('admin')
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2053 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2054 etag = calculate_etag(self.db.user.getnode(self.joeid),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2055 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2056 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2057 cgi.MiniFieldStorage('data', '3'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2058 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2059 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2060 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
2061 '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
2062 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2063 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2064 'msg': UsageError("'youMustBeKiddingMe' "
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2065 "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
2066 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2067 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
2068 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2069 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
2070 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2071 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
2072
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2073 def testPost(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2074 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2075 Post a new issue with title: foo
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2076 Verify the information of the created issue
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2077 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2078 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2079 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2080 cgi.MiniFieldStorage('title', 'foo')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2081 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2082 results = self.server.post_collection('issue', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2083 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
2084 issueid = results['data']['id']
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
2085 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
2086 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
2087 self.assertEqual(results['data']['attributes']['title'], 'foo')
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2088 self.assertEqual(self.db.issue.get(issueid, "tx_Source"), 'web')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2089
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2090 def testPostFile(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2091 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2092 Post a new file with content: hello\r\nthere
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2093 Verify the information of the created file
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2094 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2095 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2096 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2097 cgi.MiniFieldStorage('content', 'hello\r\nthere')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2098 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2099 results = self.server.post_collection('file', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2100 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
2101 fileid = results['data']['id']
5591
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
2102 results = self.server.get_element('file', fileid, self.empty_form)
a25d79e874cb Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5588
diff changeset
2103 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2104 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
2105 self.assertEqual(results['attributes']['content'],
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2106 {'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
2107
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2108 # File content is only shown with verbose=3
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2109 form = cgi.FieldStorage()
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2110 form.list = [
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2111 cgi.MiniFieldStorage('@verbose', '3')
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2112 ]
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2113 results = self.server.get_element('file', fileid, form)
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2114 results = results['data']
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2115 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2116 self.assertEqual(results['attributes']['content'], 'hello\r\nthere')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2117
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2118 def testAuthDeniedPut(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2119 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2120 Test unauthorized PUT request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2121 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2122 # Wrong permissions (caught by roundup security module).
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2123 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2124 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2125 cgi.MiniFieldStorage('realname', 'someone')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2126 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2127 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
2128 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
2129 self.assertEqual(results['error']['status'], 403)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2130
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2131 def testAuthDeniedPost(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2132 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2133 Test unauthorized POST request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2134 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2135 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2136 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2137 cgi.MiniFieldStorage('username', 'blah')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2138 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2139 results = self.server.post_collection('user', form)
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2140 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
2141 self.assertEqual(results['error']['status'], 403)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2142
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2143 def testAuthAllowedPut(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2144 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2145 Test authorized PUT request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2146 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2147 self.db.setCurrentUser('admin')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2148 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2149 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2150 cgi.MiniFieldStorage('realname', 'someone')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2151 ]
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2152 try:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2153 self.server.put_element('user', '2', form)
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
2154 except Unauthorised as err:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2155 self.fail('raised %s' % err)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2156 finally:
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2157 self.db.setCurrentUser('joe')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2158
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2159 def testAuthAllowedPost(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2160 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2161 Test authorized POST request
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2162 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2163 self.db.setCurrentUser('admin')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2164 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2165 form.list = [
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2166 cgi.MiniFieldStorage('username', 'blah')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2167 ]
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2168 try:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2169 self.server.post_collection('user', form)
5602
c40d04915e23 Python3 fixes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5601
diff changeset
2170 except Unauthorised as err:
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2171 self.fail('raised %s' % err)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2172 finally:
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2173 self.db.setCurrentUser('joe')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2174
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2175 def testDeleteAttributeUri(self):
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2176 """
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2177 Test Delete an attribute
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2178 """
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2179 self.maxDiff = 4000
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2180 # 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
2181 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
2182
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2183 # 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
2184 # With no changes
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2185 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
2186 '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
2187 )
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2188 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
2189 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
2190 results = results['data']
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2191 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
2192 self.assertEqual(len(results['attributes']['nosy']), 1)
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2193 self.assertListEqual(results['attributes']['nosy'],
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2194 [{'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
2195
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2196 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2197 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2198 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2199 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
2200 # remove the title and nosy
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2201 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
2202 'issue', issue_id, 'title', form
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2203 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2204 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
2205
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2206 del(form.list[-1])
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2207 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2208 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2209 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
2210 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
2211 'issue', issue_id, 'nosy', form
5585
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2212 )
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2213 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
2214
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2215 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2216 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
2217 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2218 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
2219 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
2220 self.assertListEqual(results['attributes']['nosy'], [])
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2221 self.assertEqual(results['attributes']['title'], None)
8725c09802b8 Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5583
diff changeset
2222
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2223 # delete protected property
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2224 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2225 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2226 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
2227 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
2228 '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
2229 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2230 expected= {'error': {
5707
f9a762678af6 Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents: 5706
diff changeset
2231 'status': 405,
f9a762678af6 Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents: 5706
diff changeset
2232 'msg': AttributeError("Attribute 'creator' can not be updated for class issue.")
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2233 }}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2234
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2235 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
2236 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2237 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
2238 type(expected['error']['msg']))
5707
f9a762678af6 Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents: 5706
diff changeset
2239 self.assertEqual(self.dummy_client.response_code, 405)
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2240
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2241 # delete required property
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2242 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2243 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2244 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
2245 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
2246 '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
2247 )
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2248 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2249 '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
2250 "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
2251 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2252 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
2253 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2254 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
2255 type(expected['error']['msg']))
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2256 self.assertEqual(str(results['error']['msg']),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2257 str(expected['error']['msg']))
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2258 self.assertEqual(self.dummy_client.response_code, 400)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2259
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2260 # delete bogus property
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2261 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2262 self.db.config['WEB_SECRET_KEY'])
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2263 form.list.append(cgi.MiniFieldStorage('@etag', etag))
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2264 results = self.server.delete_attribute(
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2265 'issue', issue_id, 'nosuchprop', form
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2266 )
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2267 expected= {'error': {'status': 400,
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2268 'msg': UsageError("Attribute 'nosuchprop' not valid "
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2269 "for class issue.")}}
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2270 print(results)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2271 self.assertEqual(results['error']['status'],
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2272 expected['error']['status'])
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2273 self.assertEqual(type(results['error']['msg']),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2274 type(expected['error']['msg']))
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2275 self.assertEqual(str(results['error']['msg']),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2276 str(expected['error']['msg']))
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2277 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
2278
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2279 def testPatchAdd(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2280 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2281 Test Patch op 'Add'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2282 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2283 # create a new issue with userid 1 in the nosy list
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2284 issue_id = self.db.issue.create(title='foo', nosy=['1'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2285
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2286 # 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
2287 # no etag
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2288 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2289 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2290 cgi.MiniFieldStorage('@op', 'add'),
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2291 cgi.MiniFieldStorage('nosy', '2')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2292 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2293 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
2294 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
2295
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2296 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2297 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2298 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2299 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2300 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
2301 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
2302 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
2303 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2304 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
2305 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2306
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2307 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2308 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
2309 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2310 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2311 self.assertEqual(len(results['attributes']['nosy']), 2)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2312 self.assertListEqual(results['attributes']['nosy'], ['1', '2'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2313
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2314 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2315 self.db.config['WEB_SECRET_KEY'])
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2316 form = cgi.FieldStorage()
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2317 form.list = [
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2318 cgi.MiniFieldStorage('@op', 'add'),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2319 cgi.MiniFieldStorage('data', '3'),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2320 cgi.MiniFieldStorage('@etag', etag)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2321 ]
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2322 results = self.server.patch_attribute('issue', issue_id, 'nosy', form)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2323 self.assertEqual(self.dummy_client.response_code, 200)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2324
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2325 # verify the result
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2326 results = self.server.get_element('issue', issue_id, self.terse_form)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2327 results = results['data']
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2328 self.assertEqual(self.dummy_client.response_code, 200)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2329 self.assertEqual(len(results['attributes']['nosy']), 3)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2330 self.assertListEqual(results['attributes']['nosy'], ['1', '2', '3'])
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2331
5747
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2332 # patch with no new_val/data
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2333 etag = calculate_etag(self.db.issue.getnode(issue_id),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2334 self.db.config['WEB_SECRET_KEY'])
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2335 form = cgi.FieldStorage()
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2336 form.list = [
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2337 cgi.MiniFieldStorage('@op', 'add'),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2338 cgi.MiniFieldStorage('data', ''),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2339 cgi.MiniFieldStorage('@etag', etag)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2340 ]
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2341 results = self.server.patch_attribute('issue', issue_id, 'nosy', form)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2342 self.assertEqual(self.dummy_client.response_code, 200)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2343
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2344 # verify the result
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2345 results = self.server.get_element('issue', issue_id, self.terse_form)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2346 results = results['data']
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2347 self.assertEqual(self.dummy_client.response_code, 200)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2348 self.assertEqual(len(results['attributes']['nosy']), 3)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2349 self.assertListEqual(results['attributes']['nosy'], ['1', '2', '3'])
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2350
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2351 # patch invalid property
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2352 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2353 self.db.config['WEB_SECRET_KEY'])
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2354 form = cgi.FieldStorage()
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2355 form.list = [
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2356 cgi.MiniFieldStorage('@op', 'add'),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2357 cgi.MiniFieldStorage('data', '3'),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2358 cgi.MiniFieldStorage('@etag', etag)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2359 ]
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2360 results = self.server.patch_attribute('issue', issue_id, 'notGoingToWork', form)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2361 self.assertEqual(self.dummy_client.response_code, 400)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2362 print(results)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2363 expected={'error': {'status': 400,
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2364 'msg': UsageError(
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2365 HyperdbValueError(
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2366 "'notGoingToWork' is not a property of issue",),)}}
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2367 self.assertEqual(results['error']['status'],
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2368 expected['error']['status'])
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2369 self.assertEqual(type(results['error']['msg']),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2370 type(expected['error']['msg']))
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2371 self.assertEqual(str(results['error']['msg']),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2372 str(expected['error']['msg']))
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2373
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2374 def testPatchReplace(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2375 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2376 Test Patch op 'Replace'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2377 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2378 # 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
2379 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
2380
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2381 # 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
2382 # no etag.
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2383 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2384 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2385 cgi.MiniFieldStorage('@op', 'replace'),
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2386 cgi.MiniFieldStorage('nosy', '2'),
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2387 cgi.MiniFieldStorage('status', '3')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2388 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2389 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
2390 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
2391 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
2392 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2393 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
2394 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
2395 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
2396 self.assertListEqual(results['attributes']['nosy'], ['1'])
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2397
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2398 # replace userid 2 to the nosy list and status = 3
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2399 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2400 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2401 form = cgi.FieldStorage()
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2402 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2403 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
2404 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
2405 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
2406 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
2407 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2408 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
2409 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2410 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2411 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
2412 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2413 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2414 self.assertEqual(results['attributes']['status'], '3')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2415 self.assertEqual(len(results['attributes']['nosy']), 1)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2416 self.assertListEqual(results['attributes']['nosy'], ['2'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2417
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2418 # replace status = 2 using status attribute
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2419 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2420 self.db.config['WEB_SECRET_KEY'])
5706
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2421 form = cgi.FieldStorage()
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2422 form.list = [
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2423 cgi.MiniFieldStorage('@op', 'replace'),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2424 cgi.MiniFieldStorage('data', '2'),
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2425 cgi.MiniFieldStorage('@etag', etag)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2426 ]
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2427 results = self.server.patch_attribute('issue', issue_id, 'status',
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2428 form)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2429 self.assertEqual(self.dummy_client.response_code, 200)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2430 # verify the result
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2431 results = self.server.get_element('issue', issue_id, self.terse_form)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2432 results = results['data']
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2433 self.assertEqual(self.dummy_client.response_code, 200)
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2434 self.assertEqual(results['attributes']['status'], '2')
dfca6136dd7b Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents: 5705
diff changeset
2435
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2436 # try to set a protected prop. It should fail.
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2437 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2438 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2439 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2440 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2441 cgi.MiniFieldStorage('@op', 'replace'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2442 cgi.MiniFieldStorage('creator', '2'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2443 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2444 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2445 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
2446 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2447 '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
2448 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2449 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
2450 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2451 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
2452 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2453 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
2454 str(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2455 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
2456
5708
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2457 # try to set a protected prop using patch_attribute. It should
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2458 # fail with a 405 bad/unsupported method.
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2459 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2460 self.db.config['WEB_SECRET_KEY'])
5708
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2461 form = cgi.FieldStorage()
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2462 form.list = [
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2463 cgi.MiniFieldStorage('@op', 'replace'),
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2464 cgi.MiniFieldStorage('data', '2'),
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2465 cgi.MiniFieldStorage('@etag', etag)
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2466 ]
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2467 results = self.server.patch_attribute('issue', issue_id, 'creator',
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2468 form)
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2469 expected= {'error': {'status': 405,
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2470 'msg': AttributeError("Attribute 'creator' can not be updated for class issue.",)}}
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2471 print(results)
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2472 self.assertEqual(results['error']['status'],
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2473 expected['error']['status'])
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2474 self.assertEqual(type(results['error']['msg']),
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2475 type(expected['error']['msg']))
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2476 self.assertEqual(str(results['error']['msg']),
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2477 str(expected['error']['msg']))
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2478 self.assertEqual(self.dummy_client.response_code, 405)
ad786c394788 Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents: 5707
diff changeset
2479
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2480 def testPatchRemoveAll(self):
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2481 """
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2482 Test Patch Action 'Remove'
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2483 """
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2484 # 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
2485 issue_id = self.db.issue.create(title='foo', nosy=['1', '2'])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2486
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2487 # 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
2488 # no etag
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2489 form = cgi.FieldStorage()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2490 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2491 cgi.MiniFieldStorage('@op', 'remove'),
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2492 cgi.MiniFieldStorage('nosy', ''),
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2493 cgi.MiniFieldStorage('title', '')
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2494 ]
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2495 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
2496 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
2497 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
2498 results = results['data']
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2499 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
2500 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
2501 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
2502 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
2503
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2504 # 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
2505 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2506 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2507 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2508 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2509 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
2510 cgi.MiniFieldStorage('nosy', ''),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2511 cgi.MiniFieldStorage('title', ''),
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2512 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
2513 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2514 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
2515 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2516
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2517 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2518 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
2519 results = results['data']
5588
6b3a9655a7d9 Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5586
diff changeset
2520 self.assertEqual(self.dummy_client.response_code, 200)
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2521 self.assertEqual(results['attributes']['title'], None)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2522 self.assertEqual(len(results['attributes']['nosy']), 0)
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2523 self.assertEqual(results['attributes']['nosy'], [])
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2524
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2525 # try to remove a protected prop. It should fail.
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2526 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2527 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2528 form = cgi.FieldStorage()
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2529 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2530 cgi.MiniFieldStorage('@op', 'remove'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2531 cgi.MiniFieldStorage('creator', '2'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2532 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2533 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2534 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
2535 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2536 '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
2537 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2538 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
2539 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2540 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
2541 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2542 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
2543 str(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2544 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
2545
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2546 # try to remove a required prop. it should fail
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2547 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2548 self.db.config['WEB_SECRET_KEY'])
5705
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2549 form.list = [
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2550 cgi.MiniFieldStorage('@op', 'remove'),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2551 cgi.MiniFieldStorage('requireme', ''),
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2552 cgi.MiniFieldStorage('@etag', etag)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2553 ]
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2554 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
2555 expected= {'error': {'status': 400,
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2556 '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
2557 }}
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2558 print(results)
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2559 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
2560 expected['error']['status'])
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2561 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
2562 type(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2563 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
2564 str(expected['error']['msg']))
457fc482e6b1 Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents: 5690
diff changeset
2565 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
2566
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2567 def testPatchAction(self):
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2568 """
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2569 Test Patch Action 'Action'
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2570 """
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2571 # 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
2572 issue_id = self.db.issue.create(title='foo')
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2573
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2574 # 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
2575 # no etag
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2576 form = cgi.FieldStorage()
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2577 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2578 cgi.MiniFieldStorage('@op', 'action'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2579 cgi.MiniFieldStorage('@action_name', 'retire')
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2580 ]
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2581 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
2582 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
2583 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
2584
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2585 # execute action retire
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2586 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2587 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2588 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2589 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2590 cgi.MiniFieldStorage('@op', 'action'),
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2591 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
2592 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
2593 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2594 results = self.server.patch_element('issue', issue_id, form)
5599
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2595 self.assertEqual(self.dummy_client.response_code, 200)
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2596
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2597 # verify the result
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2598 self.assertTrue(self.db.issue.is_retired(issue_id))
a76d88673375 Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5595
diff changeset
2599
5747
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2600 # execute action restore
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2601 form = cgi.FieldStorage()
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2602 etag = calculate_etag(self.db.issue.getnode(issue_id),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2603 self.db.config['WEB_SECRET_KEY'])
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2604 form.list = [
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2605 cgi.MiniFieldStorage('@op', 'action'),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2606 cgi.MiniFieldStorage('@action_name', 'restore'),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2607 cgi.MiniFieldStorage('@etag', etag)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2608 ]
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2609 results = self.server.patch_element('issue', issue_id, form)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2610 self.assertEqual(self.dummy_client.response_code, 200)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2611
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2612 # verify the result
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2613 self.assertTrue(not self.db.issue.is_retired(issue_id))
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2614
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2615 def testPatchRemove(self):
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2616 """
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2617 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
2618 """
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2619 # 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
2620 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
2621
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2622 # 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
2623 # no etag
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2624 form = cgi.FieldStorage()
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2625 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2626 cgi.MiniFieldStorage('@op', 'remove'),
5595
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2627 cgi.MiniFieldStorage('nosy', '1, 2'),
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2628 ]
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2629 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
2630 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
2631 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
2632 results = results['data']
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2633 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
2634 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
2635 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
2636
5747
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2637 # remove 1 and 2 from the nosy list
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2638 form = cgi.FieldStorage()
5727
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2639 etag = calculate_etag(self.db.issue.getnode(issue_id),
8b5171f353eb issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents: 5726
diff changeset
2640 self.db.config['WEB_SECRET_KEY'])
5630
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2641 form.list = [
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2642 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
2643 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
2644 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
2645 ]
07abc8d36940 Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents: 5623
diff changeset
2646 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
2647 self.assertEqual(self.dummy_client.response_code, 200)
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2648
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2649 # verify the result
5672
a7211712b110 Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5656
diff changeset
2650 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
2651 results = results['data']
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2652 self.assertEqual(self.dummy_client.response_code, 200)
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2653 self.assertEqual(len(results['attributes']['nosy']), 1)
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2654 self.assertEqual(results['attributes']['nosy'], ['3'])
65caddd54da2 Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5592
diff changeset
2655
5747
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2656 # delete last element: 3
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2657 etag = calculate_etag(self.db.issue.getnode(issue_id),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2658 self.db.config['WEB_SECRET_KEY'])
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2659 form = cgi.FieldStorage()
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2660 form.list = [
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2661 cgi.MiniFieldStorage('@op', 'remove'),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2662 cgi.MiniFieldStorage('data', '3'),
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2663 cgi.MiniFieldStorage('@etag', etag)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2664 ]
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2665 results = self.server.patch_attribute('issue', issue_id, 'nosy', form)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2666 self.assertEqual(self.dummy_client.response_code, 200)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2667
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2668 # verify the result
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2669 results = self.server.get_element('issue', issue_id, self.terse_form)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2670 results = results['data']
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2671 self.assertEqual(self.dummy_client.response_code, 200)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2672 self.assertEqual(len(results['attributes']['nosy']), 0)
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2673 self.assertListEqual(results['attributes']['nosy'], [])
17b38e209307 Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents: 5746
diff changeset
2674
5586
8f2fbc88e155 Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5585
diff changeset
2675
5592
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
2676 def get_obj(path, id):
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
2677 return {
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
2678 'id': id,
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
2679 'link': path + id
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
2680 }
adcb5cbe82bd Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents: 5591
diff changeset
2681
5583
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2682 if __name__ == '__main__':
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2683 runner = unittest.TextTestRunner()
c65d98a16780 Added rest unit test
Chau Nguyen <dangchau1991@yahoo.com>
parents:
diff changeset
2684 unittest.main(testRunner=runner)

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