annotate test/test_liveserver.py @ 6915:9ff091537f43

postgresql native-fts; more indexer tests 1) Make postgresql native-fts actually work. 2) Add simple stopword filtering to sqlite native-fts indexer. 3) Add more tests for indexer_common get_indexer Details: 1) roundup/backends/indexer_postgresql_fts.py: ignore ValueError raised if we try to index a string with a null character in it. This could happen due to an incorrect text/ mime type on a file that has nulls in it. Replace ValueError raised by postgresql with customized IndexerQueryError if a search string has a null in it. roundup/backends/rdbms_common.py: Make postgresql native-fts work. When specified it was using using whatever was returned from get_indexer(). However loading the native-fts indexer backend failed because there was no connection to the postgresql database when this call was made. Simple solution, move the call after the open_connection call in Database::__init__(). However the open_connection call creates the schema for the database if it is not there. The schema builds tables for indexer=native type indexing. As part of the build it looks at the indexer to see the min/max size of the indexed tokens. No indexer define, we get a crash. So it's a a chicken/egg issue. I solved it by setting the indexer to the Indexer from indexer_common which has the min/max token size info. I also added a no-op save_indexer to this Indexer class. I claim save_indexer() isn't needed as a commit() on the db does all the saving required. Then after open_connection is called, I call get_indexer to retrieve the correct indexer and indexer_postgresql_fts woks since the conn connection property is defined. roundup/backends/indexer_common.py: add save_index() method for indexer. It does nothing but is needed in rdbms backends during schema initialization. 2) roundup/backends/indexer_sqlite_fts.py: when this indexer is used, the indexer test in DBTest on the word "the" fail. This is due to missing stopword filtering. Implement basic stopword filtering for bare stopwords (like 'the') to make the test pass. Note: this indexer is not currently automatically run by the CI suite, it was found during manual testing. However there is a FIXME to extract the indexer tests from DBTest and run it using this backend. roundup/configuration.py, roundup/doc/admin_guide.txt: update doc on stopword use for sqlite native-fts. test/db_test_base.py: DBTest::testStringBinary creates a file with nulls in it. It was breaking postgresql with native-fts indexer. Changed test to assign mime type application/octet-stream that prevents it from being processed by any text search indexer. add test to exclude indexer searching in specific props. This code path was untested before. test/test_indexer.py: add test to call find with no words. Untested code path. add test to index and find a string with a null \x00 byte. it was tested inadvertently by testStringBinary but this makes it explicit and moves it to indexer testing. (one version each for: generic, postgresql and mysql) Renamed Get_IndexerAutoSelectTest to Get_IndexerTest and renamed autoselect tests to include autoselect. Added tests for an invalid indexer and using native-fts with anydbm (unsupported combo) to make sure the code does something useful if the validation in configuration.py is broken. test/test_liveserver.py: add test to load an issue add test using text search (fts) to find the issue add tests to find issue using postgresql native-fts test/test_postgresql.py, test/test_sqlite.py: added explanation on how to setup integration test using native-fts. added code to clean up test environment if native-fts test is run.
author John Rouillard <rouilj@ieee.org>
date Mon, 05 Sep 2022 16:25:20 -0400
parents d9c9f5b81d4d
children cb2ed1e8c852
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
1 import shutil, errno, pytest, json, gzip, mimetypes, os, re
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2
6650
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
3 from roundup import i18n
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
4 from roundup import password
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
5 from roundup.anypy.strings import b2s
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6 from roundup.cgi.wsgi_handler import RequestDispatcher
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 from .wsgi_liveserver import LiveServerTestCase
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 from . import db_test_base
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9
6548
de5f5f9c02f2 Fix spurious content-ty on 304; xfail css Cache-Control
John Rouillard <rouilj@ieee.org>
parents: 6546
diff changeset
10 from wsgiref.validate import validator
de5f5f9c02f2 Fix spurious content-ty on 304; xfail css Cache-Control
John Rouillard <rouilj@ieee.org>
parents: 6546
diff changeset
11
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 try:
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 import requests
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 skip_requests = lambda func, *args, **kwargs: func
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 except ImportError:
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 from .pytest_patcher import mark_class
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
17 skip_requests = mark_class(pytest.mark.skip(
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
18 reason='Skipping liveserver tests: requests library not available'))
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
19
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
20 try:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
21 import brotli
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
22 skip_brotli = lambda func, *args, **kwargs: func
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
23 except ImportError:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
24 from .pytest_patcher import mark_class
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
25 skip_brotli = mark_class(pytest.mark.skip(
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
26 reason='Skipping brotli tests: brotli library not available'))
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
27 brotli = None
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
28
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
29 try:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
30 import zstd
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
31 skip_zstd = lambda func, *args, **kwargs: func
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
32 except ImportError:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
33 from .pytest_patcher import mark_class
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
34 skip_zstd = mark_class(pytest.mark.skip(
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
35 reason='Skipping zstd tests: zstd library not available'))
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
36
6569
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
37 import sys
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
38
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
39 _py3 = sys.version_info[0] > 2
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
40
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
41 @skip_requests
6747
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
42 class WsgiSetup(LiveServerTestCase):
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
43 # have chicken and egg issue here. Need to encode the base_url
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
44 # in the config file but we don't know it until after
6650
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
45 # the server is started and has read the config.ini.
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
46 # so only allow one port number
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
47 port_range = (9001, 9001) # default is (8080, 8090)
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
48
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
49 dirname = '_test_instance'
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
50 backend = 'anydbm'
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
51
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
52 js_mime_type = mimetypes.guess_type("utils.js")[0]
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
53
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
54 @classmethod
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
55 def setup_class(cls):
6650
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
56 '''All tests in this class use the same roundup instance.
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
57 This instance persists across all tests.
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
58 Create the tracker dir here so that it is ready for the
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
59 create_app() method to be called.
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
60 '''
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
61 # tests in this class.
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
62 # set up and open a tracker
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
63 cls.instance = db_test_base.setupTracker(cls.dirname, cls.backend)
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
64
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
65 # open the database
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
66 cls.db = cls.instance.open('admin')
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
67
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
68 # add a user without edit access for status.
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
69 cls.db.user.create(username="fred", roles='User',
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
70 password=password.Password('sekrit'), address='fred@example.com')
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
71
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
72 # set the url the test instance will run at.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
73 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/"
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
74 # set up mailhost so errors get reported to debuging capture file
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
75 cls.db.config.MAILHOST = "localhost"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
76 cls.db.config.MAIL_HOST = "localhost"
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
77 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log"
6813
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
78
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
79 # added to enable csrf forgeries/CORS to be tested
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
80 cls.db.config.WEB_CSRF_ENFORCE_HEADER_ORIGIN = "required"
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
81 cls.db.config.WEB_ALLOWED_API_ORIGINS = "https://client.com"
6813
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
82 cls.db.config['WEB_CSRF_ENFORCE_HEADER_X-REQUESTED-WITH'] = "required"
6755
d308fb5ba9b0 Disable rate limit. Tests log in and trip the limit causeing failures.
John Rouillard <rouilj@ieee.org>
parents: 6754
diff changeset
83
d308fb5ba9b0 Disable rate limit. Tests log in and trip the limit causeing failures.
John Rouillard <rouilj@ieee.org>
parents: 6754
diff changeset
84 # disable web login rate limiting. The fast rate of tests
d308fb5ba9b0 Disable rate limit. Tests log in and trip the limit causeing failures.
John Rouillard <rouilj@ieee.org>
parents: 6754
diff changeset
85 # causes them to trip the rate limit and fail.
d308fb5ba9b0 Disable rate limit. Tests log in and trip the limit causeing failures.
John Rouillard <rouilj@ieee.org>
parents: 6754
diff changeset
86 cls.db.config.WEB_LOGIN_ATTEMPTS_MIN = 0
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
87
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
88 # enable static precompressed files
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
89 cls.db.config.WEB_USE_PRECOMPRESSED_FILES = 1
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
90
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
91 cls.db.config.save()
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
92
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
93 # add an issue to allow testing retrieval.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
94 # also used for text searching.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
95 result = cls.db.issue.create(title="foo bar RESULT")
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
96
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
97 cls.db.commit()
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
98 cls.db.close()
6650
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
99
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
100 # Force locale config to find locales in checkout not in
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
101 # installed directories
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
102 cls.backup_domain = i18n.DOMAIN
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
103 cls.backup_locale_dirs = i18n.LOCALE_DIRS
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
104 i18n.LOCALE_DIRS = ['locale']
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
105 i18n.DOMAIN = ''
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
106
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
107 @classmethod
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
108 def teardown_class(cls):
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
109 '''Close the database and delete the tracker directory
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
110 now that the app should be exiting.
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
111 '''
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
112 if cls.db:
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
113 cls.db.close()
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
114 try:
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
115 shutil.rmtree(cls.dirname)
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
116 except OSError as error:
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
117 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
6650
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
118 i18n.LOCALE_DIRS = cls.backup_locale_dirs
5be4f9104cf7 Make i18n tests work
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6648
diff changeset
119 i18n.DOMAIN = cls.backup_domain
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
120
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
121 def create_app(self):
6747
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
122 '''The wsgi app to start - no feature_flags set.'''
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
123
6569
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
124 if _py3:
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
125 return validator(RequestDispatcher(self.dirname))
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
126 else:
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
127 # wsgiref/validator.py InputWrapper::readline is broke and
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
128 # doesn't support the max bytes to read argument.
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
129 return RequestDispatcher(self.dirname)
3ae0c0fb2d08 Fix test_new_file_via_rest
John Rouillard <rouilj@ieee.org>
parents: 6568
diff changeset
130
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
131
6747
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
132 class BaseTestCases(WsgiSetup):
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
133 """Class with all tests to run against wsgi server. Is reused when
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
134 wsgi server is started with various feature flags
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
135 """
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
136
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
137 def test_start_page(self):
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
138 """ simple test that verifies that the server can serve a start page.
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
139 """
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
140 f = requests.get(self.url_base())
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
141 self.assertEqual(f.status_code, 200)
6383
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
142 self.assertTrue(b'Roundup' in f.content)
e9760702bf0c Add live server test to suite.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
143 self.assertTrue(b'Creator' in f.content)
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
144
6640
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
145 def test_start_in_german(self):
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
146 """ simple test that verifies that the server can serve a start page
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
147 and translate text to german. Use page title and remeber login
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
148 checkbox label as translation test points..
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
149
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
150 use:
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
151 url parameter @language
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
152 cookie set by param
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
153 set @language to none and verify language cookie is unset
6640
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
154 """
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
155
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
156 # test url parameter
6640
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
157 f = requests.get(self.url_base() + "?@language=de")
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
158 self.assertEqual(f.status_code, 200)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
159 print(f.content)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
160 self.assertTrue(b'Roundup' in f.content)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
161 self.assertTrue(b'Aufgabenliste' in f.content)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
162 self.assertTrue(b'dauerhaft anmelden?' in f.content)
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
163
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
164 # test language cookie - should still be german
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
165 bluemonster = f.cookies
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
166 f = requests.get(self.url_base(), cookies=bluemonster)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
167 self.assertEqual(f.status_code, 200)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
168 print(f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
169 self.assertTrue(b'Roundup' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
170 self.assertTrue(b'Aufgabenliste' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
171 self.assertTrue(b'dauerhaft anmelden?' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
172
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
173 # unset language cookie, should be english
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
174 f = requests.get(self.url_base() + "?@language=none")
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
175 self.assertEqual(f.status_code, 200)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
176 print(f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
177 self.assertTrue(b'Roundup' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
178 self.assertFalse(b'Aufgabenliste' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
179 self.assertFalse(b'dauerhaft anmelden?' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
180 with self.assertRaises(KeyError):
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
181 l = f.cookies['roundup_language']
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
182
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
183 # check with Accept-Language header
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
184 alh = {"Accept-Language":
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
185 "fr;q=0.2, en;q=0.8, de;q=0.9, *;q=0.5"}
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
186 f = requests.get(self.url_base(), headers=alh)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
187 self.assertEqual(f.status_code, 200)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
188 print(f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
189 self.assertTrue(b'Roundup' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
190 self.assertTrue(b'Aufgabenliste' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
191 self.assertTrue(b'dauerhaft anmelden?' in f.content)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
192
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
193 def test_byte_Ranges(self):
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
194 """ Roundup only handles one simple two number range.
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
195 Range: 10-20
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
196
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
197 The following are not supported.
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
198 Range: 10-20, 25-30
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
199 Range: 10-
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
200
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
201 Also If-Range only supports strong etags not dates or weak etags.
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
202
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
203 """
6655
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
204
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
205 # get whole file uncompressed. Extract content length and etag
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
206 # for future use
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
207 f = requests.get(self.url_base() + "/@@file/style.css",
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
208 headers = {"Accept-Encoding": "identity"})
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
209 # store etag for condition range testing
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
210 etag = f.headers['etag']
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
211 expected_length = f.headers['content-length']
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
212
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
213 # get first 11 bytes unconditionally (0 index really??)
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
214 hdrs = {"Range": "bytes=0-10"}
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
215 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
216 self.assertEqual(f.status_code, 206)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
217 self.assertEqual(f.content, b"/* main pag")
6655
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
218 # compression disabled for length < 100, so we can use 11 here
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
219 self.assertEqual(f.headers['content-length'], '11')
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
220 self.assertEqual(f.headers['content-range'],
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
221 "bytes 0-10/%s"%expected_length)
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
222
6655
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
223 # conditional request 11 bytes since etag matches 206 code
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
224 hdrs['If-Range'] = etag
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
225 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
226 self.assertEqual(f.status_code, 206)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
227 self.assertEqual(f.content, b"/* main pag")
6655
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
228 # compression disabled for length < 100, so we can use 11 here
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
229 self.assertEqual(f.headers['content-length'], '11')
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
230 self.assertEqual(f.headers['content-range'],
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
231 "bytes 0-10/%s"%expected_length)
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
232
6655
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
233 # conditional request returns all bytes as etag isn't correct 200 code
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
234 hdrs['If-Range'] = etag[2:] # bad tag
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
235 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
236 self.assertEqual(f.status_code, 200)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
237 # not checking content length since it could be compressed
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
238 self.assertNotIn('content-range', f.headers, 'content-range should not be present')
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
239
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
240 # range is too large, but etag is bad also, return whole file 200 code
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
241 hdrs['Range'] = "0-99999" # too large
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
242 hdrs['If-Range'] = etag[2:] # bad tag
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
243 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs)
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
244 self.assertEqual(f.status_code, 200)
6655
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
245 # not checking content length since it could be compressed
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
246 self.assertNotIn('content-range', f.headers, 'content-range should not be present')
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
247
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
248 # range is too large, but etag is specified so return whole file
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
249 # 200 code
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
250 hdrs['Range'] = "bytes=0-99999" # too large
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
251 hdrs['If-Range'] = etag # any tag works
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
252 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
253 self.assertEqual(f.status_code, 200)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
254 # not checking content length since it could be compressed
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
255 self.assertNotIn('content-range', f.headers, 'content-range should not be present')
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
256
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
257 # range too large, not if-range so error code 416
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
258 hdrs['Range'] = "bytes=0-99999" # too large
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
259 del(hdrs['If-Range'])
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
260 print(hdrs)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
261 f = requests.get(self.url_base() + "/@@file/style.css", headers=hdrs)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
262 self.assertEqual(f.status_code, 416)
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
263 self.assertEqual(f.headers['content-range'],
a193653d6fa4 Test more range error cases.
John Rouillard <rouilj@ieee.org>
parents: 6651
diff changeset
264 "bytes */%s"%expected_length)
6648
53c9b62494e6 Add language test for cookie and accept-header; Test Range header
John Rouillard <rouilj@ieee.org>
parents: 6640
diff changeset
265
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
266 def test_rest_preflight_collection(self):
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
267 # no auth for rest csrf preflight
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
268 f = requests.options(self.url_base() + '/rest/data/user',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
269 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
270 'x-requested-with': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
271 'Access-Control-Request-Headers':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
272 "x-requested-with",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
273 'Access-Control-Request-Method': "PUT",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
274 'Origin': "https://client.com"})
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
275 print(f.status_code)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
276 print(f.headers)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
277 print(f.content)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
278
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
279 self.assertEqual(f.status_code, 204)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
280
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
281 expected = { 'Access-Control-Allow-Origin': 'https://client.com',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
282 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
283 'Allow': 'OPTIONS, GET, POST',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
284 'Access-Control-Allow-Methods': 'OPTIONS, GET, POST',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
285 'Access-Control-Allow-Credentials': 'true',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
286 }
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
287
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
288 # use dict comprehension to filter headers to the ones we want to check
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
289 self.assertEqual({ key: value for (key, value) in
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
290 f.headers.items() if key in expected },
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
291 expected)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
292
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
293 # use invalid Origin
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
294 f = requests.options(self.url_base() + '/rest/data/user',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
295 headers = {'content-type': "application/json",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
296 'x-requested-with': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
297 'Access-Control-Request-Headers':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
298 "x-requested-with",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
299 'Access-Control-Request-Method': "PUT",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
300 'Origin': "ZZZ"})
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
301
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
302 self.assertEqual(f.status_code, 400)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
303
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
304 expected = '{ "error": { "status": 400, "msg": "Client is not ' \
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
305 'allowed to use Rest Interface." } }'
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
306 self.assertEqual(b2s(f.content), expected)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
307
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
308
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
309 def test_rest_invalid_method_collection(self):
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
310 # use basic auth for rest endpoint
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
311 f = requests.put(self.url_base() + '/rest/data/user',
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
312 auth=('admin', 'sekrit'),
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
313 headers = {'content-type': "",
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
314 'X-Requested-With': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
315 'Origin': "https://client.com"})
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
316 print(f.status_code)
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
317 print(f.headers)
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
318 print(f.content)
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
319
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
320 self.assertEqual(f.status_code, 405)
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
321 expected = { 'Access-Control-Allow-Origin': 'https://client.com',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
322 'Access-Control-Allow-Credentials': 'true',
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
323 'Allow': 'DELETE, GET, OPTIONS, POST',
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
324 }
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
325
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
326 print(f.headers)
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
327 # use dict comprehension to remove fields like date,
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
328 # content-length etc. from f.headers.
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
329 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
330
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
331 content = json.loads(f.content)
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
332
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
333 exp_content = "Method PUT not allowed. Allowed: DELETE, GET, OPTIONS, POST"
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
334 self.assertEqual(exp_content, content['error']['msg'])
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
335
6386
2a2da73e1e26 Remove Connection: close header for 501 error handling rest
John Rouillard <rouilj@ieee.org>
parents: 6385
diff changeset
336 def test_http_options(self):
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
337 """ options returns an unimplemented error for this case."""
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
338
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
339 # do not send content-type header for options
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
340 f = requests.options(self.url_base() + '/',
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
341 headers = {'content-type': ""})
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
342 # options is not implemented for the non-rest interface.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
343 self.assertEqual(f.status_code, 501)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
344
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
345 def test_rest_endpoint_root_options(self):
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
346 # use basic auth for rest endpoint
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
347 f = requests.options(self.url_base() + '/rest',
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
348 auth=('admin', 'sekrit'),
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
349 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
350 'Origin': "http://localhost:9001",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
351 })
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
352 print(f.status_code)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
353 print(f.headers)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
354
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
355 self.assertEqual(f.status_code, 204)
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
356 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001',
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
357 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
358 'Allow': 'OPTIONS, GET',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
359 'Access-Control-Allow-Credentials': 'true',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
360 'Access-Control-Allow-Methods': 'OPTIONS, GET',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
361 'Access-Control-Allow-Credentials': 'true',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
362 }
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
363
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
364 # use dict comprehension to remove fields like date,
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
365 # content-length etc. from f.headers.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
366 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
367
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
368 def test_rest_endpoint_data_options(self):
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
369 # use basic auth for rest endpoint
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
370 f = requests.options(self.url_base() + '/rest/data',
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
371 auth=('admin', 'sekrit'),
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
372 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
373 'Origin': "http://localhost:9001",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
374 })
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
375 print(f.status_code)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
376 print(f.headers)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
377
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
378 self.assertEqual(f.status_code, 204)
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
379 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001',
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
380 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
381 'Allow': 'OPTIONS, GET',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
382 'Access-Control-Allow-Methods': 'OPTIONS, GET',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
383 'Access-Control-Allow-Credentials': 'true',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
384 }
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
385
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
386 # use dict comprehension to remove fields like date,
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
387 # content-length etc. from f.headers.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
388 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
389
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
390 def test_rest_endpoint_collection_options(self):
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
391 # use basic auth for rest endpoint
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
392 f = requests.options(self.url_base() + '/rest/data/user',
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
393 auth=('admin', 'sekrit'),
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
394 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
395 'Origin': "http://localhost:9001",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
396 })
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
397 print(f.status_code)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
398 print(f.headers)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
399
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
400 self.assertEqual(f.status_code, 204)
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
401 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001',
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
402 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
403 'Allow': 'OPTIONS, GET, POST',
6526
3c8322e3fe25 Fix test and remove pdb invocation.
John Rouillard <rouilj@ieee.org>
parents: 6525
diff changeset
404 'Access-Control-Allow-Methods': 'OPTIONS, GET, POST',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
405 'Access-Control-Allow-Credentials': 'true',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
406 }
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
407
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
408 # use dict comprehension to remove fields like date,
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
409 # content-length etc. from f.headers.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
410 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
411
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
412
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
413 def test_rest_endpoint_item_options(self):
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
414
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
415 f = requests.options(self.url_base() + '/rest/data/user/1',
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
416 auth=('admin', 'sekrit'),
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
417 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
418 'Origin': "http://localhost:9001",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
419 })
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
420 print(f.status_code)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
421 print(f.headers)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
422
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
423 self.assertEqual(f.status_code, 204)
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
424 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001',
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
425 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
426 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
427 'Access-Control-Allow-Methods': 'OPTIONS, GET, PUT, DELETE, PATCH',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
428 'Access-Control-Allow-Credentials': 'true',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
429 }
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
430
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
431 # use dict comprehension to remove fields like date,
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
432 # content-length etc. from f.headers.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
433 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
434
6385
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
435 def test_rest_endpoint_attribute_options(self):
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
436 # use basic auth for rest endpoint
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
437 f = requests.options(self.url_base() + '/rest/data/user/1/username',
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
438 auth=('admin', 'sekrit'),
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
439 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
440 'Origin': "http://localhost:9001",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
441 })
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
442 print(f.status_code)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
443 print(f.headers)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
444
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
445 self.assertEqual(f.status_code, 204)
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
446 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001',
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
447 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
448 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
449 'Access-Control-Allow-Methods': 'OPTIONS, GET, PUT, DELETE, PATCH',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
450 'Access-Control-Allow-Credentials': 'true',
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
451 }
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
452
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
453 # use dict comprehension to remove fields like date,
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
454 # content-length etc. from f.headers.
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
455 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
456
6385
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
457 ## test a read only property.
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
458
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
459 f = requests.options(self.url_base() + '/rest/data/user/1/creator',
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
460 auth=('admin', 'sekrit'),
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
461 headers = {'content-type': "",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
462 'Origin': "http://localhost:9001",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
463 })
6385
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
464 print(f.status_code)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
465 print(f.headers)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
466
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
467 self.assertEqual(f.status_code, 204)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
468 expected1 = dict(expected)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
469 expected1['Allow'] = 'OPTIONS, GET'
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
470 expected1['Access-Control-Allow-Methods'] = 'OPTIONS, GET'
6385
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
471
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
472 # use dict comprehension to remove fields like date,
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
473 # content-length etc. from f.headers.
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
474 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected1)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
475
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
476 ## test a property that doesn't exist
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
477 f = requests.options(self.url_base() + '/rest/data/user/1/zot',
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
478 auth=('admin', 'sekrit'),
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
479 headers = {'content-type': ""})
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
480 print(f.status_code)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
481 print(f.headers)
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
482
8c43129f29ca Rename test: element => attribute; test readonly and missing attribute
John Rouillard <rouilj@ieee.org>
parents: 6384
diff changeset
483 self.assertEqual(f.status_code, 404)
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
484
6640
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
485 def test_rest_login_rate_limit(self):
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
486 """login rate limit applies to api endpoints. Only failure
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
487 logins count though. So log in 10 times in a row
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
488 to verify that valid username/passwords aren't limited.
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
489 """
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
490
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
491 for i in range(10):
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
492 # use basic auth for rest endpoint
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
493
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
494 f = requests.options(self.url_base() + '/rest/data',
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
495 auth=('admin', 'sekrit'),
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
496 headers = {'content-type': ""}
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
497 )
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
498 print(f.status_code)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
499 print(f.headers)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
500
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
501 self.assertEqual(f.status_code, 204)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
502 expected = { 'Access-Control-Allow-Origin': '*',
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
503 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override',
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
504 'Allow': 'OPTIONS, GET',
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
505 'Access-Control-Allow-Methods': 'HEAD, OPTIONS, GET, POST, PUT, DELETE, PATCH',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
506 'Access-Control-Allow-Credentials': 'true',
6640
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
507 }
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
508
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
509 for i in range(10):
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
510 # use basic auth for rest endpoint
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
511
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
512 f = requests.options(self.url_base() + '/rest/data',
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
513 auth=('admin', 'ekrit'),
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
514 headers = {'content-type': ""}
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
515 )
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
516 print(i, f.status_code)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
517 print(f.headers)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
518 print(f.text)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
519
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
520 self.assertEqual(f.status_code, 401)
6ac3667706be Test german translation of start page.
John Rouillard <rouilj@ieee.org>
parents: 6570
diff changeset
521
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
522 def test_ims(self):
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
523 ''' retreive the user_utils.js file with old and new
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
524 if-modified-since timestamps.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
525 '''
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
526 from datetime import datetime
6384
66a061e52435 Test options in rest interface against live server; rest doc update
John Rouillard <rouilj@ieee.org>
parents: 6383
diff changeset
527
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
528 f = requests.get(self.url_base() + '/@@file/user_utils.js',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
529 headers = { 'Accept-Encoding': 'gzip, foo',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
530 'If-Modified-Since': 'Sun, 13 Jul 1986 01:20:00',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
531 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
532 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
533 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
534
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
535 self.assertEqual(f.status_code, 200)
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
536 expected = { 'Content-Type': self.js_mime_type,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
537 'Content-Encoding': 'gzip',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
538 'Vary': 'Accept-Encoding',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
539 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
540
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
541 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
542 # etag etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
543 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
544
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
545 # now use today's date
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
546 a_few_seconds_ago = datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT')
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
547 f = requests.get(self.url_base() + '/@@file/user_utils.js',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
548 headers = { 'Accept-Encoding': 'gzip, foo',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
549 'If-Modified-Since': a_few_seconds_ago,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
550 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
551 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
552 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
553
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
554 self.assertEqual(f.status_code, 304)
6548
de5f5f9c02f2 Fix spurious content-ty on 304; xfail css Cache-Control
John Rouillard <rouilj@ieee.org>
parents: 6546
diff changeset
555 expected = { 'Vary': 'Accept-Encoding',
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
556 'Content-Length': '0',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
557 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
558
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
559 # use dict comprehension to remove fields like date, etag
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
560 # etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
561 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
562
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
563
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
564 def test_load_issue1(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
565 f = requests.get(self.url_base() + '/issue1>',
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
566 headers = { 'Accept-Encoding': 'gzip',
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
567 'Accept': '*/*'})
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
568
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
569 self.assertIn(b'foo bar RESULT', f.content)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
570 self.assertEqual(f.status_code, 200)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
571
6749
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
572 def test_bad_path(self):
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
573 f = requests.get(self.url_base() + '/_bad>',
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
574 headers = { 'Accept-Encoding': 'gzip, foo',
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
575 'Accept': '*/*'})
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
576
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
577 # test that returned text is encoded.
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
578 self.assertEqual(f.content, b'Not found: _bad&gt;')
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
579 self.assertEqual(f.status_code, 404)
be3fd5e9577e Add test for incorrect url.
John Rouillard <rouilj@ieee.org>
parents: 6747
diff changeset
580
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
581 def test_compression_gzipfile(self):
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
582 '''Get the compressed dummy file'''
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
583
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
584 # create a user_utils.js.gz file to test pre-compressed
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
585 # file serving code. Has custom contents to verify
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
586 # that I get the compressed one.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
587 gzfile = "%s/html/user_utils.js.gzip"%self.dirname
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
588 test_text= b"Custom text for user_utils.js\n"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
589
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
590 with gzip.open(gzfile, 'wb') as f:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
591 bytes_written = f.write(test_text)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
592
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
593 self.assertEqual(bytes_written, 30)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
594
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
595 # test file x-fer
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
596 f = requests.get(self.url_base() + '/@@file/user_utils.js',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
597 headers = { 'Accept-Encoding': 'gzip, foo',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
598 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
599 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
600 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
601
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
602 self.assertEqual(f.status_code, 200)
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
603 expected = { 'Content-Type': self.js_mime_type,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
604 'Content-Encoding': 'gzip',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
605 'Vary': 'Accept-Encoding',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
606 'Content-Length': '69',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
607 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
608
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
609 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
610 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
611 self.assertDictEqual({ key: value for (key, value) in
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
612 f.headers.items() if key in expected },
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
613 expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
614
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
615
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
616 # check content - verify it's the .gz file not the real file.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
617 self.assertEqual(f.content, test_text)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
618
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
619 '''# verify that a different encoding request returns on the fly
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
620
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
621 # test file x-fer using br, so we get runtime compression
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
622 f = requests.get(self.url_base() + '/@@file/user_utils.js',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
623 headers = { 'Accept-Encoding': 'br, foo',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
624 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
625 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
626 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
627
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
628 self.assertEqual(f.status_code, 200)
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
629 expected = { 'Content-Type': self.js_mime_type,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
630 'Content-Encoding': 'br',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
631 'Vary': 'Accept-Encoding',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
632 'Content-Length': '960',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
633 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
634
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
635 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
636 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
637 self.assertDictEqual({ key: value for (key, value) in
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
638 f.headers.items() if key in expected },
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
639 expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
640
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
641 try:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
642 from urllib3.response import BrotliDecoder
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
643 # requests has decoded br to text for me
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
644 data = f.content
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
645 except ImportError:
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
646 # I need to decode
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
647 data = brotli.decompress(f.content)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
648
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
649 self.assertEqual(b2s(data)[0:25], '// User Editing Utilities')
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
650 '''
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
651
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
652 # re-request file, but now make .gzip out of date. So we get the
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
653 # real file compressed on the fly, not our test file.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
654 os.utime(gzfile, (0,0)) # use 1970/01/01 or os base time
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
655
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
656 f = requests.get(self.url_base() + '/@@file/user_utils.js',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
657 headers = { 'Accept-Encoding': 'gzip, foo',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
658 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
659 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
660 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
661
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
662 self.assertEqual(f.status_code, 200)
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
663 expected = { 'Content-Type': self.js_mime_type,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
664 'Content-Encoding': 'gzip',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
665 'Vary': 'Accept-Encoding',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
666 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
667
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
668 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
669 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
670 self.assertDictEqual({ key: value for (key, value) in
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
671 f.headers.items() if key in expected },
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
672 expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
673
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
674
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
675 # check content - verify it's the real file, not crafted .gz.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
676 self.assertEqual(b2s(f.content)[0:25], '// User Editing Utilities')
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
677
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
678 # cleanup
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
679 os.remove(gzfile)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
680
6541
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
681 def test_compression_none_etag(self):
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
682 # use basic auth for rest endpoint
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
683 f = requests.get(self.url_base() + '/rest/data/user/1/username',
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
684 auth=('admin', 'sekrit'),
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
685 headers = {'content-type': "",
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
686 'Accept-Encoding': "",
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
687 'Accept': '*/*'})
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
688 print(f.status_code)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
689 print(f.headers)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
690
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
691 self.assertEqual(f.status_code, 200)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
692 expected = { 'Content-Type': 'application/json',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
693 'Access-Control-Allow-Credentials': 'true',
6541
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
694 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH',
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
695 }
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
696
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
697 content_str = '''{ "data": {
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
698 "id": "1",
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
699 "link": "http://localhost:9001/rest/data/user/1/username",
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
700 "data": "admin"
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
701 }
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
702 }'''
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
703 content = json.loads(content_str)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
704
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
705
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
706 if (type("") == type(f.content)):
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
707 json_dict = json.loads(f.content)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
708 else:
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
709 json_dict = json.loads(b2s(f.content))
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
710
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
711 # etag wil not match, creation date different
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
712 del(json_dict['data']['@etag'])
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
713
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
714 # type is "class 'str'" under py3, "type 'str'" py2
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
715 # just skip comparing it.
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
716 del(json_dict['data']['type'])
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
717
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
718 self.assertDictEqual(json_dict, content)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
719
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
720 # verify that ETag header has no - delimiter
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
721 print(f.headers['ETag'])
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
722 with self.assertRaises(ValueError):
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
723 f.headers['ETag'].index('-')
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
724
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
725 # use dict comprehension to remove fields like date,
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
726 # content-length etc. from f.headers.
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
727 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
728
c8f3ec942e29 Test case where there is no content-encoding.
John Rouillard <rouilj@ieee.org>
parents: 6539
diff changeset
729
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
730 def test_compression_gzip(self, method='gzip'):
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
731 if method == 'gzip':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
732 decompressor = None
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
733 elif method == 'br':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
734 decompressor = brotli.decompress
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
735 elif method == 'zstd':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
736 decompressor = zstd.decompress
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
737
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
738 # use basic auth for rest endpoint
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
739 f = requests.get(self.url_base() + '/rest/data/user/1/username',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
740 auth=('admin', 'sekrit'),
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
741 headers = {'content-type': "",
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
742 'Accept-Encoding': '%s, foo'%method,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
743 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
744 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
745 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
746
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
747 self.assertEqual(f.status_code, 200)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
748 expected = { 'Content-Type': 'application/json',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
749 'Access-Control-Allow-Credentials': 'true',
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
750 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
751 'Content-Encoding': method,
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
752 'Vary': 'Origin, Accept-Encoding',
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
753 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
754
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
755 content_str = '''{ "data": {
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
756 "id": "1",
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
757 "link": "http://localhost:9001/rest/data/user/1/username",
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
758 "data": "admin"
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
759 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
760 }'''
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
761 content = json.loads(content_str)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
762
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
763 print(f.content)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
764 print(type(f.content))
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
765
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
766 try:
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
767 if (type("") == type(f.content)):
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
768 json_dict = json.loads(f.content)
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
769 else:
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
770 json_dict = json.loads(b2s(f.content))
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
771 except (ValueError, UnicodeDecodeError):
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
772 # Handle error from trying to load compressed data as only
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
773 # gzip gets decompressed automatically
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
774 # ValueError - raised by loads on compressed content python2
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
775 # UnicodeDecodeError - raised by loads on compressed content
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
776 # python3
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
777 json_dict = json.loads(b2s(decompressor(f.content)))
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
778
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
779 # etag will not match, creation date different
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
780 del(json_dict['data']['@etag'])
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
781
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
782 # type is "class 'str'" under py3, "type 'str'" py2
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
783 # just skip comparing it.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
784 del(json_dict['data']['type'])
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
785
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
786 self.assertDictEqual(json_dict, content)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
787
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
788 # verify that ETag header ends with -<method>
6539
f8df7fed18f6 issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents: 6526
diff changeset
789 try:
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
790 self.assertRegex(f.headers['ETag'], r'^"[0-9a-f]{32}-%s"$'%method)
6539
f8df7fed18f6 issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents: 6526
diff changeset
791 except AttributeError:
f8df7fed18f6 issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents: 6526
diff changeset
792 # python2 no assertRegex so try substring match
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
793 self.assertEqual(33, f.headers['ETag'].rindex('-' + method))
6539
f8df7fed18f6 issue2551175 - Make ETag content-encoding aware.
John Rouillard <rouilj@ieee.org>
parents: 6526
diff changeset
794
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
795 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
796 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
797 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
798
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
799
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
800 # use basic auth for rest endpoint, error case, bad attribute
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
801 f = requests.get(self.url_base() + '/rest/data/user/1/foo',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
802 auth=('admin', 'sekrit'),
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
803 headers = {'content-type': "",
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
804 'Accept-Encoding': '%s, foo'%method,
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
805 'Accept': '*/*',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
806 'Origin': 'ZZZZ'})
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
807 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
808 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
809
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
810 # NOTE: not compressed payload too small
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
811 self.assertEqual(f.status_code, 400)
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
812 expected = { 'Content-Type': 'application/json',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
813 'Access-Control-Allow-Credentials': 'true',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
814 'Access-Control-Allow-Origin': 'ZZZZ',
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
815 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
816 'Vary': 'Origin'
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
817 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
818
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
819 content = { "error":
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
820 {
6525
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
821 "status": 400,
c505c774a94d Mutiple changes to REST code.
John Rouillard <rouilj@ieee.org>
parents: 6509
diff changeset
822 "msg": "Invalid attribute foo"
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
823 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
824 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
825
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
826 json_dict = json.loads(b2s(f.content))
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
827 self.assertDictEqual(json_dict, content)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
828
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
829 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
830 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
831 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
832
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
833 # test file x-fer
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
834 f = requests.get(self.url_base() + '/@@file/user_utils.js',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
835 headers = { 'Accept-Encoding': '%s, foo'%method,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
836 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
837 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
838 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
839
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
840 self.assertEqual(f.status_code, 200)
6897
d9c9f5b81d4d application/javascript is now text/javascript
John Rouillard <rouilj@ieee.org>
parents: 6813
diff changeset
841 expected = { 'Content-Type': self.js_mime_type,
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
842 'Content-Encoding': method,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
843 'Vary': 'Accept-Encoding',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
844 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
845
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
846 # compare to byte string as f.content may be compressed.
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
847 # so running b2s on it will throw a UnicodeError
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
848 if f.content[0:25] == b'// User Editing Utilities':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
849 # no need to decompress, urlib3.response did it for gzip and br
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
850 data = f.content
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
851 else:
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
852 # I need to decode
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
853 data = decompressor(f.content)
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
854
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
855 # check first few bytes.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
856 self.assertEqual(b2s(data)[0:25], '// User Editing Utilities')
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
857
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
858 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
859 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
860 self.assertDictEqual({ key: value for (key, value) in
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
861 f.headers.items() if key in expected },
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
862 expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
863
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
864 # test file x-fer
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
865 f = requests.get(self.url_base() + '/user1',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
866 headers = { 'Accept-Encoding': '%s, foo'%method,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
867 'Accept': '*/*'})
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
868 print(f.status_code)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
869 print(f.headers)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
870
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
871 self.assertEqual(f.status_code, 200)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
872 expected = { 'Content-Type': 'text/html; charset=utf-8',
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
873 'Content-Encoding': method,
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
874 'Vary': 'Accept-Encoding',
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
875 }
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
876
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
877 if f.content[0:25] == b'<!-- dollarId: user.item,':
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
878 # no need to decompress, urlib3.response did it for gzip and br
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
879 data = f.content
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
880 else:
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
881 # I need to decode
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
882 data = decompressor(f.content)
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
883
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
884 # check first few bytes.
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
885 self.assertEqual(b2s(data[0:25]), '<!-- dollarId: user.item,')
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
886
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
887 # use dict comprehension to remove fields like date,
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
888 # content-length etc. from f.headers.
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
889 self.assertDictEqual({ key: value for (key, value) in
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
890 f.headers.items() if key in expected },
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
891 expected)
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
892
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
893 @skip_brotli
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
894 def test_compression_br(self):
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
895 self.test_compression_gzip(method="br")
6458
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
896
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
897 @skip_zstd
8f1b91756457 issue2551147 - Enable compression of http responses in roundup.
John Rouillard <rouilj@ieee.org>
parents: 6386
diff changeset
898 def test_compression_zstd(self):
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
899 self.test_compression_gzip(method="zstd")
6546
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
900
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
901 def test_cache_control_css(self):
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
902 f = requests.get(self.url_base() + '/@@file/style.css',
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
903 headers = {'content-type': "",
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
904 'Accept': '*/*'})
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
905 print(f.status_code)
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
906 print(f.headers)
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
907
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
908 self.assertEqual(f.status_code, 200)
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
909 self.assertEqual(f.headers['Cache-Control'], 'public, max-age=4838400')
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
910
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
911 def test_cache_control_js(self):
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
912 f = requests.get(self.url_base() + '/@@file/help_controls.js',
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
913 headers = {'content-type': "",
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
914 'Accept': '*/*'})
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
915 print(f.status_code)
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
916 print(f.headers)
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
917
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
918 self.assertEqual(f.status_code, 200)
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
919 self.assertEqual(f.headers['Cache-Control'], 'public, max-age=1209600')
c58c7cd31243 issue2550991 - Some mechanism to set expiration header or max age for static resources
John Rouillard <rouilj@ieee.org>
parents: 6541
diff changeset
920
6813
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
921 def test_missing_session_key(self):
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
922 '''Test case where we have an outdated session cookie. Make
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
923 sure cookie is removed.
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
924 '''
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
925 session = requests.Session()
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
926 session.headers.update({'Origin': 'http://localhost:9001'})
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
927
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
928 # login using form to get cookie
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
929 login = {"__login_name": 'admin', '__login_password': 'sekrit',
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
930 "@action": "login"}
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
931 f = session.post(self.url_base()+'/', data=login)
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
932
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
933 # verify cookie is present and we are logged in
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
934 self.assertIn('<b>Hello, admin</b>', f.text)
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
935 self.assertIn('roundup_session_Roundupissuetracker',
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
936 session.cookies)
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
937
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
938 f = session.get(self.url_base()+'/')
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
939 self.assertIn('<b>Hello, admin</b>', f.text)
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
940
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
941 for cookie in session.cookies:
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
942 if cookie.name == 'roundup_session_Roundupissuetracker':
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
943 cookie.value = 'bad_cookie_no_chocolate'
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
944 break
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
945
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
946 f = session.get(self.url_base()+'/')
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
947
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
948 self.assertNotIn('<b>Hello, admin</b>', f.text)
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
949 self.assertNotIn('roundup_session_Roundupissuetracker', session.cookies)
6b636fb29740 Refactor client.py session cookie code. Remove session db access.
John Rouillard <rouilj@ieee.org>
parents: 6758
diff changeset
950
6750
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
951 def test_login_fail_then_succeed(self):
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
952 # Set up session to manage cookies <insert blue monster here>
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
953 session = requests.Session()
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
954 session.headers.update({'Origin': 'http://localhost:9001'})
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
955
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
956 # login using form
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
957 login = {"__login_name": 'admin', '__login_password': 'bad_sekrit',
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
958 "@action": "login"}
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
959 f = session.post(self.url_base()+'/', data=login)
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
960 # verify error message and no hello message in sidebar.
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
961 self.assertIn('class="error-message">Invalid login <br/ >', f.text)
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
962 self.assertNotIn('<b>Hello, admin</b>', f.text)
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
963
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
964 # login using form
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
965 login = {"__login_name": 'admin', '__login_password': 'sekrit',
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
966 "@action": "login"}
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
967 f = session.post(self.url_base()+'/', data=login)
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
968 # look for change in text in sidebar post login
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
969 self.assertIn('<b>Hello, admin</b>', f.text)
c63ddea96fcb Test form login failure code path.
John Rouillard <rouilj@ieee.org>
parents: 6749
diff changeset
970
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
971 def test__generic_item_template_editok(self, user="admin"):
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
972 """Load /status1 object. Admin has edit rights so should see
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
973 a submit button. fred doesn't have edit rights
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
974 so should not have a submit button.
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
975 """
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
976 # Set up session to manage cookies <insert blue monster here>
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
977 session = requests.Session()
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
978 session.headers.update({'Origin': self.url_base()})
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
979
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
980 # login using form
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
981 login = {"__login_name": user, '__login_password': 'sekrit',
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
982 "@action": "login"}
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
983 f = session.post(self.url_base()+'/', data=login)
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
984 # look for change in text in sidebar post login
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
985 self.assertIn('Hello, %s'%user, f.text)
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
986 f = session.post(self.url_base()+'/status7', data=login)
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
987 print(f.content)
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
988
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
989 # status1's name is unread
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
990 self.assertIn(b'done-cbb', f.content)
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
991
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
992 if user == 'admin':
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
993 self.assertIn(b'<input name="submit_button" type="submit" value="Submit Changes">', f.content)
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
994 else:
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
995 self.assertNotIn(b'<input name="submit_button" type="submit" value="Submit Changes">', f.content)
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
996
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
997 # logout
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
998 f = session.get(self.url_base()+'/?@action=logout')
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
999 self.assertIn(b"Remember me?", f.content)
6756
1572568fe146 See if explicit logout prevents fred from having a submit button.
John Rouillard <rouilj@ieee.org>
parents: 6755
diff changeset
1000
6758
6d4ac1ae2ae8 Mark test__generic_item_template_editbad as xfail
John Rouillard <rouilj@ieee.org>
parents: 6757
diff changeset
1001 @pytest.mark.xfail
6757
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
1002 def test__generic_item_template_editbad(self, user="fred"):
f6dd6cd920bc Split edit ok and edit not ok test into two tests.
John Rouillard <rouilj@ieee.org>
parents: 6756
diff changeset
1003 self.test__generic_item_template_editok(user=user)
6754
bb04638dc78d Test _generic.item.html to mke sure submit button displayed properly
John Rouillard <rouilj@ieee.org>
parents: 6750
diff changeset
1004
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1005 def test_new_issue_with_file_upload(self):
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1006 # Set up session to manage cookies <insert blue monster here>
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1007 session = requests.Session()
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1008 session.headers.update({'Origin': 'http://localhost:9001'})
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1009
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1010 # login using form
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1011 login = {"__login_name": 'admin', '__login_password': 'sekrit',
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1012 "@action": "login"}
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1013 f = session.post(self.url_base()+'/', data=login)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1014 # look for change in text in sidebar post login
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1015 self.assertIn('Hello, admin', f.text)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1016
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1017 # create a new issue and upload a file
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1018 file_content = 'this is a test file\n'
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1019 file = {"@file": ('test1.txt', file_content, "text/plain") }
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1020 issue = {"title": "my title", "priority": "1", "@action": "new"}
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1021 f = session.post(self.url_base()+'/issue?@template=item', data=issue, files=file)
6570
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1022
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1023 # use redirected url to determine which issue and file were created.
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1024 m = re.search(r'[0-9]/issue(?P<issue>[0-9]+)\?@ok_message.*file%20(?P<file>[0-9]+)%20', f.url)
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1025
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1026 # verify message in redirected url: file 1 created\nissue 1 created
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1027 # warning may fail if another test loads tracker with files.
6570
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1028 # Escape % signs in string by doubling them. This verifies the
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1029 # search is working correctly.
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1030 # use groupdict for python2.
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1031 self.assertEqual('http://localhost:9001/issue%(issue)s?@ok_message=file%%20%(file)s%%20created%%0Aissue%%20%(issue)s%%20created&@template=item'%m.groupdict(), f.url)
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1032
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1033 # we have an issue display, verify filename is listed there
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1034 # seach for unique filename given to it.
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1035 self.assertIn("test1.txt", f.text)
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1036
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1037 # download file and verify content
6570
198875530c04 fix test_new_issue_with_file_upload
John Rouillard <rouilj@ieee.org>
parents: 6569
diff changeset
1038 f = session.get(self.url_base()+'/file%(file)s/text1.txt'%m.groupdict())
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1039 self.assertEqual(f.text, file_content)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1040 print(f.text)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1041
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1042 def test_new_file_via_rest(self):
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1043
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1044 session = requests.Session()
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1045 session.auth = ('admin', 'sekrit')
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1046
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1047 url = self.url_base() + '/rest/data/'
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1048 fname = 'a-bigger-testfile'
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1049 d = dict(name = fname, type='application/octet-stream')
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1050 c = dict (content = r'xyzzy')
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1051 r = session.post(url + 'file', files = c, data = d,
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1052 headers = {'x-requested-with': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1053 'Origin': "http://localhost:9001"}
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1054 )
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1055
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1056 # was a 500 before fix for issue2551178
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1057 self.assertEqual(r.status_code, 201)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1058 # just compare the path leave off the number
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1059 self.assertIn('http://localhost:9001/rest/data/file/',
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1060 r.headers["location"])
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1061 json_dict = json.loads(r.text)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1062 self.assertEqual(json_dict["data"]["link"], r.headers["location"])
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1063
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1064 # download file and verify content
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1065 r = session.get(r.headers["location"] +'/content',
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1066 headers = {'x-requested-with': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1067 'Origin': "http://localhost:9001"}
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1068 )
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1069 json_dict = json.loads(r.text)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1070 self.assertEqual(json_dict['data']['data'], c["content"])
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1071 print(r.text)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1072
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1073 # Upload a file via rest interface - no auth
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1074 session.auth = None
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1075 r = session.post(url + 'file', files = c, data = d,
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1076 headers = {'x-requested-with': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1077 'Origin': "http://localhost:9001"}
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1078 )
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1079 self.assertEqual(r.status_code, 403)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1080
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1081 # get session variable from web form login
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1082 # and use it to upload file
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1083 # login using form
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1084 login = {"__login_name": 'admin', '__login_password': 'sekrit',
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1085 "@action": "login"}
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1086 f = session.post(self.url_base()+'/', data=login,
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1087 headers = {'Origin': "http://localhost:9001"}
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1088 )
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1089 # look for change in text in sidebar post login
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1090 self.assertIn('Hello, admin', f.text)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1091
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1092 r = session.post(url + 'file', files = c, data = d,
6693
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1093 headers = {'x-requested-with': "rest",
9a1f5e496e6c issue2551203 - Add support for CORS preflight request
John Rouillard <rouilj@ieee.org>
parents: 6655
diff changeset
1094 'Origin': "http://localhost:9001"}
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1095 )
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1096 self.assertEqual(r.status_code, 201)
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1097 print(r.status_code)
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1098
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1099 def test_fts(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1100 f = requests.get(self.url_base() + "?@search_text=RESULT")
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1101 self.assertIn("foo bar", f.text)
6567
34199d2fef48 issue2551178 - Traceback in Apache WSGI (file upload)
John Rouillard <rouilj@ieee.org>
parents: 6548
diff changeset
1102
6747
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1103 class TestFeatureFlagCacheTrackerOn(BaseTestCases, WsgiSetup):
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1104 """Class to run all test in BaseTestCases with the cache_tracker
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1105 feature flag enabled when starting the wsgi server
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1106 """
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1107 def create_app(self):
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1108 '''The wsgi app to start with feature flag enabled'''
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1109 ff = { "cache_tracker": "" }
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1110 if _py3:
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1111 return validator(RequestDispatcher(self.dirname, feature_flags=ff))
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1112 else:
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1113 # wsgiref/validator.py InputWrapper::readline is broke and
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1114 # doesn't support the max bytes to read argument.
d32d43e4a5ba wsgi can cache tracker instance enabled by feature flag.
John Rouillard <rouilj@ieee.org>
parents: 6693
diff changeset
1115 return RequestDispatcher(self.dirname, feature_flags=ff)
6915
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1116
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1117 class TestPostgresWsgiServer(BaseTestCases, WsgiSetup):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1118 """Class to run all test in BaseTestCases with the cache_tracker
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1119 feature flag enabled when starting the wsgi server
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1120 """
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1121
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1122 backend = 'postgresql'
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1123
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1124 @classmethod
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1125 def setup_class(cls):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1126 '''All tests in this class use the same roundup instance.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1127 This instance persists across all tests.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1128 Create the tracker dir here so that it is ready for the
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1129 create_app() method to be called.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1130
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1131 cribbed from WsgiSetup::setup_class
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1132 '''
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1133
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1134 # tests in this class.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1135 # set up and open a tracker
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1136 cls.instance = db_test_base.setupTracker(cls.dirname, cls.backend)
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1137
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1138 # open the database
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1139 cls.db = cls.instance.open('admin')
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1140
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1141 # add a user without edit access for status.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1142 cls.db.user.create(username="fred", roles='User',
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1143 password=password.Password('sekrit'), address='fred@example.com')
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1144
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1145 # set the url the test instance will run at.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1146 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1147 # set up mailhost so errors get reported to debuging capture file
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1148 cls.db.config.MAILHOST = "localhost"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1149 cls.db.config.MAIL_HOST = "localhost"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1150 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1151
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1152 # added to enable csrf forgeries/CORS to be tested
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1153 cls.db.config.WEB_CSRF_ENFORCE_HEADER_ORIGIN = "required"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1154 cls.db.config.WEB_ALLOWED_API_ORIGINS = "https://client.com"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1155 cls.db.config['WEB_CSRF_ENFORCE_HEADER_X-REQUESTED-WITH'] = "required"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1156
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1157 cls.db.config.INDEXER = "native-fts"
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1158
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1159 # disable web login rate limiting. The fast rate of tests
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1160 # causes them to trip the rate limit and fail.
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1161 cls.db.config.WEB_LOGIN_ATTEMPTS_MIN = 0
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1162
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1163 # enable static precompressed files
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1164 cls.db.config.WEB_USE_PRECOMPRESSED_FILES = 1
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1165
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1166 cls.db.config.save()
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1167
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1168 cls.db.commit()
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1169 cls.db.close()
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1170
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1171 # re-open the database to get the updated INDEXER
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1172 cls.db = cls.instance.open('admin')
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1173
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1174 result = cls.db.issue.create(title="foo bar RESULT")
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1175
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1176 cls.db.commit()
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1177 cls.db.close()
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1178
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1179 # Force locale config to find locales in checkout not in
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1180 # installed directories
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1181 cls.backup_domain = i18n.DOMAIN
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1182 cls.backup_locale_dirs = i18n.LOCALE_DIRS
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1183 i18n.LOCALE_DIRS = ['locale']
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1184 i18n.DOMAIN = ''
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1185
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1186 def test_native_fts(self):
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1187 self.assertIn("postgresql_fts", str(self.db.indexer))
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1188
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1189 # use a ts: search as well so it only works on postgres_fts indexer
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1190 f = requests.get(self.url_base() + "?@search_text=ts:RESULT")
9ff091537f43 postgresql native-fts; more indexer tests
John Rouillard <rouilj@ieee.org>
parents: 6897
diff changeset
1191 self.assertIn("foo bar RESULT", f.text)

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