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