Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 8248:f6923d2ba9a5
test: issue2551366. Probe for open port in test_liveserver.py
Add a method to probe for an open port to wsgi_liveserver.py. Start
the roundup server under wsgi on the open port. If a port can't be
found, it skips all tests.
Also changed all hardcoded URL references to use the dynamicly
determined tracker url/port value.
I fed my patch to wsgi_liveserver.py upstream at:
https://github.com/jerrykan/wsgi-liveserver/issues/3
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 31 Dec 2024 23:48:38 -0500 |
| parents | 393dfc750d8b |
| children | cae1bbf2536b |
comparison
equal
deleted
inserted
replaced
| 8247:6747051fef79 | 8248:f6923d2ba9a5 |
|---|---|
| 77 @skip_requests | 77 @skip_requests |
| 78 class WsgiSetup(LiveServerTestCase): | 78 class WsgiSetup(LiveServerTestCase): |
| 79 # have chicken and egg issue here. Need to encode the base_url | 79 # have chicken and egg issue here. Need to encode the base_url |
| 80 # in the config file but we don't know it until after | 80 # in the config file but we don't know it until after |
| 81 # the server is started and has read the config.ini. | 81 # the server is started and has read the config.ini. |
| 82 # so only allow one port number | 82 # Probe for an unused port and set the port range to |
| 83 port_range = (9001, 9001) # default is (8080, 8090) | 83 # include only that port. |
| 84 tracker_port = LiveServerTestCase.probe_ports(8080, 8100) | |
| 85 if tracker_port is None: | |
| 86 pytest.skip("Unable to find available port for server: 8080-8100", | |
| 87 allow_module_level=True) | |
| 88 port_range = (tracker_port, tracker_port) | |
| 89 | |
| 90 # set a couple of properties to use for URL generation in | |
| 91 # expected output or use to set TRACKER_WEB in config.ini. | |
| 92 tracker_web = "http://localhost:%d/" % tracker_port | |
| 93 # tracker_web_base should be the same as self.base_url() | |
| 94 tracker_web_base = "http://localhost:%d" % tracker_port | |
| 84 | 95 |
| 85 dirname = '_test_instance' | 96 dirname = '_test_instance' |
| 86 backend = 'anydbm' | 97 backend = 'anydbm' |
| 87 | 98 |
| 88 js_mime_type = mimetypes.guess_type("utils.js")[0] | 99 js_mime_type = mimetypes.guess_type("utils.js")[0] |
| 104 # add a user without edit access for status. | 115 # add a user without edit access for status. |
| 105 cls.db.user.create(username="fred", roles='User', | 116 cls.db.user.create(username="fred", roles='User', |
| 106 password=password.Password('sekrit'), address='fred@example.com') | 117 password=password.Password('sekrit'), address='fred@example.com') |
| 107 | 118 |
| 108 # set the url the test instance will run at. | 119 # set the url the test instance will run at. |
| 109 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/" | 120 cls.db.config['TRACKER_WEB'] = cls.tracker_web |
| 110 # set up mailhost so errors get reported to debuging capture file | 121 # set up mailhost so errors get reported to debuging capture file |
| 111 cls.db.config.MAILHOST = "localhost" | 122 cls.db.config.MAILHOST = "localhost" |
| 112 cls.db.config.MAIL_HOST = "localhost" | 123 cls.db.config.MAIL_HOST = "localhost" |
| 113 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log" | 124 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log" |
| 114 | 125 |
| 188 """ | 199 """ |
| 189 | 200 |
| 190 def create_login_session(self, username="admin", password="sekrit", | 201 def create_login_session(self, username="admin", password="sekrit", |
| 191 return_response=True, expect_login_ok=True): | 202 return_response=True, expect_login_ok=True): |
| 192 # Set up session to manage cookies <insert blue monster here> | 203 # Set up session to manage cookies <insert blue monster here> |
| 204 | |
| 193 session = requests.Session() | 205 session = requests.Session() |
| 194 session.headers.update({'Origin': 'http://localhost:9001'}) | 206 session.headers.update({'Origin': self.tracker_web_base}) |
| 195 | 207 |
| 196 # login using form to get cookie | 208 # login using form to get cookie |
| 197 login = {"__login_name": username, '__login_password': password, | 209 login = {"__login_name": username, '__login_password': password, |
| 198 "@action": "login"} | 210 "@action": "login"} |
| 199 response = session.post(self.url_base()+'/', data=login) | 211 response = session.post(self.url_base()+'/', data=login) |
| 745 def test_rest_endpoint_root_options(self): | 757 def test_rest_endpoint_root_options(self): |
| 746 # use basic auth for rest endpoint | 758 # use basic auth for rest endpoint |
| 747 f = requests.options(self.url_base() + '/rest', | 759 f = requests.options(self.url_base() + '/rest', |
| 748 auth=('admin', 'sekrit'), | 760 auth=('admin', 'sekrit'), |
| 749 headers = {'content-type': "", | 761 headers = {'content-type': "", |
| 750 'Origin': "http://localhost:9001", | 762 'Origin': self.tracker_web_base, |
| 751 }) | 763 }) |
| 752 print(f.status_code) | 764 print(f.status_code) |
| 753 print(f.headers) | 765 print(f.headers) |
| 754 | 766 |
| 755 self.assertEqual(f.status_code, 204) | 767 self.assertEqual(f.status_code, 204) |
| 756 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001', | 768 expected = { 'Access-Control-Allow-Origin': self.tracker_web_base, |
| 757 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', | 769 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', |
| 758 'Allow': 'OPTIONS, GET', | 770 'Allow': 'OPTIONS, GET', |
| 759 'Access-Control-Allow-Credentials': 'true', | 771 'Access-Control-Allow-Credentials': 'true', |
| 760 'Access-Control-Allow-Methods': 'OPTIONS, GET', | 772 'Access-Control-Allow-Methods': 'OPTIONS, GET', |
| 761 'Access-Control-Allow-Credentials': 'true', | 773 'Access-Control-Allow-Credentials': 'true', |
| 768 def test_rest_endpoint_data_options(self): | 780 def test_rest_endpoint_data_options(self): |
| 769 # use basic auth for rest endpoint | 781 # use basic auth for rest endpoint |
| 770 f = requests.options(self.url_base() + '/rest/data', | 782 f = requests.options(self.url_base() + '/rest/data', |
| 771 auth=('admin', 'sekrit'), | 783 auth=('admin', 'sekrit'), |
| 772 headers = {'content-type': "", | 784 headers = {'content-type': "", |
| 773 'Origin': "http://localhost:9001", | 785 'Origin': self.tracker_web_base, |
| 774 }) | 786 }) |
| 775 print(f.status_code) | 787 print(f.status_code) |
| 776 print(f.headers) | 788 print(f.headers) |
| 777 | 789 |
| 778 self.assertEqual(f.status_code, 204) | 790 self.assertEqual(f.status_code, 204) |
| 779 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001', | 791 expected = { 'Access-Control-Allow-Origin': self.tracker_web_base, |
| 780 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', | 792 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', |
| 781 'Allow': 'OPTIONS, GET', | 793 'Allow': 'OPTIONS, GET', |
| 782 'Access-Control-Allow-Methods': 'OPTIONS, GET', | 794 'Access-Control-Allow-Methods': 'OPTIONS, GET', |
| 783 'Access-Control-Allow-Credentials': 'true', | 795 'Access-Control-Allow-Credentials': 'true', |
| 784 } | 796 } |
| 790 def test_rest_endpoint_collection_options(self): | 802 def test_rest_endpoint_collection_options(self): |
| 791 # use basic auth for rest endpoint | 803 # use basic auth for rest endpoint |
| 792 f = requests.options(self.url_base() + '/rest/data/user', | 804 f = requests.options(self.url_base() + '/rest/data/user', |
| 793 auth=('admin', 'sekrit'), | 805 auth=('admin', 'sekrit'), |
| 794 headers = {'content-type': "", | 806 headers = {'content-type': "", |
| 795 'Origin': "http://localhost:9001", | 807 'Origin': self.tracker_web_base, |
| 796 }) | 808 }) |
| 797 print(f.status_code) | 809 print(f.status_code) |
| 798 print(f.headers) | 810 print(f.headers) |
| 799 | 811 |
| 800 self.assertEqual(f.status_code, 204) | 812 self.assertEqual(f.status_code, 204) |
| 801 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001', | 813 expected = { 'Access-Control-Allow-Origin': self.tracker_web_base, |
| 802 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', | 814 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', |
| 803 'Allow': 'OPTIONS, GET, POST', | 815 'Allow': 'OPTIONS, GET, POST', |
| 804 'Access-Control-Allow-Methods': 'OPTIONS, GET, POST', | 816 'Access-Control-Allow-Methods': 'OPTIONS, GET, POST', |
| 805 'Access-Control-Allow-Credentials': 'true', | 817 'Access-Control-Allow-Credentials': 'true', |
| 806 } | 818 } |
| 813 def test_rest_endpoint_item_options(self): | 825 def test_rest_endpoint_item_options(self): |
| 814 | 826 |
| 815 f = requests.options(self.url_base() + '/rest/data/user/1', | 827 f = requests.options(self.url_base() + '/rest/data/user/1', |
| 816 auth=('admin', 'sekrit'), | 828 auth=('admin', 'sekrit'), |
| 817 headers = {'content-type': "", | 829 headers = {'content-type': "", |
| 818 'Origin': "http://localhost:9001", | 830 'Origin': self.tracker_web_base, |
| 819 }) | 831 }) |
| 820 print(f.status_code) | 832 print(f.status_code) |
| 821 print(f.headers) | 833 print(f.headers) |
| 822 | 834 |
| 823 self.assertEqual(f.status_code, 204) | 835 self.assertEqual(f.status_code, 204) |
| 824 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001', | 836 expected = { 'Access-Control-Allow-Origin': self.tracker_web_base, |
| 825 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', | 837 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', |
| 826 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', | 838 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', |
| 827 'Access-Control-Allow-Methods': 'OPTIONS, GET, PUT, DELETE, PATCH', | 839 'Access-Control-Allow-Methods': 'OPTIONS, GET, PUT, DELETE, PATCH', |
| 828 'Access-Control-Allow-Credentials': 'true', | 840 'Access-Control-Allow-Credentials': 'true', |
| 829 } | 841 } |
| 835 def test_rest_endpoint_attribute_options(self): | 847 def test_rest_endpoint_attribute_options(self): |
| 836 # use basic auth for rest endpoint | 848 # use basic auth for rest endpoint |
| 837 f = requests.options(self.url_base() + '/rest/data/user/1/username', | 849 f = requests.options(self.url_base() + '/rest/data/user/1/username', |
| 838 auth=('admin', 'sekrit'), | 850 auth=('admin', 'sekrit'), |
| 839 headers = {'content-type': "", | 851 headers = {'content-type': "", |
| 840 'Origin': "http://localhost:9001", | 852 'Origin': self.tracker_web_base, |
| 841 }) | 853 }) |
| 842 print(f.status_code) | 854 print(f.status_code) |
| 843 print(f.headers) | 855 print(f.headers) |
| 844 | 856 |
| 845 self.assertEqual(f.status_code, 204) | 857 self.assertEqual(f.status_code, 204) |
| 846 expected = { 'Access-Control-Allow-Origin': 'http://localhost:9001', | 858 expected = { 'Access-Control-Allow-Origin': self.tracker_web_base, |
| 847 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', | 859 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Requested-With, X-HTTP-Method-Override', |
| 848 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', | 860 'Allow': 'OPTIONS, GET, PUT, DELETE, PATCH', |
| 849 'Access-Control-Allow-Methods': 'OPTIONS, GET, PUT, DELETE, PATCH', | 861 'Access-Control-Allow-Methods': 'OPTIONS, GET, PUT, DELETE, PATCH', |
| 850 'Access-Control-Allow-Credentials': 'true', | 862 'Access-Control-Allow-Credentials': 'true', |
| 851 } | 863 } |
| 857 ## test a read only property. | 869 ## test a read only property. |
| 858 | 870 |
| 859 f = requests.options(self.url_base() + '/rest/data/user/1/creator', | 871 f = requests.options(self.url_base() + '/rest/data/user/1/creator', |
| 860 auth=('admin', 'sekrit'), | 872 auth=('admin', 'sekrit'), |
| 861 headers = {'content-type': "", | 873 headers = {'content-type': "", |
| 862 'Origin': "http://localhost:9001", | 874 'Origin': self.tracker_web_base, |
| 863 }) | 875 }) |
| 864 print(f.status_code) | 876 print(f.status_code) |
| 865 print(f.headers) | 877 print(f.headers) |
| 866 | 878 |
| 867 self.assertEqual(f.status_code, 204) | 879 self.assertEqual(f.status_code, 204) |
| 875 | 887 |
| 876 ## test a property that doesn't exist | 888 ## test a property that doesn't exist |
| 877 f = requests.options(self.url_base() + '/rest/data/user/1/zot', | 889 f = requests.options(self.url_base() + '/rest/data/user/1/zot', |
| 878 auth=('admin', 'sekrit'), | 890 auth=('admin', 'sekrit'), |
| 879 headers = {'content-type': "", | 891 headers = {'content-type': "", |
| 880 'Origin': "http://localhost:9001",}) | 892 'Origin': self.tracker_web_base,}) |
| 881 print(f.status_code) | 893 print(f.status_code) |
| 882 print(f.headers) | 894 print(f.headers) |
| 883 | 895 |
| 884 self.assertEqual(f.status_code, 404) | 896 self.assertEqual(f.status_code, 404) |
| 885 | 897 |
| 886 def test_rest_endpoint_user_roles(self): | 898 def test_rest_endpoint_user_roles(self): |
| 887 # use basic auth for rest endpoint | 899 # use basic auth for rest endpoint |
| 888 f = requests.get(self.url_base() + '/rest/data/user/roles', | 900 f = requests.get(self.url_base() + '/rest/data/user/roles', |
| 889 auth=('admin', 'sekrit'), | 901 auth=('admin', 'sekrit'), |
| 890 headers = {'content-type': "", | 902 headers = {'content-type': "", |
| 891 'Origin': "http://localhost:9001", | 903 'Origin': self.tracker_web_base, |
| 892 }) | 904 }) |
| 893 print(f.status_code) | 905 print(f.status_code) |
| 894 print(f.headers) | 906 print(f.headers) |
| 895 | 907 |
| 896 self.assertEqual(f.status_code, 200) | 908 self.assertEqual(f.status_code, 200) |
| 1188 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH', | 1200 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH', |
| 1189 } | 1201 } |
| 1190 | 1202 |
| 1191 content_str = '''{ "data": { | 1203 content_str = '''{ "data": { |
| 1192 "id": "1", | 1204 "id": "1", |
| 1193 "link": "http://localhost:9001/rest/data/user/1/username", | 1205 "link": "%s/rest/data/user/1/username", |
| 1194 "data": "admin" | 1206 "data": "admin" |
| 1195 } | 1207 } |
| 1196 }''' | 1208 }''' % self.tracker_web_base |
| 1197 content = json.loads(content_str) | 1209 content = json.loads(content_str) |
| 1198 | 1210 |
| 1199 | 1211 |
| 1200 if (type("") == type(f.content)): | 1212 if (type("") == type(f.content)): |
| 1201 json_dict = json.loads(f.content) | 1213 json_dict = json.loads(f.content) |
| 1246 'Vary': 'Origin, Accept-Encoding', | 1258 'Vary': 'Origin, Accept-Encoding', |
| 1247 } | 1259 } |
| 1248 | 1260 |
| 1249 content_str = '''{ "data": { | 1261 content_str = '''{ "data": { |
| 1250 "id": "1", | 1262 "id": "1", |
| 1251 "link": "http://localhost:9001/rest/data/user/1/username", | 1263 "link": "%s/rest/data/user/1/username", |
| 1252 "data": "admin" | 1264 "data": "admin" |
| 1253 } | 1265 } |
| 1254 }''' | 1266 }''' % self.tracker_web_base |
| 1255 content = json.loads(content_str) | 1267 content = json.loads(content_str) |
| 1256 | 1268 |
| 1257 print(f.content) | 1269 print(f.content) |
| 1258 print(type(f.content)) | 1270 print(type(f.content)) |
| 1259 | 1271 |
| 1494 # verify message in redirected url: file 1 created\nissue 1 created | 1506 # verify message in redirected url: file 1 created\nissue 1 created |
| 1495 # warning may fail if another test loads tracker with files. | 1507 # warning may fail if another test loads tracker with files. |
| 1496 # Escape % signs in string by doubling them. This verifies the | 1508 # Escape % signs in string by doubling them. This verifies the |
| 1497 # search is working correctly. | 1509 # search is working correctly. |
| 1498 # use groupdict for python2. | 1510 # use groupdict for python2. |
| 1499 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) | 1511 self.assertEqual( self.tracker_web_base + '/issue%(issue)s?@ok_message=file%%20%(file)s%%20created%%0Aissue%%20%(issue)s%%20created&@template=item'%m.groupdict(), f.url) |
| 1500 | 1512 |
| 1501 # we have an issue display, verify filename is listed there | 1513 # we have an issue display, verify filename is listed there |
| 1502 # seach for unique filename given to it. | 1514 # seach for unique filename given to it. |
| 1503 self.assertIn("test1.txt", f.text) | 1515 self.assertIn("test1.txt", f.text) |
| 1504 | 1516 |
| 1518 fname = 'a-bigger-testfile' | 1530 fname = 'a-bigger-testfile' |
| 1519 d = dict(name = fname, type='application/octet-stream') | 1531 d = dict(name = fname, type='application/octet-stream') |
| 1520 c = dict (content = r'xyzzy') | 1532 c = dict (content = r'xyzzy') |
| 1521 r = session.post(url + 'file', files = c, data = d, | 1533 r = session.post(url + 'file', files = c, data = d, |
| 1522 headers = {'x-requested-with': "rest", | 1534 headers = {'x-requested-with': "rest", |
| 1523 'Origin': "http://localhost:9001"} | 1535 'Origin': self.tracker_web_base} |
| 1524 ) | 1536 ) |
| 1525 | 1537 |
| 1526 # was a 500 before fix for issue2551178 | 1538 # was a 500 before fix for issue2551178 |
| 1527 self.assertEqual(r.status_code, 201) | 1539 self.assertEqual(r.status_code, 201) |
| 1528 # just compare the path leave off the number | 1540 # just compare the path leave off the number |
| 1529 self.assertIn('http://localhost:9001/rest/data/file/', | 1541 self.assertIn(self.tracker_web_base + '/rest/data/file/', |
| 1530 r.headers["location"]) | 1542 r.headers["location"]) |
| 1531 json_dict = json.loads(r.text) | 1543 json_dict = json.loads(r.text) |
| 1532 self.assertEqual(json_dict["data"]["link"], r.headers["location"]) | 1544 self.assertEqual(json_dict["data"]["link"], r.headers["location"]) |
| 1533 | 1545 |
| 1534 # download file and verify content | 1546 # download file and verify content |
| 1535 r = session.get(r.headers["location"] +'/content', | 1547 r = session.get(r.headers["location"] +'/content', |
| 1536 headers = {'x-requested-with': "rest", | 1548 headers = {'x-requested-with': "rest", |
| 1537 'Origin': "http://localhost:9001"} | 1549 'Origin': self.tracker_web_base} |
| 1538 ) | 1550 ) |
| 1539 json_dict = json.loads(r.text) | 1551 json_dict = json.loads(r.text) |
| 1540 self.assertEqual(json_dict['data']['data'], c["content"]) | 1552 self.assertEqual(json_dict['data']['data'], c["content"]) |
| 1541 print(r.text) | 1553 print(r.text) |
| 1542 | 1554 |
| 1543 # Upload a file via rest interface - no auth | 1555 # Upload a file via rest interface - no auth |
| 1544 session.auth = None | 1556 session.auth = None |
| 1545 r = session.post(url + 'file', files = c, data = d, | 1557 r = session.post(url + 'file', files = c, data = d, |
| 1546 headers = {'x-requested-with': "rest", | 1558 headers = {'x-requested-with': "rest", |
| 1547 'Origin': "http://localhost:9001"} | 1559 'Origin': self.tracker_web_base} |
| 1548 ) | 1560 ) |
| 1549 self.assertEqual(r.status_code, 403) | 1561 self.assertEqual(r.status_code, 403) |
| 1550 | 1562 |
| 1551 # get session variable from web form login | 1563 # get session variable from web form login |
| 1552 # and use it to upload file | 1564 # and use it to upload file |
| 1554 # look for change in text in sidebar post login | 1566 # look for change in text in sidebar post login |
| 1555 self.assertIn('Hello, admin', f.text) | 1567 self.assertIn('Hello, admin', f.text) |
| 1556 | 1568 |
| 1557 r = session.post(url + 'file', files = c, data = d, | 1569 r = session.post(url + 'file', files = c, data = d, |
| 1558 headers = {'x-requested-with': "rest", | 1570 headers = {'x-requested-with': "rest", |
| 1559 'Origin': "http://localhost:9001"} | 1571 'Origin': self.tracker_web_base} |
| 1560 ) | 1572 ) |
| 1561 self.assertEqual(r.status_code, 201) | 1573 self.assertEqual(r.status_code, 201) |
| 1562 print(r.status_code) | 1574 print(r.status_code) |
| 1563 | 1575 |
| 1564 def test_fts(self): | 1576 def test_fts(self): |
| 1609 # add a user without edit access for status. | 1621 # add a user without edit access for status. |
| 1610 cls.db.user.create(username="fred", roles='User', | 1622 cls.db.user.create(username="fred", roles='User', |
| 1611 password=password.Password('sekrit'), address='fred@example.com') | 1623 password=password.Password('sekrit'), address='fred@example.com') |
| 1612 | 1624 |
| 1613 # set the url the test instance will run at. | 1625 # set the url the test instance will run at. |
| 1614 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/" | 1626 cls.db.config['TRACKER_WEB'] = cls.tracker_web |
| 1615 # set up mailhost so errors get reported to debuging capture file | 1627 # set up mailhost so errors get reported to debuging capture file |
| 1616 cls.db.config.MAILHOST = "localhost" | 1628 cls.db.config.MAILHOST = "localhost" |
| 1617 cls.db.config.MAIL_HOST = "localhost" | 1629 cls.db.config.MAIL_HOST = "localhost" |
| 1618 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log" | 1630 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log" |
| 1619 | 1631 |
| 1697 # add a user without edit access for status. | 1709 # add a user without edit access for status. |
| 1698 cls.db.user.create(username="fred", roles='User', | 1710 cls.db.user.create(username="fred", roles='User', |
| 1699 password=password.Password('sekrit'), address='fred@example.com') | 1711 password=password.Password('sekrit'), address='fred@example.com') |
| 1700 | 1712 |
| 1701 # set the url the test instance will run at. | 1713 # set the url the test instance will run at. |
| 1702 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/" | 1714 cls.db.config['TRACKER_WEB'] = cls.tracker_web |
| 1703 # set up mailhost so errors get reported to debuging capture file | 1715 # set up mailhost so errors get reported to debuging capture file |
| 1704 cls.db.config.MAILHOST = "localhost" | 1716 cls.db.config.MAILHOST = "localhost" |
| 1705 cls.db.config.MAIL_HOST = "localhost" | 1717 cls.db.config.MAIL_HOST = "localhost" |
| 1706 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log" | 1718 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log" |
| 1707 | 1719 |
| 1759 # verify that valid logins are not counted against the limit. | 1771 # verify that valid logins are not counted against the limit. |
| 1760 for i in range(10): | 1772 for i in range(10): |
| 1761 # use basic auth for rest endpoint | 1773 # use basic auth for rest endpoint |
| 1762 | 1774 |
| 1763 request_headers = {'content-type': "", | 1775 request_headers = {'content-type': "", |
| 1764 'Origin': "http://localhost:9001",} | 1776 'Origin': self.tracker_web_base,} |
| 1765 f = requests.options(url_base_numeric + '/rest/data', | 1777 f = requests.options(url_base_numeric + '/rest/data', |
| 1766 auth=('admin', 'sekrit'), | 1778 auth=('admin', 'sekrit'), |
| 1767 headers=request_headers | 1779 headers=request_headers |
| 1768 ) | 1780 ) |
| 1769 #print(f.status_code) | 1781 #print(f.status_code) |
| 1796 # use basic auth for rest endpoint | 1808 # use basic auth for rest endpoint |
| 1797 | 1809 |
| 1798 f = requests.options(url_base_numeric + '/rest/data', | 1810 f = requests.options(url_base_numeric + '/rest/data', |
| 1799 auth=('admin', 'ekrit'), | 1811 auth=('admin', 'ekrit'), |
| 1800 headers = {'content-type': "", | 1812 headers = {'content-type': "", |
| 1801 'Origin': "http://localhost:9001",} | 1813 'Origin': self.tracker_web_base,} |
| 1802 ) | 1814 ) |
| 1803 | 1815 |
| 1804 if (i < 4): # assuming limit is 4. | 1816 if (i < 4): # assuming limit is 4. |
| 1805 for header in headers_expected.keys(): | 1817 for header in headers_expected.keys(): |
| 1806 self.assertEqual(f.headers[header], | 1818 self.assertEqual(f.headers[header], |
| 1833 # test lockout this is a valid login but should be rejected | 1845 # test lockout this is a valid login but should be rejected |
| 1834 # with 429. | 1846 # with 429. |
| 1835 f = requests.options(url_base_numeric + '/rest/data', | 1847 f = requests.options(url_base_numeric + '/rest/data', |
| 1836 auth=('admin', 'sekrit'), | 1848 auth=('admin', 'sekrit'), |
| 1837 headers = {'content-type': "", | 1849 headers = {'content-type': "", |
| 1838 'Origin': "http://localhost:9001",} | 1850 'Origin': self.tracker_web_base,} |
| 1839 ) | 1851 ) |
| 1840 self.assertEqual(f.status_code, 429) | 1852 self.assertEqual(f.status_code, 429) |
| 1841 | 1853 |
| 1842 for header in headers_expected.keys(): | 1854 for header in headers_expected.keys(): |
| 1843 self.assertEqual(f.headers[header], | 1855 self.assertEqual(f.headers[header], |
| 1848 # slept long enough to get a login slot. Should work with | 1860 # slept long enough to get a login slot. Should work with |
| 1849 # 200 return code. | 1861 # 200 return code. |
| 1850 f = requests.get(url_base_numeric + '/rest/data', | 1862 f = requests.get(url_base_numeric + '/rest/data', |
| 1851 auth=('admin', 'sekrit'), | 1863 auth=('admin', 'sekrit'), |
| 1852 headers = {'content-type': "", | 1864 headers = {'content-type': "", |
| 1853 'Origin': "http://localhost:9001",} | 1865 'Origin': self.tracker_web_base,} |
| 1854 ) | 1866 ) |
| 1855 self.assertEqual(f.status_code, 200) | 1867 self.assertEqual(f.status_code, 200) |
| 1856 print(i, f.status_code) | 1868 print(i, f.status_code) |
| 1857 print(f.headers) | 1869 print(f.headers) |
| 1858 print(f.text) | 1870 print(f.text) |
| 1866 'X-RateLimit-Reset, ' | 1878 'X-RateLimit-Reset, ' |
| 1867 'X-RateLimit-Limit-Period, ' | 1879 'X-RateLimit-Limit-Period, ' |
| 1868 'Retry-After, ' | 1880 'Retry-After, ' |
| 1869 'Sunset, ' | 1881 'Sunset, ' |
| 1870 'Allow'), | 1882 'Allow'), |
| 1871 'Access-Control-Allow-Origin': 'http://localhost:9001', | 1883 'Access-Control-Allow-Origin': self.tracker_web_base, |
| 1872 'Access-Control-Allow-Credentials': 'true', | 1884 'Access-Control-Allow-Credentials': 'true', |
| 1873 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH' | 1885 'Allow': 'OPTIONS, GET, POST, PUT, DELETE, PATCH' |
| 1874 } | 1886 } |
| 1875 | 1887 |
| 1876 for header in headers_expected.keys(): | 1888 for header in headers_expected.keys(): |
| 1877 self.assertEqual(f.headers[header], | 1889 self.assertEqual(f.headers[header], |
| 1878 headers_expected[header]) | 1890 headers_expected[header]) |
| 1879 | 1891 |
| 1880 expected_data = { | 1892 expected_data = { |
| 1881 "status": { | 1893 "status": { |
| 1882 "link": "http://localhost:9001/rest/data/status" | 1894 "link": self.tracker_web_base + "/rest/data/status" |
| 1883 }, | 1895 }, |
| 1884 "keyword": { | 1896 "keyword": { |
| 1885 "link": "http://localhost:9001/rest/data/keyword" | 1897 "link": self.tracker_web_base + "/rest/data/keyword" |
| 1886 }, | 1898 }, |
| 1887 "priority": { | 1899 "priority": { |
| 1888 "link": "http://localhost:9001/rest/data/priority" | 1900 "link": self.tracker_web_base + "/rest/data/priority" |
| 1889 }, | 1901 }, |
| 1890 "user": { | 1902 "user": { |
| 1891 "link": "http://localhost:9001/rest/data/user" | 1903 "link": self.tracker_web_base + "/rest/data/user" |
| 1892 }, | 1904 }, |
| 1893 "file": { | 1905 "file": { |
| 1894 "link": "http://localhost:9001/rest/data/file" | 1906 "link": self.tracker_web_base + "/rest/data/file" |
| 1895 }, | 1907 }, |
| 1896 "msg": { | 1908 "msg": { |
| 1897 "link": "http://localhost:9001/rest/data/msg" | 1909 "link": self.tracker_web_base + "/rest/data/msg" |
| 1898 }, | 1910 }, |
| 1899 "query": { | 1911 "query": { |
| 1900 "link": "http://localhost:9001/rest/data/query" | 1912 "link": self.tracker_web_base + "/rest/data/query" |
| 1901 }, | 1913 }, |
| 1902 "issue": { | 1914 "issue": { |
| 1903 "link": "http://localhost:9001/rest/data/issue" | 1915 "link": self.tracker_web_base + "/rest/data/issue" |
| 1904 } | 1916 } |
| 1905 } | 1917 } |
| 1906 | 1918 |
| 1907 json_dict = json.loads(f.text) | 1919 json_dict = json.loads(f.text) |
| 1908 self.assertEqual(json_dict['data'], expected_data) | 1920 self.assertEqual(json_dict['data'], expected_data) |
