Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 6570:198875530c04
fix test_new_issue_with_file_upload
file designator can change if tests running before this add/remove
files.
Create the issue and use the returned url to extract the issue number
and file number from the redirected url and the @ok_message param
respectively. Use these values for the rest of the steps.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 21 Dec 2021 18:53:55 -0500 |
| parents | 3ae0c0fb2d08 |
| children | 6ac3667706be |
comparison
equal
deleted
inserted
replaced
| 6569:3ae0c0fb2d08 | 6570:198875530c04 |
|---|---|
| 1 import shutil, errno, pytest, json, gzip, os | 1 import shutil, errno, pytest, json, gzip, os, re |
| 2 | 2 |
| 3 from roundup.anypy.strings import b2s | 3 from roundup.anypy.strings import b2s |
| 4 from roundup.cgi.wsgi_handler import RequestDispatcher | 4 from roundup.cgi.wsgi_handler import RequestDispatcher |
| 5 from .wsgi_liveserver import LiveServerTestCase | 5 from .wsgi_liveserver import LiveServerTestCase |
| 6 from . import db_test_base | 6 from . import db_test_base |
| 899 print(f.headers) | 899 print(f.headers) |
| 900 | 900 |
| 901 self.assertEqual(f.status_code, 200) | 901 self.assertEqual(f.status_code, 200) |
| 902 self.assertEqual(f.headers['Cache-Control'], 'public, max-age=1209600') | 902 self.assertEqual(f.headers['Cache-Control'], 'public, max-age=1209600') |
| 903 | 903 |
| 904 @pytest.mark.xfail(reason="Work in progress") | |
| 905 def test_new_issue_with_file_upload(self): | 904 def test_new_issue_with_file_upload(self): |
| 906 # Set up session to manage cookies <insert blue monster here> | 905 # Set up session to manage cookies <insert blue monster here> |
| 907 session = requests.Session() | 906 session = requests.Session() |
| 908 | 907 |
| 909 # login using form | 908 # login using form |
| 916 # create a new issue and upload a file | 915 # create a new issue and upload a file |
| 917 file_content = 'this is a test file\n' | 916 file_content = 'this is a test file\n' |
| 918 file = {"@file": ('test1.txt', file_content, "text/plain") } | 917 file = {"@file": ('test1.txt', file_content, "text/plain") } |
| 919 issue = {"title": "my title", "priority": "1", "@action": "new"} | 918 issue = {"title": "my title", "priority": "1", "@action": "new"} |
| 920 f = session.post(self.url_base()+'/issue?@template=item', data=issue, files=file) | 919 f = session.post(self.url_base()+'/issue?@template=item', data=issue, files=file) |
| 921 # we have an issue display, verify filename is listed there | 920 |
| 922 self.assertIn("test1.txt", f.text) | 921 # use redirected url to determine which issue and file were created. |
| 922 m = re.search(r'[0-9]/issue(?P<issue>[0-9]+)\?@ok_message.*file%20(?P<file>[0-9]+)%20', f.url) | |
| 923 | |
| 923 # verify message in redirected url: file 1 created\nissue 1 created | 924 # verify message in redirected url: file 1 created\nissue 1 created |
| 924 # warning may fail if another test loads tracker with files. | 925 # warning may fail if another test loads tracker with files. |
| 925 self.assertEqual('http://localhost:9001/issue1?@ok_message=file%201%20created%0Aissue%201%20created&@template=item', f.url) | 926 # Escape % signs in string by doubling them. This verifies the |
| 927 # search is working correctly. | |
| 928 # use groupdict for python2. | |
| 929 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) | |
| 930 | |
| 931 # we have an issue display, verify filename is listed there | |
| 932 # seach for unique filename given to it. | |
| 933 self.assertIn("test1.txt", f.text) | |
| 926 | 934 |
| 927 # download file and verify content | 935 # download file and verify content |
| 928 f = session.get(self.url_base()+'/file1/text1.txt') | 936 f = session.get(self.url_base()+'/file%(file)s/text1.txt'%m.groupdict()) |
| 929 self.assertEqual(f.text, file_content) | 937 self.assertEqual(f.text, file_content) |
| 930 print(f.text) | 938 print(f.text) |
| 931 | 939 |
| 932 def test_new_file_via_rest(self): | 940 def test_new_file_via_rest(self): |
| 933 | 941 |
