##// END OF EJS Templates
chore(tests): add more flexibility to where we want to print mustcontain output for testing response
super-admin -
r5190:9f610147 default
parent child Browse files
Show More
@@ -18,6 +18,7 b''
18
18
19 import threading
19 import threading
20 import time
20 import time
21 import sys
21 import logging
22 import logging
22 import os.path
23 import os.path
23 import subprocess
24 import subprocess
@@ -31,7 +32,7 b' from urllib.parse import unquote_plus'
31 import webob
32 import webob
32
33
33 from webtest.app import TestResponse, TestApp
34 from webtest.app import TestResponse, TestApp
34 from webtest.compat import print_stderr
35
35
36
36 import pytest
37 import pytest
37
38
@@ -51,6 +52,10 b' from rhodecode.tests import login_user_s'
51 log = logging.getLogger(__name__)
52 log = logging.getLogger(__name__)
52
53
53
54
55 def print_to_func(value, print_to=sys.stderr):
56 print(value, file=print_to)
57
58
54 class CustomTestResponse(TestResponse):
59 class CustomTestResponse(TestResponse):
55
60
56 def _save_output(self, out):
61 def _save_output(self, out):
@@ -60,7 +65,7 b' class CustomTestResponse(TestResponse):'
60
65
61 def mustcontain(self, *strings, **kw):
66 def mustcontain(self, *strings, **kw):
62 """
67 """
63 Assert that the response contains all of the strings passed
68 Assert that the response contains all the strings passed
64 in as arguments.
69 in as arguments.
65
70
66 Equivalent to::
71 Equivalent to::
@@ -68,6 +73,8 b' class CustomTestResponse(TestResponse):'
68 assert string in res
73 assert string in res
69 """
74 """
70 print_body = kw.pop('print_body', False)
75 print_body = kw.pop('print_body', False)
76 print_to = kw.pop('print_to', sys.stderr)
77
71 if 'no' in kw:
78 if 'no' in kw:
72 no = kw['no']
79 no = kw['no']
73 del kw['no']
80 del kw['no']
@@ -82,18 +89,18 b' class CustomTestResponse(TestResponse):'
82
89
83 for s in strings:
90 for s in strings:
84 if s not in self:
91 if s not in self:
85 print_stderr(f"Actual response (no {s!r}):")
92 print_to_func(f"Actual response (no {s!r}):", print_to=print_to)
86 print_stderr(f"body output saved as `{f}`")
93 print_to_func(f"body output saved as `{f}`", print_to=print_to)
87 if print_body:
94 if print_body:
88 print_stderr(str(self))
95 print_to_func(str(self), print_to=print_to)
89 raise IndexError(f"Body does not contain string {s!r}, body output saved as {f}")
96 raise IndexError(f"Body does not contain string {s!r}, body output saved as {f}")
90
97
91 for no_s in no:
98 for no_s in no:
92 if no_s in self:
99 if no_s in self:
93 print_stderr(f"Actual response (has {no_s!r})")
100 print_to_func(f"Actual response (has {no_s!r})", print_to=print_to)
94 print_stderr(f"body output saved as `{f}`")
101 print_to_func(f"body output saved as `{f}`", print_to=print_to)
95 if print_body:
102 if print_body:
96 print_stderr(str(self))
103 print_to_func(str(self), print_to=print_to)
97 raise IndexError(f"Body contains bad string {no_s!r}, body output saved as {f}")
104 raise IndexError(f"Body contains bad string {no_s!r}, body output saved as {f}")
98
105
99 def assert_response(self):
106 def assert_response(self):
General Comments 0
You need to be logged in to leave comments. Login now