Mercurial > p > roundup > code
annotate test/rest_common.py @ 5879:94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
issue2551058: Add new permissions: 'Rest Access' and 'Xmlrpc Access'
to allow per-user access control to rest and xmlrpc interfaces using
roles.
Updated all schemas to add these new perms to all authenticated roles.
Error conditions in handle_xmlrpc were not working right in manual
testing. I tried to make it a little better, but I don't actually
understand how the fault xmlrpc object is supposed to be used. So I
may have messed something up. I'll try to ping the people who wrote
the xmlrpc code to have them review.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 27 Sep 2019 23:29:59 -0400 |
| parents | 1b57d8f3eb97 |
| children | 5d0873a4de4a |
| 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 | 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 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
8 from datetime import datetime, timedelta |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
9 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
10 try: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
11 from datetime import timezone |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
12 myutc = timezone.utc |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
13 except ImportError: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
14 # python 2 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
15 from datetime import tzinfo |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
16 ZERO = timedelta(0) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
17 class UTC(tzinfo): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
18 """UTC""" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
19 def utcoffset(self, dt): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
20 return ZERO |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
21 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
22 def tzname(self, dt): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
23 return "UTC" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
24 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
25 def dst(self, dt): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
26 return ZERO |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
27 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
28 myutc = UTC() |
|
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
|
29 |
| 5583 | 30 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
|
31 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
|
32 from roundup.exceptions import * |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
33 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
|
34 from roundup.rest import RestfulInstance, calculate_etag |
| 5583 | 35 from roundup.backends import list_backends |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
36 from roundup.cgi import client |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
37 from roundup.anypy.strings import b2s, s2b |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
38 import random |
| 5583 | 39 |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
40 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
|
41 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
|
42 |
| 5602 | 43 from .db_test_base import setupTracker |
| 5583 | 44 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
45 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
|
46 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
47 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
|
48 import json |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
49 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
50 from copy import copy |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
51 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
52 try: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
53 import jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
54 skip_jwt = lambda func, *args, **kwargs: func |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
55 except ImportError: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
56 from .pytest_patcher import mark_class |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
57 jwt=None |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
58 skip_jwt = mark_class(pytest.mark.skip( |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
59 reason='Skipping JWT tests: jwt library not available')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
60 |
| 5583 | 61 NEEDS_INSTANCE = 1 |
| 62 | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
63 |
|
5601
fcbeff272828
Integrate REST tests into db framework
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5600
diff
changeset
|
64 class TestCase(): |
| 5583 | 65 |
| 66 backend = None | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
67 url_pfx = 'http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/' |
| 5583 | 68 |
| 69 def setUp(self): | |
| 70 self.dirname = '_test_rest' | |
| 71 # set up and open a tracker | |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
72 # Set optimize=True as code under test (Client.main()::determine_user) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
73 # will close and re-open the database on user changes. This wipes |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
74 # out additions to the schema needed for testing. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
75 self.instance = setupTracker(self.dirname, self.backend, optimize=True) |
| 5583 | 76 |
| 77 # open the database | |
| 78 self.db = self.instance.open('admin') | |
| 79 | |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
80 # 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
|
81 # 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
|
82 # 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
|
83 # 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
|
84 # 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
|
85 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
|
86 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
|
87 |
| 5583 | 88 # Get user id (user4 maybe). Used later to get data from db. |
| 89 self.joeid = self.db.user.create( | |
| 90 username='joe', | |
| 91 password=password.Password('random'), | |
| 92 address='random@home.org', | |
| 93 realname='Joe Random', | |
| 94 roles='User' | |
| 95 ) | |
| 96 | |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
97 self.db.user.set('1', address="admin@admin.com") |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
98 self.db.user.set('2', address="anon@admin.com") |
| 5583 | 99 self.db.commit() |
| 100 self.db.close() | |
| 101 self.db = self.instance.open('joe') | |
| 5604 | 102 # Allow joe to retire |
| 103 p = self.db.security.addPermission(name='Retire', klass='issue') | |
| 104 self.db.security.addPermissionToRole('User', p) | |
| 5583 | 105 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
106 # add set of roles for testing jwt's. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
107 self.db.security.addRole(name="User:email", |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
108 description="allow email by jwt") |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
109 # allow the jwt to access everybody's email addresses. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
110 # this makes it easier to differentiate between User and |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
111 # User:email roles by accessing the /rest/data/user |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
112 # endpoint |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
113 jwt_perms = self.db.security.addPermission(name='View', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
114 klass='user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
115 properties=('id', 'realname', 'address', 'username'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
116 description="Allow jwt access to email", |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
117 props_only=False) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
118 self.db.security.addPermissionToRole("User:email", jwt_perms) |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
119 self.db.security.addPermissionToRole("User:email", "Rest Access") |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
120 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
121 # add set of roles for testing jwt's. |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
122 # this is like the user:email role, but it missing access to the rest endpoint. |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
123 self.db.security.addRole(name="User:emailnorest", |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
124 description="allow email by jwt") |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
125 jwt_perms = self.db.security.addPermission(name='View', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
126 klass='user', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
127 properties=('id', 'realname', 'address', 'username'), |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
128 description="Allow jwt access to email but forget to allow rest", |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
129 props_only=False) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
130 self.db.security.addPermissionToRole("User:emailnorest", jwt_perms) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
131 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
132 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
133 if jwt: |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
134 # must be 32 chars in length minimum (I think this is at least |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
135 # 256 bits of data) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
136 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
137 secret = "TestingTheJwtSecretTestingTheJwtSecret" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
138 self.db.config['WEB_JWT_SECRET'] = secret |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
139 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
140 # generate all timestamps in UTC. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
141 base_datetime = datetime(1970,1,1, tzinfo=myutc) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
142 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
143 # A UTC timestamp for now. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
144 dt = datetime.now(myutc) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
145 now_ts = int((dt - base_datetime).total_seconds()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
146 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
147 # one good for a minute |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
148 dt = dt + timedelta(seconds=60) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
149 plus1min_ts = int((dt - base_datetime).total_seconds()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
150 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
151 # one that expired a minute ago |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
152 dt = dt - timedelta(seconds=120) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
153 expired_ts = int((dt - base_datetime).total_seconds()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
154 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
155 # claims match what cgi/client.py::determine_user |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
156 # is looking for |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
157 claim= { 'sub': self.db.getuid(), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
158 'iss': self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
159 'aud': self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
160 'roles': [ 'User' ], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
161 'iat': now_ts, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
162 'exp': plus1min_ts, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
163 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
164 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
165 self.jwt = {} |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
166 self.claim = {} |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
167 # generate invalid claim with expired timestamp |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
168 self.claim['expired'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
169 self.claim['expired']['exp'] = expired_ts |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
170 self.jwt['expired'] = b2s(jwt.encode(self.claim['expired'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
171 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
172 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
173 # generate valid claim with user role |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
174 self.claim['user'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
175 self.claim['user']['exp'] = plus1min_ts |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
176 self.jwt['user'] = b2s(jwt.encode(self.claim['user'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
177 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
178 # generate invalid claim bad issuer |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
179 self.claim['badiss'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
180 self.claim['badiss']['iss'] = "http://someissuer/bugs" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
181 self.jwt['badiss'] = b2s(jwt.encode(self.claim['badiss'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
182 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
183 # generate invalid claim bad aud(ience) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
184 self.claim['badaud'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
185 self.claim['badaud']['aud'] = "http://someaudience/bugs" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
186 self.jwt['badaud'] = b2s(jwt.encode(self.claim['badaud'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
187 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
188 # generate invalid claim bad sub(ject) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
189 self.claim['badsub'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
190 self.claim['badsub']['sub'] = str("99") |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
191 self.jwt['badsub'] = b2s(jwt.encode(self.claim['badsub'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
192 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
193 # generate invalid claim bad roles |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
194 self.claim['badroles'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
195 self.claim['badroles']['roles'] = [ "badrole1", "badrole2" ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
196 self.jwt['badroles'] = b2s(jwt.encode(self.claim['badroles'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
197 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
198 # generate valid claim with limited user:email role |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
199 self.claim['user:email'] = copy(claim) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
200 self.claim['user:email']['roles'] = [ "user:email" ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
201 self.jwt['user:email'] = b2s(jwt.encode(self.claim['user:email'], secret, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
202 algorithm='HS256')) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
203 |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
204 # generate valid claim with limited user:emailnorest role |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
205 self.claim['user:emailnorest'] = copy(claim) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
206 self.claim['user:emailnorest']['roles'] = [ "user:emailnorest" ] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
207 self.jwt['user:emailnorest'] = b2s(jwt.encode(self.claim['user:emailnorest'], secret, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
208 algorithm='HS256')) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
209 |
| 5583 | 210 self.db.tx_Source = 'web' |
| 211 | |
| 212 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
|
213 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
|
214 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
|
215 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
|
216 self.db.issue.addprop(requireme=hyperdb.String(required=True)) |
| 5583 | 217 self.db.msg.addprop(tx_Source=hyperdb.String()) |
| 218 | |
| 219 self.db.post_init() | |
| 220 | |
| 221 thisdir = os.path.dirname(__file__) | |
| 222 vars = {} | |
| 5602 | 223 with open(os.path.join(thisdir, "tx_Source_detector.py")) as f: |
| 224 code = compile(f.read(), "tx_Source_detector.py", "exec") | |
| 225 exec(code, vars) | |
| 5583 | 226 vars['init'](self.db) |
| 227 | |
| 228 env = { | |
| 229 'PATH_INFO': 'http://localhost/rounduptest/rest/', | |
| 230 'HTTP_HOST': 'localhost', | |
| 231 'TRACKER_NAME': 'rounduptest' | |
| 232 } | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
233 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
|
234 self.dummy_client.request.headers.get = self.get_header |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
235 self.empty_form = cgi.FieldStorage() |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
236 self.terse_form = cgi.FieldStorage() |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
237 self.terse_form.list = [ |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
238 cgi.MiniFieldStorage('@verbose', '0'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
239 ] |
| 5583 | 240 |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
241 self.server = RestfulInstance(self.dummy_client, self.db) |
| 5583 | 242 |
|
5710
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
243 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
|
244 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
245 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
|
246 |
| 5583 | 247 def tearDown(self): |
| 248 self.db.close() | |
| 249 try: | |
| 250 shutil.rmtree(self.dirname) | |
| 5602 | 251 except OSError as error: |
| 5583 | 252 if error.errno not in (errno.ENOENT, errno.ESRCH): |
| 253 raise | |
| 254 | |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
255 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
|
256 try: |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
257 return self.headers[header.lower()] |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
258 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
|
259 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
|
260 |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
261 def create_stati(self): |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
262 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
263 self.db.status.create(name='open', order='9') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
264 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
265 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
266 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
267 self.db.status.create(name='closed', order='91') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
268 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
269 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
270 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
271 self.db.priority.create(name='normal') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
272 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
273 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
274 try: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
275 self.db.priority.create(name='critical') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
276 except ValueError: |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
277 pass |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
278 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
279 def create_sampledata(self): |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
280 """ Create sample data common to some test cases |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
281 """ |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
282 self.create_stati() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
283 self.db.issue.create( |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
284 title='foo1', |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
285 status=self.db.status.lookup('open'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
286 priority=self.db.priority.lookup('normal'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
287 nosy = [ "1", "2" ] |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
288 ) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
289 issue_open_norm = self.db.issue.create( |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
290 title='foo2', |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
291 status=self.db.status.lookup('open'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
292 priority=self.db.priority.lookup('normal'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
293 assignedto = "3" |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
294 ) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
295 issue_open_crit = self.db.issue.create( |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
296 title='foo5', |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
297 status=self.db.status.lookup('open'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
298 priority=self.db.priority.lookup('critical') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
299 ) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
300 |
| 5583 | 301 def testGet(self): |
| 302 """ | |
| 303 Retrieve all three users | |
| 304 obtain data for 'joe' | |
| 305 """ | |
| 306 # Retrieve all three users. | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 self.assertEqual( |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
313 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
|
314 "3" |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
315 ) |
| 5583 | 316 |
| 317 # Obtain data for 'joe'. | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
318 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
|
319 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
320 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 321 self.assertEqual(results['attributes']['username'], 'joe') |
| 322 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 323 | |
| 5678 | 324 # Obtain data for 'joe' via username lookup. |
| 325 results = self.server.get_element('user', 'joe', self.empty_form) | |
| 326 results = results['data'] | |
| 327 self.assertEqual(self.dummy_client.response_code, 200) | |
| 328 self.assertEqual(results['attributes']['username'], 'joe') | |
| 329 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 330 | |
| 331 # Obtain data for 'joe' via username lookup (long form). | |
| 332 key = 'username=joe' | |
| 333 results = self.server.get_element('user', key, self.empty_form) | |
| 334 results = results['data'] | |
| 335 self.assertEqual(self.dummy_client.response_code, 200) | |
| 336 self.assertEqual(results['attributes']['username'], 'joe') | |
| 337 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 338 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
339 # Obtain data for 'joe'. |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
340 results = self.server.get_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
341 '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
|
342 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
343 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
|
344 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
|
345 |
|
5872
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
346 def testGetTransitive(self): |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
347 """ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
348 Retrieve all issues with an 'o' in status |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
349 sort by status.name (not order) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
350 """ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
351 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
352 #self.maxDiff=None |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
353 self.create_sampledata() |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
354 self.db.issue.set('2', status=self.db.status.lookup('closed')) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
355 self.db.issue.set('3', status=self.db.status.lookup('chatting')) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
356 expected={'data': |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
357 {'@total_size': 2, |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
358 'collection': [ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
359 { 'id': '2', |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
360 'link': base_path + 'issue/2', |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
361 'status': |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
362 { 'id': '10', |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
363 'link': base_path + 'status/10' |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
364 } |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
365 }, |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
366 { 'id': '1', |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
367 'link': base_path + 'issue/1', |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
368 'status': |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
369 { 'id': '9', |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
370 'link': base_path + 'status/9' |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
371 } |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
372 }, |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
373 ]} |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
374 } |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
375 form = cgi.FieldStorage() |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
376 form.list = [ |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
377 cgi.MiniFieldStorage('status.name', 'o'), |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
378 cgi.MiniFieldStorage('@fields', 'status'), |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
379 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
380 ] |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
381 results = self.server.get_collection('issue', form) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
382 self.assertDictEqual(expected, results) |
|
1b91e3df3fd0
Implement transitive props for sort and filter
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5865
diff
changeset
|
383 |
|
5874
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
384 def testGetExactMatch(self): |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
385 """ Retrieve all issues with an exact title |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
386 """ |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
387 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
388 #self.maxDiff=None |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
389 self.create_sampledata() |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
390 self.db.issue.set('2', title='This is an exact match') |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
391 self.db.issue.set('3', title='This is an exact match') |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
392 self.db.issue.set('1', title='This is AN exact match') |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
393 expected={'data': |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
394 {'@total_size': 2, |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
395 'collection': [ |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
396 { 'id': '2', |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
397 'link': base_path + 'issue/2', |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
398 }, |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
399 { 'id': '3', |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
400 'link': base_path + 'issue/3', |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
401 }, |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
402 ]} |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
403 } |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
404 form = cgi.FieldStorage() |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
405 form.list = [ |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
406 cgi.MiniFieldStorage('title:', 'This is an exact match'), |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
407 cgi.MiniFieldStorage('@sort', 'status.name'), |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
408 ] |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
409 results = self.server.get_collection('issue', form) |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
410 self.assertDictEqual(expected, results) |
|
6630baff5f68
Implement exact string search in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5872
diff
changeset
|
411 |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
412 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
|
413 """ 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
|
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 self.maxDiff = 4000 |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
416 self.create_sampledata() |
|
5682
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
417 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
|
418 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
419 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
420 # 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
|
421 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
|
422 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
|
423 cgi.MiniFieldStorage('status', 'open'), |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
424 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
|
425 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
|
426 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
427 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
428 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
|
429 {'@total_size': 3, |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
430 'collection': [ { |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
431 'creator': {'id': '3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
432 '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
|
433 'username': 'joe'}, |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
434 '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
|
435 '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
|
436 '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
|
437 '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
|
438 'nosy': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
439 {'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
|
440 '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
|
441 '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
|
442 {'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
|
443 '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
|
444 '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
|
445 ], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
446 '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
|
447 'title': 'foo1' }, |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
448 { 'creator': {'id': '3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
449 '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
|
450 'username': 'joe'}, |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
451 '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
|
452 '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
|
453 '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
|
454 '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
|
455 '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
|
456 'nosy': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
457 {'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
|
458 '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
|
459 '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
|
460 ], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
461 '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
|
462 'title': 'foo2'}, |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
463 {'creator': {'id': '3', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
464 '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
|
465 'username': 'joe'}, |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
466 '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
|
467 '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
|
468 '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
|
469 '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
|
470 '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
|
471 'nosy': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
472 '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
|
473 '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
|
474 ]}} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
475 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
476 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
|
477 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
|
478 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
479 # 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
|
480 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
|
481 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
|
482 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
|
483 # 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
|
484 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
485 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
486 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
|
487 {'@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
|
488 'collection': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
489 {'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
|
490 '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
|
491 { '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
|
492 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
493 '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
|
494 {'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
|
495 '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
|
496 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
497 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
498 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
|
499 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
|
500 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
501 # 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
507 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
508 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
|
509 '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
|
510 "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
|
511 '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
|
512 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
513 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
|
514 # 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
|
515 # 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
|
516 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
|
517 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
|
518 ) |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
519 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
520 # 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
|
521 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
527 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
528 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
|
529 '@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
|
530 'collection': [ |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
531 {'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
|
532 '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
|
533 '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
|
534 '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
|
535 '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
|
536 {'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
|
537 '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
|
538 '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
|
539 '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
|
540 '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
|
541 {'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
|
542 '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
|
543 '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
|
544 'nosy': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
545 '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
|
546 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
551 # 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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
557 # 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
|
558 # 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
|
559 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
|
560 {'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
|
561 '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
|
562 '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
|
563 {'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
|
564 '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
|
565 '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
|
566 {'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
|
567 '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
|
568 'queries': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
569 '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
|
570 '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
|
571 '@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
|
572 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
573 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
|
574 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
|
575 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
576 ## 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
|
577 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
|
578 form.list = [ |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
579 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
|
580 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
|
581 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
582 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
|
583 '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
|
584 '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
|
585 '@etag': '', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
586 '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
|
587 'attributes': { |
|
5825
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
588 'creator': {'id': '1', |
|
bcb894bc9740
Add test of protected values for collections and item.
John Rouillard <rouilj@ieee.org>
parents:
5801
diff
changeset
|
589 '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
|
590 '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
|
591 '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
|
592 'queries': [], |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
593 '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
|
594 } |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
595 }} |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
596 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
601 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
|
602 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
|
603 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
|
604 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
|
605 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
606 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
|
607 '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
|
608 '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
|
609 'attributes': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
610 'status': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
611 '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
|
612 '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
|
613 'priority': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
614 '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
|
615 '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
|
616 '@etag': '', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
617 '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
|
618 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
619 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
|
620 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
|
621 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
|
622 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
623 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
|
624 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
|
625 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
|
626 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
|
627 ] |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
628 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
|
629 '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
|
630 '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
|
631 'attributes': { |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
632 '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
|
633 '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
|
634 '@etag': '', |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
635 '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
|
636 |
|
e8ac82b8d074
Fix parse of @fields/@attrs with : as separator. Add tests @verbose and @fields.
John Rouillard <rouilj@ieee.org>
parents:
5678
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
641 def testSorting(self): |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
642 self.maxDiff = 4000 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
643 self.create_sampledata() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
644 self.db.issue.set('1', status='7') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
645 self.db.issue.set('2', status='2') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
646 self.db.issue.set('3', status='2') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
647 self.db.commit() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
648 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/issue/' |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
649 # change some data for sorting on later |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
650 form = cgi.FieldStorage() |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
651 form.list = [ |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
652 cgi.MiniFieldStorage('@fields', 'status'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
653 cgi.MiniFieldStorage('@sort', 'status,-id'), |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
654 cgi.MiniFieldStorage('@verbose', '0') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
655 ] |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
656 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
657 # status is sorted by orderprop (property 'order') |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
658 # which provides the same ordering as the status ID |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
659 expected={'data': { |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
660 '@total_size': 3, |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
661 'collection': [ |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
662 {'link': base_path + '3', 'status': '2', 'id': '3'}, |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
663 {'link': base_path + '2', 'status': '2', 'id': '2'}, |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
664 {'link': base_path + '1', 'status': '7', 'id': '1'}]}} |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
665 |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
666 results = self.server.get_collection('issue', form) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
667 self.assertDictEqual(expected, results) |
|
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
668 |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
669 def testFilter(self): |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
670 """ |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
671 Retrieve all three users |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
672 obtain data for 'joe' |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
673 """ |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
674 # create sample data |
|
5865
04deafac71ab
Implement sorting of collections in REST API
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5842
diff
changeset
|
675 self.create_stati() |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
676 self.db.issue.create( |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
677 title='foo4', |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
678 status=self.db.status.lookup('closed'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
679 priority=self.db.priority.lookup('critical') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
680 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
681 self.db.issue.create( |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
682 title='foo1', |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
683 status=self.db.status.lookup('open'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
684 priority=self.db.priority.lookup('normal') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
685 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
686 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
|
687 title='foo2 normal', |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
688 status=self.db.status.lookup('open'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
689 priority=self.db.priority.lookup('normal') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
690 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
691 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
|
692 title='foo3 closed normal', |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
693 status=self.db.status.lookup('closed'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
694 priority=self.db.priority.lookup('normal') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
695 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
696 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
|
697 title='foo4 closed', |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
698 status=self.db.status.lookup('closed'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
699 priority=self.db.priority.lookup('critical') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
700 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
701 issue_open_crit = self.db.issue.create( |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
702 title='foo5', |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
703 status=self.db.status.lookup('open'), |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
704 priority=self.db.priority.lookup('critical') |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
705 ) |
|
5623
1c4adab65faf
use config file setting for creating tracker uri
John Rouillard <rouilj@ieee.org>
parents:
5604
diff
changeset
|
706 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
|
707 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
708 # Retrieve all issue status=open |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
709 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
710 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
711 cgi.MiniFieldStorage('status', 'open') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
712 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
713 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
714 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
|
715 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
|
716 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
717 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
|
718 results['data']['collection']) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
719 self.assertNotIn( |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
720 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
|
721 results['data']['collection'] |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
722 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
723 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
724 # Retrieve all issue status=closed and priority=critical |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
725 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
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('status', 'closed'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
728 cgi.MiniFieldStorage('priority', 'critical') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
729 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
730 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
731 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
|
732 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
|
733 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
734 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
|
735 results['data']['collection']) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
736 self.assertNotIn( |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
737 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
|
738 results['data']['collection'] |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
739 ) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
740 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
741 # 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
|
742 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
743 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
744 cgi.MiniFieldStorage('status', 'closed'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
745 cgi.MiniFieldStorage('priority', 'normal,critical') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
746 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
747 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
748 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
|
749 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
|
750 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
751 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
|
752 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
753 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
|
754 results['data']['collection']) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
755 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
|
756 results['data']['collection']) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
757 |
|
5842
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
758 # 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
|
759 # 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
|
760 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
761 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
762 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
|
763 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
|
764 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
|
765 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
766 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
|
767 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
|
768 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
|
769 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
770 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
|
771 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
772 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
|
773 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
774 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
|
775 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
776 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
777 # 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
|
778 # 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
|
779 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
780 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
781 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
|
782 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
|
783 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
|
784 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
785 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
|
786 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
|
787 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
|
788 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
789 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
|
790 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
791 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
|
792 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
793 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
|
794 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
795 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
|
796 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
797 # 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
|
798 # 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
|
799 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
800 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
801 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
|
802 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
807 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
|
808 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
809 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
|
810 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
811 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
|
812 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
813 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
|
814 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
815 # 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
|
816 # 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
|
817 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
818 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
819 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
|
820 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
821 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
|
822 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
|
823 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
|
824 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
825 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
|
826 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
827 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
|
828 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
829 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
|
830 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
831 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
|
832 |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
833 # 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
|
834 form = cgi.FieldStorage() |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
835 form.list = [ |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
836 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
|
837 ] |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
838 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
|
839 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
|
840 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
|
841 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
842 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
|
843 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
844 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
|
845 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
846 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
|
847 results['data']['collection']) |
|
9c6617857032
Support use of duplicate rest filters keys. So URL's like:
John Rouillard <rouilj@ieee.org>
parents:
5825
diff
changeset
|
848 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
|
849 |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
850 def testPagination(self): |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
851 """ |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
852 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
|
853 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
|
854 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
|
855 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
|
856 number of items. |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
857 """ |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
858 # 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
|
859 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
|
860 self.db.issue.create(title='foo' + str(i)) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
861 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
862 # Retrieving all the issues |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
863 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
|
864 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
|
865 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
|
866 # 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
|
867 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
|
868 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
|
869 self.assertEqual( |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
870 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
|
871 str(total_length) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
872 ) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
873 |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
874 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
875 # 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
|
876 # 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
|
877 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
|
878 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
|
879 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
|
880 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
|
881 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
|
882 "bugs/rest/data/issue" |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
883 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
884 # Retrieve page 1 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
885 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
886 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
887 cgi.MiniFieldStorage('@page_size', page_size), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
888 cgi.MiniFieldStorage('@page_index', 1) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
889 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
890 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
891 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
|
892 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
|
893 page_one_expected) |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
894 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
|
895 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
|
896 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
|
897 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
|
898 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
|
899 "%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
|
900 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
|
901 "%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
|
902 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
903 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
|
904 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
905 # Retrieve page 2 |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
906 form = cgi.FieldStorage() |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
907 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
908 cgi.MiniFieldStorage('@page_size', page_size), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
909 cgi.MiniFieldStorage('@page_index', 2) |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
910 ] |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
911 results = self.server.get_collection('issue', form) |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
912 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
|
913 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
|
914 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
|
915 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
|
916 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
|
917 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
|
918 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
|
919 "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
|
920 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
|
921 "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
|
922 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
|
923 "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
|
924 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
|
925 'self') |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
926 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
|
927 'next') |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
928 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
|
929 'prev') |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
930 |
|
5639
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
931 # Retrieve page 3 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
932 form = cgi.FieldStorage() |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
933 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
934 cgi.MiniFieldStorage('@page_size', page_size), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
935 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
|
936 ] |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
937 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
|
938 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
|
939 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
|
940 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
|
941 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
|
942 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
|
943 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
|
944 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
|
945 "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
|
946 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
|
947 "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
|
948 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
949 # 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
|
950 # 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
|
951 form = cgi.FieldStorage() |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
952 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
953 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
|
954 ] |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
964 # 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
|
965 # is needed to: |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
966 # page_size < 0 |
|
f576957cbb1f
Add support for prev/next/self links when returning paginated results.
John Rouillard <rouilj@ieee.org>
parents:
5630
diff
changeset
|
967 # 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
|
968 |
|
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
|
969 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
|
970 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
971 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
|
972 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
|
973 |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
974 # 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
|
975 # 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
|
976 # 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
|
977 # 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
|
978 try: |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
979 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
|
980 except AttributeError: |
|
5cd9ac3daed7
Fixes for mysql and postgresql primary db.
John Rouillard <rouilj@ieee.org>
parents:
5733
diff
changeset
|
981 # 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
|
982 # 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
|
983 pass |
|
5733
62bdcb874433
Test code was not testing the loop that retries otk database updates
John Rouillard <rouilj@ieee.org>
parents:
5732
diff
changeset
|
984 |
|
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
|
985 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
|
986 # 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
|
987 # 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
|
988 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
|
989 # 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
|
990 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
|
991 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
|
992 "/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
|
993 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
|
994 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
995 # 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
|
996 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
|
997 # 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
|
998 # 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
|
999 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
|
1000 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
|
1001 # 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
|
1002 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
|
1003 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
|
1004 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
|
1005 ) |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1006 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1007 # 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
|
1008 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
|
1009 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
|
1010 "/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
|
1011 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
|
1012 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
|
1013 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
|
1014 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1015 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
|
1016 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
|
1017 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
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 # 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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 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
|
1030 "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
|
1031 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1032 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
|
1033 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
|
1034 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
|
1035 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
|
1036 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1037 # 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
|
1038 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
|
1039 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
|
1040 "/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
|
1041 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
|
1042 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
|
1043 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
|
1044 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
|
1045 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
|
1046 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
|
1047 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1048 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
|
1049 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1050 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
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 # 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
|
1062 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
|
1063 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
|
1064 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
|
1065 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1066 # 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
|
1067 # 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
|
1068 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
|
1069 "/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
|
1070 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
|
1071 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1072 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
|
1073 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
|
1074 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
|
1075 "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
|
1076 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1077 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
|
1078 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
|
1079 "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
|
1080 |
|
0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
John Rouillard <rouilj@ieee.org>
parents:
5729
diff
changeset
|
1081 # 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
|
1082 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
|
1083 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
|
1084 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1085 def testEtagGeneration(self): |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1086 ''' 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
|
1087 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1088 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
|
1089 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
|
1090 ''' |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1091 from roundup import date |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1092 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1093 originalDate = date.Date |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1094 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1095 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
|
1096 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1097 # 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
|
1098 def dummyDate(adate=None): |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1099 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
|
1100 return dummy |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1101 return dummyClosure |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1102 |
|
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1103 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
|
1104 try: |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1105 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
|
1106 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
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 ) |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1112 |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1113 # 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
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 print(etag) |
|
5729
9ea2ce9d10cf
A few internet references report that etags for the same underlying
John Rouillard <rouilj@ieee.org>
parents:
5728
diff
changeset
|
1119 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
|
1120 |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1121 # 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
|
1122 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
|
1123 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
|
1124 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
|
1125 print(etag) |
|
5729
9ea2ce9d10cf
A few internet references report that etags for the same underlying
John Rouillard <rouilj@ieee.org>
parents:
5728
diff
changeset
|
1126 self.assertNotEqual(etag, '"0433784660a141e8262835171e70fd2f"') |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1127 |
|
5728
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1128 # 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
|
1129 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
|
1130 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
|
1131 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
|
1132 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
|
1133 print(etag) |
|
5729
9ea2ce9d10cf
A few internet references report that etags for the same underlying
John Rouillard <rouilj@ieee.org>
parents:
5728
diff
changeset
|
1134 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
|
1135 finally: |
|
bfd28644fe43
In suggestion from Joseph Myers, put test code in a try: finally: block
John Rouillard <rouilj@ieee.org>
parents:
5727
diff
changeset
|
1136 date.Date = originalDate |
|
5668
a4bb88a1a643
A fix for https://issues.roundup-tracker.org/issue2551034
John Rouillard <rouilj@ieee.org>
parents:
5656
diff
changeset
|
1137 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1138 def testEtagProcessing(self): |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1139 ''' |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1140 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
|
1141 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
|
1142 @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
|
1143 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1144 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
|
1145 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
|
1146 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1147 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
|
1148 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
|
1149 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
|
1150 ''' |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1151 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
|
1152 'brokenheader', 'brokenetag', 'none'): |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1153 try: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1154 # 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
|
1155 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
|
1156 except AttributeError: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1157 pass |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1158 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1159 form = cgi.FieldStorage() |
|
5726
e199d0ae4a25
issue2551033: prevent reverse engineering hidden data by using etags
John Rouillard <rouilj@ieee.org>
parents:
5711
diff
changeset
|
1160 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
|
1161 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
|
1162 form.list = [ |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1163 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
|
1164 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1165 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1166 if mode == 'header': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1167 print("Mode = %s"%mode) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1168 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
|
1169 elif mode == 'etag': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1170 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
|
1171 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
|
1172 elif mode == 'both': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1173 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
|
1174 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
|
1175 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
|
1176 elif mode == 'brokenheader': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1177 print("Mode = %s"%mode) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1178 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
|
1179 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
|
1180 elif mode == 'brokenetag': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1181 print("Mode = %s"%mode) |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1182 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
|
1183 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
|
1184 elif mode == 'none': |
|
5645
7f4d19867123
Make print into function call for python3 compatibility.
John Rouillard <rouilj@ieee.org>
parents:
5643
diff
changeset
|
1185 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
|
1186 else: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1187 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
|
1188 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1189 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
|
1190 '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
|
1191 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1192 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
|
1193 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
|
1194 else: |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
1195 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
|
1196 |
|
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
|
1197 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
|
1198 """ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1199 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
|
1200 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
|
1201 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
|
1202 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
|
1203 """ |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1204 |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1205 # 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
|
1206 # 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
|
1207 # 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
|
1208 # 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
|
1209 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
|
1210 "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
|
1211 "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
|
1212 "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
|
1213 "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
|
1214 "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
|
1215 }' |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1216 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
|
1217 "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
|
1218 "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
|
1219 } |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1220 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
|
1221 "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
|
1222 "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
|
1223 } |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1224 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
|
1225 # 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
|
1226 # 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
|
1227 # 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
|
1228 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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 "/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
|
1235 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
|
1236 |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1237 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
|
1238 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
|
1239 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
|
1240 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
|
1241 "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
|
1242 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
|
1243 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
|
1244 "/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
|
1245 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
|
1246 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
|
1247 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
|
1248 "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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 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
|
1254 ['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
|
1255 "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
|
1256 |
|
4aae822e2cb4
Added a few comments and a test that fails with the pre-patched code
John Rouillard <rouilj@ieee.org>
parents:
5686
diff
changeset
|
1257 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1258 def testDispatch(self): |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1259 """ |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1260 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
|
1261 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
|
1262 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
|
1263 process. |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1264 """ |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1265 # TEST #1 |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1266 # 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
|
1267 # 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
|
1268 # 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
|
1269 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
|
1270 self.db.config['WEB_SECRET_KEY']) |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1271 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
|
1272 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
|
1273 "CONTENT_LENGTH": len(body), |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1274 "REQUEST_METHOD": "PUT" |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1275 } |
|
5686
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1276 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
|
1277 "content-type": env['CONTENT_TYPE'], |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1278 "content-length": env['CONTENT_LENGTH'], |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1279 "if-match": etag |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1280 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1281 self.headers=headers |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1282 # 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
|
1283 # 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
|
1284 # FieldStorage(None, None, []) |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1285 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
|
1286 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
|
1287 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1288 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1289 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
|
1290 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
|
1291 "/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
|
1292 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1293 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1294 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
|
1295 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
|
1296 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
|
1297 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
|
1298 '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
|
1299 |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1300 |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1301 # 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
|
1302 # 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
|
1303 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
|
1304 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
|
1305 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
|
1306 headers=headers, |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1307 environ=env) |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1308 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
|
1309 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
|
1310 "/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
|
1311 form) |
|
eb51c0d9c9bf
Move @apiver version extraction code after the input is parsed for
John Rouillard <rouilj@ieee.org>
parents:
5682
diff
changeset
|
1312 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
|
1313 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1314 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1315 # TEST #2 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1316 # 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
|
1317 # 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
|
1318 # 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
|
1319 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
|
1320 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
|
1321 etagb = etag.strip ('"') |
|
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1322 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
|
1323 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
|
1324 "CONTENT_LENGTH": len(body), |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1325 "REQUEST_METHOD": "PUT", |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1326 } |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1327 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
|
1328 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
|
1329 form = client.BinaryFieldStorage(body_file, |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1330 headers=None, |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1331 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1332 self.server.client.request.headers.get=self.get_header |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1333 |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1334 headers={"accept": "application/json", |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1335 "content-type": env['CONTENT_TYPE'], |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1336 "if-match": etag |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1337 } |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1338 self.headers=headers # set for dispatch |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1339 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1340 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
|
1341 "/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
|
1342 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1343 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1344 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
|
1345 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
|
1346 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
|
1347 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
|
1348 'Joe Doe 2') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1349 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1350 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1351 # TEST #3 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1352 # 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
|
1353 # 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
|
1354 # FieldStorage(None, None, []) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1355 # use etag from header |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1356 # |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1357 # 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
|
1358 # 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
|
1359 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
|
1360 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
|
1361 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
|
1362 "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
|
1363 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1364 form = cgi.FieldStorage() |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1365 form.list = [ |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1366 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
|
1367 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
|
1368 ] |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1369 self.headers = headers |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1370 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
|
1371 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
|
1372 "/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
|
1373 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1374 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
|
1375 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
|
1376 "/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
|
1377 self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1378 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
|
1379 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
|
1380 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1381 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
|
1382 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
|
1383 "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
|
1384 "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
|
1385 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
|
1386 "<type 'str'>")) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1387 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
|
1388 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1389 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1390 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1391 # TEST #4 |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1392 # 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
|
1393 # 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
|
1394 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
|
1395 self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1396 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
|
1397 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
1398 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
|
1399 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
|
1400 etagb = etag.strip ('"') |
|
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1401 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
|
1402 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
|
1403 "CONTENT_LENGTH": len(body), |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1404 "REQUEST_METHOD": "PATCH" |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1405 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1406 headers={"accept": "application/json", |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1407 "content-type": env['CONTENT_TYPE'], |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1408 "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
|
1409 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1410 self.headers=headers |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1411 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
|
1412 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
|
1413 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1414 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1415 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
|
1416 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
|
1417 "/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
|
1418 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1419 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1420 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
|
1421 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
|
1422 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
|
1423 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
|
1424 'demo2@example.com') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1425 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1426 # 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
|
1427 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
|
1428 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
|
1429 etagb = etag.strip ('"') |
|
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1430 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
|
1431 stored_results['data']['attributes']['address'], |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
1432 etagb)) |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1433 # 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
|
1434 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
|
1435 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
|
1436 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1437 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1438 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
|
1439 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
|
1440 "/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
|
1441 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1442 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1443 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
|
1444 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
|
1445 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
|
1446 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
|
1447 'random@home.org') |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1448 del(self.headers) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1449 |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1450 # TEST #5 |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1451 # POST: create new issue |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1452 # no etag needed |
|
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1453 etag = "not needed" |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1454 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
|
1455 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
|
1456 "CONTENT_LENGTH": len(body), |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1457 "REQUEST_METHOD": "POST" |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1458 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1459 headers={"accept": "application/json", |
|
5655
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1460 "content-type": env['CONTENT_TYPE'], |
|
207e0f5d551c
Merge in non-conflicting changes from ba67e397f063
John Rouillard <rouilj@ieee.org>
diff
changeset
|
1461 "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
|
1462 } |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1463 self.headers=headers |
|
5651
a02ef29b4242
Fix REST tests for Python 3.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5650
diff
changeset
|
1464 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
|
1465 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
|
1466 headers=headers, |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1467 environ=env) |
|
5650
e8ca7072c629
Fix Python 3 issues in REST code.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5647
diff
changeset
|
1468 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
|
1469 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
|
1470 "/rest/data/issue", |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1471 form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1472 |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1473 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
|
1474 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
|
1475 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
|
1476 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
|
1477 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
|
1478 self.empty_form) |
|
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
1479 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
|
1480 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
|
1481 'foo bar') |
|
5653
ba67e397f063
Fix string/bytes issues under python 3.
John Rouillard <rouilj@ieee.org>
parents:
5647
diff
changeset
|
1482 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1483 # TEST #6 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1484 # 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
|
1485 # 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
|
1486 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
|
1487 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
|
1488 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
|
1489 "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
|
1490 "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
|
1491 } |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1492 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
|
1493 "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
|
1494 "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
|
1495 } |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1496 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
|
1497 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
|
1498 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
|
1499 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1500 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
|
1501 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
|
1502 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
|
1503 "/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
|
1504 form) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1505 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1506 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
|
1507 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
|
1508 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
|
1509 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
|
1510 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
|
1511 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
|
1512 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1513 # TEST #7 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1514 # 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
|
1515 # 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
|
1516 # 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
|
1517 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
|
1518 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
|
1519 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
|
1520 "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
|
1521 "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
|
1522 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1523 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
|
1524 "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
|
1525 "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
|
1526 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1527 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
|
1528 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
|
1529 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
|
1530 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1531 environ=env) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1532 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
|
1533 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
|
1534 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
|
1535 "/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
|
1536 form) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1537 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1538 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
|
1539 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
|
1540 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
|
1541 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
|
1542 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
|
1543 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
|
1544 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1545 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1546 # TEST #8 |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1547 # 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
|
1548 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
|
1549 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
|
1550 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
|
1551 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
|
1552 "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
|
1553 "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
|
1554 # 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
|
1555 # .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
|
1556 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
|
1557 "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
|
1558 "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
|
1559 "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
|
1560 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1561 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
|
1562 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
|
1563 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
|
1564 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1565 environ=env) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1566 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
|
1567 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
|
1568 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
|
1569 "/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
|
1570 form) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1571 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
|
1572 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
|
1573 print(results) |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1574 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
|
1575 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
|
1576 |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1577 # TEST #9 |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1578 # 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
|
1579 # ... ; version=z |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1580 # or |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1581 # 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
|
1582 # or |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1583 # @apiver |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1584 # 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
|
1585 form = cgi.FieldStorage() |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1586 form.list = [ |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1587 cgi.MiniFieldStorage('@apiver', 'L'), |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1588 ] |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1589 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
|
1590 self.headers=headers |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1591 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
|
1592 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
|
1593 "/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
|
1594 print(results) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1595 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
|
1596 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
|
1597 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
|
1598 "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
|
1599 "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
|
1600 |
|
5741
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1601 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
|
1602 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
|
1603 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
|
1604 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
|
1605 "/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
|
1606 print(results) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1607 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
|
1608 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
|
1609 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
|
1610 "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
|
1611 "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
|
1612 |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1613 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
|
1614 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
|
1615 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
|
1616 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
|
1617 "/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
|
1618 print(results) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1619 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
|
1620 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
|
1621 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
|
1622 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
|
1623 "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
|
1624 "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
|
1625 |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1626 # 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
|
1627 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
|
1628 } |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1629 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
|
1630 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
|
1631 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
|
1632 "/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
|
1633 print(results) |
|
9c2e51aae18a
Test to make sure version selection via accept header is parsed correctly.
John Rouillard <rouilj@ieee.org>
parents:
5734
diff
changeset
|
1634 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
|
1635 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
|
1636 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
|
1637 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
|
1638 "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
|
1639 "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
|
1640 |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1641 # TEST #10 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1642 # 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
|
1643 expected_rest = { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1644 "data": { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1645 "supported_versions": [ |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1646 1 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1647 ], |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1648 "default_version": 1, |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1649 "links": [ |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1650 { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1651 "rel": "summary", |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1652 "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
|
1653 }, |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1654 { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1655 "rel": "self", |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1656 "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
|
1657 }, |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1658 { |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1659 "rel": "data", |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1660 "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
|
1661 } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1662 ] |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1663 } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1664 } |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1665 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1666 self.headers={} |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1667 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
|
1668 "/rest", self.empty_form) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1669 print(results) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1670 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
|
1671 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
|
1672 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
|
1673 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1674 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1675 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
|
1676 "/rest/", self.empty_form) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1677 print(results) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1678 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
|
1679 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
|
1680 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
|
1681 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1682 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
|
1683 "/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
|
1684 print(results) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1685 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
|
1686 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1687 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
|
1688 "/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
|
1689 print(results) |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1690 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
|
1691 |
| 5746 | 1692 expected_data = { |
| 1693 "data": { | |
| 1694 "issue": { | |
| 1695 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue" | |
| 1696 }, | |
| 1697 "priority": { | |
| 1698 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/priority" | |
| 1699 }, | |
| 1700 "user": { | |
| 1701 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user" | |
| 1702 }, | |
| 1703 "query": { | |
| 1704 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/query" | |
| 1705 }, | |
| 1706 "status": { | |
| 1707 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/status" | |
| 1708 }, | |
| 1709 "keyword": { | |
| 1710 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/keyword" | |
| 1711 }, | |
| 1712 "msg": { | |
| 1713 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/msg" | |
| 1714 }, | |
| 1715 "file": { | |
| 1716 "link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/file" | |
| 1717 } | |
| 1718 } | |
| 1719 } | |
| 1720 | |
| 1721 results = self.server.dispatch('GET', | |
| 1722 "/rest/data", self.empty_form) | |
| 1723 print(results) | |
| 1724 self.assertEqual(self.server.client.response_code, 200) | |
| 1725 results_dict = json.loads(b2s(results)) | |
| 1726 self.assertEqual(results_dict, expected_data) | |
| 1727 | |
| 1728 results = self.server.dispatch('GET', | |
| 1729 "/rest/data/", self.empty_form) | |
| 1730 print(results) | |
| 1731 self.assertEqual(self.server.client.response_code, 200) | |
| 1732 results_dict = json.loads(b2s(results)) | |
| 1733 self.assertEqual(results_dict, expected_data) | |
| 1734 | |
|
5742
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1735 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
|
1736 "/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
|
1737 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
|
1738 |
|
97d7faebef0a
Test @apiver version parsing using bogus version. Test /rest, /rest/
John Rouillard <rouilj@ieee.org>
parents:
5741
diff
changeset
|
1739 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
|
1740 "/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
|
1741 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
|
1742 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1743 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
|
1744 |
|
5744
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1745 def testAcceptHeaderParsing(self): |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1746 # TEST #1 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1747 # json highest priority |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1748 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
|
1749 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
|
1750 "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
|
1751 "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
|
1752 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1753 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1754 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
|
1755 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1756 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1757 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1758 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
|
1759 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
|
1760 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1761 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1762 # TEST #2 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1763 # text highest priority |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1764 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
|
1765 "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
|
1766 "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
|
1767 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1768 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1769 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
|
1770 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1771 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1772 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1773 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
|
1774 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
|
1775 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1776 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1777 # TEST #3 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1778 # no acceptable type |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1779 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
|
1780 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1781 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1782 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
|
1783 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1784 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1785 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1786 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
|
1787 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
|
1788 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1789 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1790 # TEST #4 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1791 # 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
|
1792 headers={} |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1793 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1794 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
|
1795 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1796 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1797 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1798 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
|
1799 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
|
1800 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1801 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1802 # TEST #5 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1803 # 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
|
1804 headers={ "accept": "*/*"} |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1805 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1806 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
|
1807 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1808 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1809 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1810 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
|
1811 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
|
1812 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1813 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1814 # TEST #6 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1815 # 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
|
1816 # 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
|
1817 # and errors. |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1818 # 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
|
1819 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
|
1820 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
|
1821 "*/*; 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
|
1822 "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
|
1823 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1824 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1825 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
|
1826 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1827 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1828 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1829 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
|
1830 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
|
1831 "application/json") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1832 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1833 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1834 ''' |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1835 # 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
|
1836 # not installed for testing |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1837 # TEST #7 |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1838 # xml wins |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1839 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
|
1840 "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
|
1841 "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
|
1842 } |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1843 self.headers=headers |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1844 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
|
1845 "/rest/data/status/1", |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1846 self.empty_form) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1847 print(results) |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1848 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
|
1849 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
|
1850 "application/xml") |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1851 ''' |
|
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1852 |
|
5743
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1853 def testMethodOverride(self): |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1854 # TEST #1 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1855 # 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
|
1856 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1857 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
|
1858 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
|
1859 "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
|
1860 "REQUEST_METHOD": "POST" |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1861 } |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1862 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
|
1863 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
|
1864 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
|
1865 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
|
1866 "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
|
1867 "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
|
1868 "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
|
1869 } |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1870 self.headers=headers |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1871 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
|
1872 headers=headers, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1873 environ=env) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1874 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
|
1875 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
|
1876 "/rest/data/status", |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1877 form) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1878 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1879 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
|
1880 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
|
1881 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
|
1882 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
|
1883 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
|
1884 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
|
1885 "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
|
1886 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1887 # TEST #2 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1888 # 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
|
1889 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
|
1890 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
|
1891 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
|
1892 etagb = etag.strip ('"') |
|
5744
d4de45cde106
Accept header parsing fixes. Now return first acceptable match rather
John Rouillard <rouilj@ieee.org>
parents:
5743
diff
changeset
|
1893 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
|
1894 "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
|
1895 "content-length": 0, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1896 "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
|
1897 } |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1898 self.headers=headers |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1899 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
|
1900 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
|
1901 headers=headers, |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1902 environ=env) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1903 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
|
1904 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
|
1905 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
|
1906 "/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
|
1907 form) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1908 print(results) |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1909 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
|
1910 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
|
1911 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
|
1912 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
|
1913 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
|
1914 |
|
60299cd36670
Basic tests for tunneling of methods via x-http-method-override.
John Rouillard <rouilj@ieee.org>
parents:
5742
diff
changeset
|
1915 |
|
5711
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1916 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
|
1917 ''' 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
|
1918 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
|
1919 ''' |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1920 import time |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1921 # setup environment |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1922 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
|
1923 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
|
1924 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
|
1925 "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
|
1926 "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
|
1927 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1928 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
|
1929 "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
|
1930 "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
|
1931 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1932 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
|
1933 # 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
|
1934 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
|
1935 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
|
1936 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1937 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
|
1938 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1939 ## 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
|
1940 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
|
1941 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
|
1942 "/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
|
1943 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1944 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1945 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
|
1946 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
|
1947 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
|
1948 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1949 # 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
|
1950 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
|
1951 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1952 ## 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
|
1953 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
|
1954 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
|
1955 "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
|
1956 "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
|
1957 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1958 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
|
1959 "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
|
1960 "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
|
1961 } |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1962 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
|
1963 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
|
1964 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
|
1965 headers=headers, |
|
aea2cc142c1b
Added some more rest testing and make sure api version is valid.
John Rouillard <rouilj@ieee.org>
parents:
5710
diff
changeset
|
1966 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
|
1967 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
|
1968 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
|
1969 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1970 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1971 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1972 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
|
1973 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
|
1974 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
|
1975 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
|
1976 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
|
1977 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
|
1978 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
|
1979 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
|
1980 'foo bar') |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1981 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1982 ## 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
|
1983 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
|
1984 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
|
1985 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1986 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1987 # 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
|
1988 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
|
1989 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
|
1990 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
|
1991 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
|
1992 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
|
1993 "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
|
1994 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1995 ## 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
|
1996 ## allowed (405) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
1997 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
|
1998 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
|
1999 "/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
|
2000 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2001 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
|
2002 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2003 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2004 ## 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
|
2005 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
|
2006 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
|
2007 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
|
2008 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2009 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2010 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
|
2011 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
|
2012 "/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
|
2013 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2014 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
|
2015 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
|
2016 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2017 # 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
|
2018 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
|
2019 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
|
2020 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2021 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
|
2022 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
|
2023 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
|
2024 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2025 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2026 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
|
2027 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2028 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2029 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
|
2030 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
|
2031 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
|
2032 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
|
2033 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
|
2034 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
|
2035 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2036 ## 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
|
2037 ## 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
|
2038 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
|
2039 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
|
2040 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
|
2041 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2042 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2043 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
|
2044 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
|
2045 "/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
|
2046 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2047 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
|
2048 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
|
2049 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2050 # 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
|
2051 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
|
2052 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
|
2053 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2054 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
|
2055 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
|
2056 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
|
2057 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2058 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2059 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
|
2060 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2061 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2062 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
|
2063 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
|
2064 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
|
2065 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
|
2066 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
|
2067 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
|
2068 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
|
2069 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2070 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2071 ## 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
|
2072 ## 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
|
2073 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
|
2074 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
|
2075 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
|
2076 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2077 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2078 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
|
2079 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
|
2080 "/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
|
2081 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2082 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
|
2083 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
|
2084 # 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
|
2085 # 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
|
2086 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
|
2087 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
|
2088 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
|
2089 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2090 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2091 ## 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
|
2092 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
|
2093 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
|
2094 # 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
|
2095 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
|
2096 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
|
2097 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
|
2098 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2099 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2100 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
|
2101 url, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2102 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2103 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2104 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
|
2105 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
|
2106 # 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
|
2107 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
|
2108 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
|
2109 "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
|
2110 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2111 ## 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
|
2112 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
|
2113 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
|
2114 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
|
2115 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2116 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2117 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
|
2118 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
|
2119 "/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
|
2120 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2121 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
|
2122 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2123 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
|
2124 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
|
2125 "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
|
2126 "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
|
2127 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2128 ## 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
|
2129 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
|
2130 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
|
2131 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
|
2132 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2133 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2134 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
|
2135 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
|
2136 "/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
|
2137 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2138 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
|
2139 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2140 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
|
2141 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
|
2142 "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
|
2143 "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
|
2144 |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2145 ## 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
|
2146 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
|
2147 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
|
2148 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
|
2149 headers=headers, |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2150 environ=env) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2151 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
|
2152 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
|
2153 "/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
|
2154 form) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2155 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
|
2156 print(results) |
|
0b79bfcb3312
Add support for making an idempotent POST. This allows retrying a POST
John Rouillard <rouilj@ieee.org>
parents:
5708
diff
changeset
|
2157 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
|
2158 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
|
2159 "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
|
2160 "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
|
2161 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
|
2162 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2163 def testPutElement(self): |
| 5583 | 2164 """ |
| 2165 Change joe's 'realname' | |
| 2166 Check if we can't change admin's detail | |
| 2167 """ | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2168 # 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
|
2169 # no etag |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2170 form = cgi.FieldStorage() |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2171 form.list = [ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2172 cgi.MiniFieldStorage('data', 'Joe Doe Doe') |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2173 ] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2174 results = self.server.put_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2175 'user', self.joeid, 'realname', form |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2176 ) |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2177 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
|
2178 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
|
2179 '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
|
2180 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2181 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
|
2182 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
|
2183 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2184 # 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
|
2185 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2186 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
|
2187 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
|
2188 form.list = [ |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2189 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
|
2190 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2191 |
|
5674
6dc4dba1c225
REST: Use If-Match header for incoming requests
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5673
diff
changeset
|
2192 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
|
2193 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
|
2194 '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
|
2195 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2196 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
|
2197 results = self.server.get_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2198 '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
|
2199 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2200 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
|
2201 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
|
2202 del(self.headers) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2203 |
|
5643
a60cbbcc9309
Added support for accepting application/json payload in addition to
John Rouillard <rouilj@ieee.org>
parents:
5639
diff
changeset
|
2204 # 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
|
2205 # 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
|
2206 # 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
|
2207 # 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
|
2208 # having to filter out protected items. |
| 5583 | 2209 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2210 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
|
2211 self.db.config['WEB_SECRET_KEY']) |
| 5583 | 2212 form.list = [ |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2213 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
|
2214 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
|
2215 cgi.MiniFieldStorage('@etag', etag) |
| 5583 | 2216 ] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2217 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
|
2218 self.assertEqual(self.dummy_client.response_code, 200) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2219 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
|
2220 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
|
2221 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe') |
| 5583 | 2222 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2223 # 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
|
2224 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
|
2225 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
|
2226 self.assertEqual(results['error']['status'], 403) |
| 5583 | 2227 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2228 # 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
|
2229 # 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
|
2230 # 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
|
2231 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2232 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
|
2233 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
|
2234 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2235 cgi.MiniFieldStorage('JustKidding', '3'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2236 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
|
2237 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2238 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2239 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
|
2240 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2241 '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
|
2242 'found in class user')}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2243 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
|
2244 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2245 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
|
2246 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2247 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
|
2248 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
|
2249 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
|
2250 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
|
2251 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2252 def testPutAttribute(self): |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2253 # put protected property |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2254 # 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
|
2255 self.db.setCurrentUser('admin') |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2256 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2257 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
|
2258 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
|
2259 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2260 cgi.MiniFieldStorage('data', '3'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2261 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2262 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2263 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
|
2264 '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
|
2265 ) |
|
5707
f9a762678af6
Change some 400 errors to 405 (method not allowed) errors where user is
John Rouillard <rouilj@ieee.org>
parents:
5706
diff
changeset
|
2266 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
|
2267 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
|
2268 '"activity" are reserved\'')}} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2269 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2270 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
|
2271 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2272 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
|
2273 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
|
2274 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
|
2275 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2276 # put invalid property |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2277 # 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
|
2278 self.db.setCurrentUser('admin') |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2279 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2280 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
|
2281 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
|
2282 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2283 cgi.MiniFieldStorage('data', '3'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2284 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2285 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2286 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
|
2287 '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
|
2288 ) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2289 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2290 'msg': UsageError("'youMustBeKiddingMe' " |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2291 "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
|
2292 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2293 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
|
2294 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2295 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
|
2296 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2297 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
|
2298 |
| 5583 | 2299 def testPost(self): |
| 2300 """ | |
| 2301 Post a new issue with title: foo | |
| 2302 Verify the information of the created issue | |
| 2303 """ | |
| 2304 form = cgi.FieldStorage() | |
| 2305 form.list = [ | |
| 2306 cgi.MiniFieldStorage('title', 'foo') | |
| 2307 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2308 results = self.server.post_collection('issue', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2309 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
|
2310 issueid = results['data']['id'] |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2311 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
|
2312 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
|
2313 self.assertEqual(results['data']['attributes']['title'], 'foo') |
| 5583 | 2314 self.assertEqual(self.db.issue.get(issueid, "tx_Source"), 'web') |
| 2315 | |
| 2316 def testPostFile(self): | |
| 2317 """ | |
| 2318 Post a new file with content: hello\r\nthere | |
| 2319 Verify the information of the created file | |
| 2320 """ | |
| 2321 form = cgi.FieldStorage() | |
| 2322 form.list = [ | |
| 2323 cgi.MiniFieldStorage('content', 'hello\r\nthere') | |
| 2324 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2325 results = self.server.post_collection('file', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2326 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
|
2327 fileid = results['data']['id'] |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2328 results = self.server.get_element('file', fileid, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
2329 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2330 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
|
2331 self.assertEqual(results['attributes']['content'], |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2332 {'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
|
2333 |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2334 # File content is only shown with verbose=3 |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2335 form = cgi.FieldStorage() |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2336 form.list = [ |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2337 cgi.MiniFieldStorage('@verbose', '3') |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2338 ] |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2339 results = self.server.get_element('file', fileid, form) |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2340 results = results['data'] |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2341 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2342 self.assertEqual(results['attributes']['content'], 'hello\r\nthere') |
| 2343 | |
| 2344 def testAuthDeniedPut(self): | |
| 2345 """ | |
| 2346 Test unauthorized PUT request | |
| 2347 """ | |
| 2348 # Wrong permissions (caught by roundup security module). | |
| 2349 form = cgi.FieldStorage() | |
| 2350 form.list = [ | |
| 2351 cgi.MiniFieldStorage('realname', 'someone') | |
| 2352 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2353 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
|
2354 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
|
2355 self.assertEqual(results['error']['status'], 403) |
| 5583 | 2356 |
| 2357 def testAuthDeniedPost(self): | |
| 2358 """ | |
| 2359 Test unauthorized POST request | |
| 2360 """ | |
| 2361 form = cgi.FieldStorage() | |
| 2362 form.list = [ | |
| 2363 cgi.MiniFieldStorage('username', 'blah') | |
| 2364 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2365 results = self.server.post_collection('user', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2366 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
|
2367 self.assertEqual(results['error']['status'], 403) |
| 5583 | 2368 |
| 2369 def testAuthAllowedPut(self): | |
| 2370 """ | |
| 2371 Test authorized PUT request | |
| 2372 """ | |
| 2373 self.db.setCurrentUser('admin') | |
| 2374 form = cgi.FieldStorage() | |
| 2375 form.list = [ | |
| 2376 cgi.MiniFieldStorage('realname', 'someone') | |
| 2377 ] | |
| 2378 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2379 self.server.put_element('user', '2', form) |
| 5602 | 2380 except Unauthorised as err: |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2381 self.fail('raised %s' % err) |
| 5583 | 2382 finally: |
| 2383 self.db.setCurrentUser('joe') | |
| 2384 | |
| 2385 def testAuthAllowedPost(self): | |
| 2386 """ | |
| 2387 Test authorized POST request | |
| 2388 """ | |
| 2389 self.db.setCurrentUser('admin') | |
| 2390 form = cgi.FieldStorage() | |
| 2391 form.list = [ | |
| 2392 cgi.MiniFieldStorage('username', 'blah') | |
| 2393 ] | |
| 2394 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2395 self.server.post_collection('user', form) |
| 5602 | 2396 except Unauthorised as err: |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2397 self.fail('raised %s' % err) |
| 5583 | 2398 finally: |
| 2399 self.db.setCurrentUser('joe') | |
| 2400 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2401 def testDeleteAttributeUri(self): |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2402 """ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2403 Test Delete an attribute |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2404 """ |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2405 self.maxDiff = 4000 |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2406 # 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
|
2407 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
|
2408 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2409 # 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
|
2410 # With no changes |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2411 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
|
2412 '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
|
2413 ) |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2414 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
|
2415 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
|
2416 results = results['data'] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2417 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
|
2418 self.assertEqual(len(results['attributes']['nosy']), 1) |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2419 self.assertListEqual(results['attributes']['nosy'], |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2420 [{'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
|
2421 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2422 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2423 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
|
2424 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
|
2425 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
|
2426 # remove the title and nosy |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2427 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
|
2428 'issue', issue_id, 'title', form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2429 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2430 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
|
2431 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2432 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
|
2433 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
|
2434 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
|
2435 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
|
2436 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
|
2437 'issue', issue_id, 'nosy', form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2438 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2439 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
|
2440 |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2441 # verify the result |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2442 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
|
2443 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2444 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
|
2445 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
|
2446 self.assertListEqual(results['attributes']['nosy'], []) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2447 self.assertEqual(results['attributes']['title'], None) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
2448 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2449 # delete protected property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2450 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
|
2451 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
|
2452 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
|
2453 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
|
2454 '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
|
2455 ) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2456 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
|
2457 '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
|
2458 '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
|
2459 }} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2460 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2461 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
|
2462 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2463 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
|
2464 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
|
2465 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
|
2466 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2467 # delete required property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2468 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
|
2469 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
|
2470 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
|
2471 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
|
2472 '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
|
2473 ) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2474 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2475 '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
|
2476 "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
|
2477 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2478 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
|
2479 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2480 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
|
2481 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
|
2482 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
|
2483 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
|
2484 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
|
2485 |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2486 # delete bogus property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2487 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
|
2488 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
|
2489 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
|
2490 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
|
2491 '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
|
2492 ) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2493 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
|
2494 '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
|
2495 "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
|
2496 print(results) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2497 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
|
2498 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
|
2499 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
|
2500 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
|
2501 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
|
2502 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
|
2503 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
|
2504 |
| 5583 | 2505 def testPatchAdd(self): |
| 2506 """ | |
| 2507 Test Patch op 'Add' | |
| 2508 """ | |
| 2509 # create a new issue with userid 1 in the nosy list | |
| 2510 issue_id = self.db.issue.create(title='foo', nosy=['1']) | |
| 2511 | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2512 # 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
|
2513 # no etag |
| 5583 | 2514 form = cgi.FieldStorage() |
| 2515 form.list = [ | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2516 cgi.MiniFieldStorage('@op', 'add'), |
| 5583 | 2517 cgi.MiniFieldStorage('nosy', '2') |
| 2518 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2519 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
|
2520 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
|
2521 |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2522 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
|
2523 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
|
2524 form = cgi.FieldStorage() |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2525 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2526 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
|
2527 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
|
2528 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
|
2529 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2530 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
|
2531 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2532 |
| 2533 # verify the result | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2534 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
|
2535 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2536 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2537 self.assertEqual(len(results['attributes']['nosy']), 2) |
| 2538 self.assertListEqual(results['attributes']['nosy'], ['1', '2']) | |
| 2539 | |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2540 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
|
2541 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
|
2542 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
|
2543 form.list = [ |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2544 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
|
2545 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
|
2546 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
|
2547 ] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2548 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
|
2549 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
|
2550 |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2551 # 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
|
2552 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
|
2553 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
|
2554 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
|
2555 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
|
2556 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
|
2557 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2558 # 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
|
2559 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
|
2560 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
|
2561 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
|
2562 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
|
2563 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
|
2564 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
|
2565 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
|
2566 ] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2567 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
|
2568 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
|
2569 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2570 # 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
|
2571 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
|
2572 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
|
2573 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
|
2574 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
|
2575 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
|
2576 |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2577 # patch invalid property |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2578 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
|
2579 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
|
2580 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
|
2581 form.list = [ |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2582 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
|
2583 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
|
2584 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
|
2585 ] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2586 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
|
2587 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
|
2588 print(results) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2589 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
|
2590 'msg': UsageError( |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2591 HyperdbValueError( |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2592 "'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
|
2593 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
|
2594 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
|
2595 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
|
2596 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
|
2597 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
|
2598 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
|
2599 |
| 5583 | 2600 def testPatchReplace(self): |
| 2601 """ | |
| 2602 Test Patch op 'Replace' | |
| 2603 """ | |
| 2604 # create a new issue with userid 1 in the nosy list and status = 1 | |
| 2605 issue_id = self.db.issue.create(title='foo', nosy=['1'], status='1') | |
| 2606 | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2607 # 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
|
2608 # no etag. |
| 5583 | 2609 form = cgi.FieldStorage() |
| 2610 form.list = [ | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2611 cgi.MiniFieldStorage('@op', 'replace'), |
| 5583 | 2612 cgi.MiniFieldStorage('nosy', '2'), |
| 2613 cgi.MiniFieldStorage('status', '3') | |
| 2614 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2615 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
|
2616 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
|
2617 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
|
2618 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2619 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
|
2620 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
|
2621 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
|
2622 self.assertListEqual(results['attributes']['nosy'], ['1']) |
| 5583 | 2623 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2624 # 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
|
2625 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
|
2626 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
|
2627 form = cgi.FieldStorage() |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2628 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2629 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
|
2630 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
|
2631 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
|
2632 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
|
2633 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2634 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
|
2635 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2636 # verify the result |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2637 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
|
2638 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2639 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2640 self.assertEqual(results['attributes']['status'], '3') |
| 2641 self.assertEqual(len(results['attributes']['nosy']), 1) | |
| 2642 self.assertListEqual(results['attributes']['nosy'], ['2']) | |
| 2643 | |
|
5706
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2644 # 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
|
2645 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
|
2646 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
|
2647 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
|
2648 form.list = [ |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2649 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
|
2650 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
|
2651 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
|
2652 ] |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2653 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
|
2654 form) |
|
dfca6136dd7b
Add more tests including call to patch an attribute with add and
John Rouillard <rouilj@ieee.org>
parents:
5705
diff
changeset
|
2655 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
|
2656 # 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
|
2657 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
|
2658 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
|
2659 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
|
2660 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
|
2661 |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2662 # 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
|
2663 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
|
2664 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
|
2665 form = cgi.FieldStorage() |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2666 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2667 cgi.MiniFieldStorage('@op', 'replace'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2668 cgi.MiniFieldStorage('creator', '2'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2669 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2670 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2671 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
|
2672 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2673 '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
|
2674 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2675 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
|
2676 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2677 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
|
2678 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2679 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
|
2680 str(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2681 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
|
2682 |
|
5708
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2683 # 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
|
2684 # 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
|
2685 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
|
2686 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
|
2687 form = cgi.FieldStorage() |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2688 form.list = [ |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2689 cgi.MiniFieldStorage('@op', 'replace'), |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2690 cgi.MiniFieldStorage('data', '2'), |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2691 cgi.MiniFieldStorage('@etag', etag) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2692 ] |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2693 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
|
2694 form) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2695 expected= {'error': {'status': 405, |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2696 '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
|
2697 print(results) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2698 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
|
2699 expected['error']['status']) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2700 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
|
2701 type(expected['error']['msg'])) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2702 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
|
2703 str(expected['error']['msg'])) |
|
ad786c394788
Add another test case: change protected attribute using patch_attribute.
John Rouillard <rouilj@ieee.org>
parents:
5707
diff
changeset
|
2704 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
|
2705 |
| 5583 | 2706 def testPatchRemoveAll(self): |
| 2707 """ | |
| 2708 Test Patch Action 'Remove' | |
| 2709 """ | |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2710 # create a new issue with userid 1 and 2 in the nosy list |
| 5583 | 2711 issue_id = self.db.issue.create(title='foo', nosy=['1', '2']) |
| 2712 | |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2713 # 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
|
2714 # no etag |
| 5583 | 2715 form = cgi.FieldStorage() |
| 2716 form.list = [ | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2717 cgi.MiniFieldStorage('@op', 'remove'), |
| 5583 | 2718 cgi.MiniFieldStorage('nosy', ''), |
| 2719 cgi.MiniFieldStorage('title', '') | |
| 2720 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2721 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
|
2722 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
|
2723 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
|
2724 results = results['data'] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2725 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
|
2726 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
|
2727 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
|
2728 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
|
2729 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2730 # 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
|
2731 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2732 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
|
2733 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
|
2734 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2735 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
|
2736 cgi.MiniFieldStorage('nosy', ''), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2737 cgi.MiniFieldStorage('title', ''), |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2738 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
|
2739 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2740 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
|
2741 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2742 |
| 2743 # verify the result | |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2744 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
|
2745 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
2746 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 2747 self.assertEqual(results['attributes']['title'], None) |
| 2748 self.assertEqual(len(results['attributes']['nosy']), 0) | |
| 2749 self.assertEqual(results['attributes']['nosy'], []) | |
| 2750 | |
|
5705
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2751 # 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
|
2752 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
|
2753 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
|
2754 form = cgi.FieldStorage() |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2755 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2756 cgi.MiniFieldStorage('@op', 'remove'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2757 cgi.MiniFieldStorage('creator', '2'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2758 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2759 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2760 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
|
2761 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2762 '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
|
2763 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2764 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
|
2765 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2766 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
|
2767 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2768 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
|
2769 str(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2770 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
|
2771 |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2772 # 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
|
2773 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
|
2774 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
|
2775 form.list = [ |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2776 cgi.MiniFieldStorage('@op', 'remove'), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2777 cgi.MiniFieldStorage('requireme', ''), |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2778 cgi.MiniFieldStorage('@etag', etag) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2779 ] |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2780 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
|
2781 expected= {'error': {'status': 400, |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2782 '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
|
2783 }} |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2784 print(results) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2785 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
|
2786 expected['error']['status']) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2787 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
|
2788 type(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2789 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
|
2790 str(expected['error']['msg'])) |
|
457fc482e6b1
Method PUT: ignore specification of protected properties which can not
John Rouillard <rouilj@ieee.org>
parents:
5690
diff
changeset
|
2791 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
|
2792 |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2793 def testPatchAction(self): |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2794 """ |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2795 Test Patch Action 'Action' |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2796 """ |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2797 # 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
|
2798 issue_id = self.db.issue.create(title='foo') |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2799 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2800 # 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
|
2801 # no etag |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2802 form = cgi.FieldStorage() |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2803 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2804 cgi.MiniFieldStorage('@op', 'action'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2805 cgi.MiniFieldStorage('@action_name', 'retire') |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2806 ] |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2807 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
|
2808 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
|
2809 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
|
2810 |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2811 # execute action retire |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2812 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2813 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
|
2814 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
|
2815 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2816 cgi.MiniFieldStorage('@op', 'action'), |
|
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2817 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
|
2818 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
|
2819 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2820 results = self.server.patch_element('issue', issue_id, form) |
|
5599
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2821 self.assertEqual(self.dummy_client.response_code, 200) |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2822 |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2823 # verify the result |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2824 self.assertTrue(self.db.issue.is_retired(issue_id)) |
|
a76d88673375
Added Patch operator 'action'
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5595
diff
changeset
|
2825 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2826 # 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
|
2827 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
|
2828 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
|
2829 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
|
2830 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
|
2831 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
|
2832 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
|
2833 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
|
2834 ] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2835 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
|
2836 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
|
2837 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2838 # 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
|
2839 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
|
2840 |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2841 def testPatchRemove(self): |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2842 """ |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2843 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
|
2844 """ |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2845 # 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
|
2846 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
|
2847 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2848 # 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
|
2849 # no etag |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2850 form = cgi.FieldStorage() |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2851 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2852 cgi.MiniFieldStorage('@op', 'remove'), |
|
5595
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2853 cgi.MiniFieldStorage('nosy', '1, 2'), |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2854 ] |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2855 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
|
2856 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
|
2857 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
|
2858 results = results['data'] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2859 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
|
2860 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
|
2861 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
|
2862 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2863 # 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
|
2864 form = cgi.FieldStorage() |
|
5727
8b5171f353eb
issue2551033: actually use the key in hmac generation. Finally add
John Rouillard <rouilj@ieee.org>
parents:
5726
diff
changeset
|
2865 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
|
2866 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
|
2867 form.list = [ |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2868 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
|
2869 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
|
2870 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
|
2871 ] |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5623
diff
changeset
|
2872 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
|
2873 self.assertEqual(self.dummy_client.response_code, 200) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2874 |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2875 # verify the result |
|
5672
a7211712b110
Fix tests for latest REST changes
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5656
diff
changeset
|
2876 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
|
2877 results = results['data'] |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2878 self.assertEqual(self.dummy_client.response_code, 200) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2879 self.assertEqual(len(results['attributes']['nosy']), 1) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2880 self.assertEqual(results['attributes']['nosy'], ['3']) |
|
65caddd54da2
Handle operation for patch separately
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5592
diff
changeset
|
2881 |
|
5747
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2882 # 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
|
2883 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
|
2884 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
|
2885 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
|
2886 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
|
2887 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
|
2888 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
|
2889 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
|
2890 ] |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2891 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
|
2892 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
|
2893 |
|
17b38e209307
Test patch op=action restore; test patch add for attribute with no value.
John Rouillard <rouilj@ieee.org>
parents:
5746
diff
changeset
|
2894 # 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
|
2895 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
|
2896 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
|
2897 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
|
2898 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
|
2899 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
|
2900 |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2901 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2902 def test_expired_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2903 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2904 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2905 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2906 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2907 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2908 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2909 secret = self.db.config.WEB_JWT_SECRET |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2910 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2911 # verify library and tokens are correct |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2912 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2913 jwt.decode, self.jwt['expired'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2914 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2915 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2916 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2917 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2918 result = jwt.decode(self.jwt['user'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2919 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2920 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2921 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2922 self.assertEqual(self.claim['user'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2923 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2924 result = jwt.decode(self.jwt['user:email'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2925 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2926 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2927 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2928 self.assertEqual(self.claim['user:email'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2929 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2930 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2931 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2932 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2933 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2934 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2935 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2936 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2937 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2938 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2939 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2940 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2941 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2942 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2943 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2944 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2945 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2946 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2947 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2948 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2949 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2950 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2951 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2952 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2953 # set up for expired token first |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2954 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['expired'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2955 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2956 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2957 # this will be the admin still as auth failed |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2958 self.assertEqual('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2959 self.assertEqual(out[0], b'Invalid Login - Signature has expired') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2960 del(out[0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2961 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2962 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2963 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2964 def test_user_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2965 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2966 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2967 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2968 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2969 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2970 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2971 secret = self.db.config.WEB_JWT_SECRET |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2972 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2973 # verify library and tokens are correct |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2974 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2975 jwt.decode, self.jwt['expired'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2976 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2977 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2978 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2979 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2980 result = jwt.decode(self.jwt['user'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2981 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2982 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2983 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2984 self.assertEqual(self.claim['user'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2985 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2986 result = jwt.decode(self.jwt['user:email'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2987 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2988 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2989 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2990 self.assertEqual(self.claim['user:email'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2991 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2992 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2993 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2994 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2995 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2996 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2997 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2998 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
2999 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3000 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3001 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3002 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3003 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3004 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3005 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3006 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3007 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3008 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3009 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3010 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3011 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3012 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3013 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3014 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3015 # set up for standard user role token |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3016 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3017 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3018 print(out[0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3019 json_dict = json.loads(b2s(out[0])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3020 print(json_dict) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3021 # user will be joe id 3 as auth works |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3022 self.assertTrue('3', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3023 # there should be three items in the collection admin, anon, and joe |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3024 self.assertEqual(3, len(json_dict['data']['collection'])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3025 # since this token has no access to email addresses, only joe |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3026 # should have email addresses. Order is by id by default. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3027 self.assertFalse('address' in json_dict['data']['collection'][0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3028 self.assertFalse('address' in json_dict['data']['collection'][1]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3029 self.assertTrue('address' in json_dict['data']['collection'][2]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3030 del(out[0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3031 self.db.setCurrentUser('admin') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3032 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3033 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3034 def test_user_email_jwt(self): |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3035 '''tests "Rest Access" permission present case''' |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3036 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3037 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3038 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3039 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3040 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3041 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3042 secret = self.db.config.WEB_JWT_SECRET |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3043 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3044 # verify library and tokens are correct |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3045 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3046 jwt.decode, self.jwt['expired'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3047 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3048 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3049 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3050 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3051 result = jwt.decode(self.jwt['user'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3052 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3053 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3054 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3055 self.assertEqual(self.claim['user'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3056 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3057 result = jwt.decode(self.jwt['user:email'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3058 secret, algorithms=['HS256'], |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3059 audience=self.db.config.TRACKER_WEB, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3060 issuer=self.db.config.TRACKER_WEB) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3061 self.assertEqual(self.claim['user:email'],result) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3062 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3063 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3064 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3065 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3066 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3067 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3068 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3069 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3070 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3071 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3072 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3073 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3074 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3075 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3076 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3077 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3078 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3079 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3080 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3081 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3082 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3083 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3084 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3085 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3086 # set up for limited user:email role token |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3087 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user:email'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3088 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3089 json_dict = json.loads(b2s(out[0])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3090 print(json_dict) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3091 # user will be joe id 3 as auth works |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3092 self.assertTrue('3', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3093 # there should be three items in the collection admin, anon, and joe |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3094 self.assertEqual(3, len(json_dict['data']['collection'])) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3095 # However this token has access to email addresses, so all three |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3096 # should have email addresses. Order is by id by default. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3097 self.assertTrue('address' in json_dict['data']['collection'][0]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3098 self.assertTrue('address' in json_dict['data']['collection'][1]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3099 self.assertTrue('address' in json_dict['data']['collection'][2]) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3100 |
|
5879
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3101 @skip_jwt |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3102 def test_user_emailnorest_jwt(self): |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3103 '''tests "Rest Access" permission missing case''' |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3104 # self.dummy_client.main() closes database, so |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3105 # we need a new test with setup called for each test |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3106 out = [] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3107 def wh(s): |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3108 out.append(s) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3109 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3110 secret = self.db.config.WEB_JWT_SECRET |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3111 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3112 # verify library and tokens are correct |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3113 self.assertRaises(jwt.exceptions.InvalidTokenError, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3114 jwt.decode, self.jwt['expired'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3115 secret, algorithms=['HS256'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3116 audience=self.db.config.TRACKER_WEB, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3117 issuer=self.db.config.TRACKER_WEB) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3118 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3119 result = jwt.decode(self.jwt['user'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3120 secret, algorithms=['HS256'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3121 audience=self.db.config.TRACKER_WEB, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3122 issuer=self.db.config.TRACKER_WEB) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3123 self.assertEqual(self.claim['user'],result) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3124 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3125 result = jwt.decode(self.jwt['user:email'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3126 secret, algorithms=['HS256'], |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3127 audience=self.db.config.TRACKER_WEB, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3128 issuer=self.db.config.TRACKER_WEB) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3129 self.assertEqual(self.claim['user:email'],result) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3130 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3131 # set environment for all jwt tests |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3132 env = { |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3133 'PATH_INFO': 'rest/data/user', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3134 'HTTP_HOST': 'localhost', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3135 'TRACKER_NAME': 'rounduptest', |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3136 "REQUEST_METHOD": "GET" |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3137 } |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3138 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3139 [], None) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3140 self.dummy_client.db = self.db |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3141 self.dummy_client.request.headers.get = self.get_header |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3142 self.empty_form = cgi.FieldStorage() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3143 self.terse_form = cgi.FieldStorage() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3144 self.terse_form.list = [ |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3145 cgi.MiniFieldStorage('@verbose', '0'), |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3146 ] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3147 self.dummy_client.form = cgi.FieldStorage() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3148 self.dummy_client.form.list = [ |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3149 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3150 ] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3151 # accumulate json output for further analysis |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3152 self.dummy_client.write = wh |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3153 |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3154 # set up for limited user:email role token |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3155 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user:emailnorest'] |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3156 self.dummy_client.main() |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3157 json_dict = json.loads(b2s(out[0])) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3158 # user will be joe id 3 as auth works |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3159 self.assertTrue('1', self.db.getuid()) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3160 { "error": { "status": 403, "msg": "Forbidden." } } |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3161 self.assertTrue('error' in json_dict) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3162 self.assertTrue(json_dict['error']['status'], 403) |
|
94a7669677ae
add permissions to control user of rest and xmlrpc API interfaces.
John Rouillard <rouilj@ieee.org>
parents:
5878
diff
changeset
|
3163 self.assertTrue(json_dict['error']['msg'], "Forbidden.") |
|
5878
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3164 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3165 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3166 def test_disabled_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3167 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3168 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3169 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3170 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3171 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3172 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3173 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3174 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3175 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3176 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3177 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3178 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3179 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3180 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3181 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3182 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3183 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3184 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3185 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3186 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3187 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3188 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3189 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3190 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3191 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3192 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3193 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3194 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3195 # disable jwt validation by making secret too short |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3196 # use the default value for this in configure.py. |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3197 self.db.config['WEB_JWT_SECRET'] = "disabled" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3198 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['user'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3199 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3200 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3201 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3202 self.assertEqual(out[0], b'Invalid Login - Support for jwt disabled by admin.') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3203 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3204 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3205 def test_bad_issue_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3206 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3207 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3208 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3209 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3210 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3211 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3212 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3213 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3214 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3215 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3216 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3217 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3218 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3219 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3220 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3221 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3222 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3223 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3224 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3225 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3226 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3227 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3228 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3229 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3230 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3231 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3232 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3233 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3234 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badiss'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3235 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3236 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3237 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3238 self.assertEqual(out[0], b'Invalid Login - Invalid issuer') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3239 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3240 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3241 def test_bad_audience_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3242 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3243 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3244 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3245 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3246 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3247 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3248 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3249 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3250 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3251 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3252 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3253 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3254 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3255 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3256 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3257 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3258 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3259 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3260 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3261 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3262 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3263 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3264 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3265 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3266 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3267 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3268 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3269 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3270 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badaud'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3271 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3272 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3273 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3274 self.assertEqual(out[0], b'Invalid Login - Invalid audience') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3275 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3276 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3277 def test_bad_roles_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3278 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3279 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3280 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3281 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3282 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3283 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3284 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3285 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3286 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3287 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3288 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3289 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3290 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3291 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3292 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3293 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3294 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3295 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3296 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3297 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3298 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3299 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3300 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3301 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3302 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3303 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3304 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3305 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3306 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badroles'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3307 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3308 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3309 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3310 self.assertEqual(out[0], b'Invalid Login - Token roles are invalid.') |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3311 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3312 @skip_jwt |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3313 def test_bad_subject_jwt(self): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3314 # self.dummy_client.main() closes database, so |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3315 # we need a new test with setup called for each test |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3316 out = [] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3317 def wh(s): |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3318 out.append(s) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3319 |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3320 # set environment for all jwt tests |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3321 env = { |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3322 'PATH_INFO': 'rest/data/user', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3323 'HTTP_HOST': 'localhost', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3324 'TRACKER_NAME': 'rounduptest', |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3325 "REQUEST_METHOD": "GET" |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3326 } |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3327 self.dummy_client = client.Client(self.instance, MockNull(), env, |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3328 [], None) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3329 self.dummy_client.db = self.db |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3330 self.dummy_client.request.headers.get = self.get_header |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3331 self.empty_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3332 self.terse_form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3333 self.terse_form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3334 cgi.MiniFieldStorage('@verbose', '0'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3335 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3336 self.dummy_client.form = cgi.FieldStorage() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3337 self.dummy_client.form.list = [ |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3338 cgi.MiniFieldStorage('@fields', 'username,address'), |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3339 ] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3340 # accumulate json output for further analysis |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3341 self.dummy_client.write = wh |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3342 env['HTTP_AUTHORIZATION'] = 'bearer %s'%self.jwt['badsub'] |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3343 self.dummy_client.main() |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3344 # user will be 1 as there is no auth |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3345 self.assertTrue('1', self.db.getuid()) |
|
1b57d8f3eb97
Add rudimentery experiment JSON Web Token (jwt) support
John Rouillard <rouilj@ieee.org>
parents:
5874
diff
changeset
|
3346 self.assertEqual(out[0], b'Invalid Login - Token subject is invalid.') |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
3347 |
|
5592
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
3348 def get_obj(path, id): |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
3349 return { |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
3350 'id': id, |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
3351 'link': path + id |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
3352 } |
|
adcb5cbe82bd
Add unittest for pagination and filtering
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5591
diff
changeset
|
3353 |
| 5583 | 3354 if __name__ == '__main__': |
| 3355 runner = unittest.TextTestRunner() | |
| 3356 unittest.main(testRunner=runner) |
