##// 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 19 import threading
20 20 import time
21 import sys
21 22 import logging
22 23 import os.path
23 24 import subprocess
@@ -31,7 +32,7 b' from urllib.parse import unquote_plus'
31 32 import webob
32 33
33 34 from webtest.app import TestResponse, TestApp
34 from webtest.compat import print_stderr
35
35 36
36 37 import pytest
37 38
@@ -51,6 +52,10 b' from rhodecode.tests import login_user_s'
51 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 59 class CustomTestResponse(TestResponse):
55 60
56 61 def _save_output(self, out):
@@ -60,7 +65,7 b' class CustomTestResponse(TestResponse):'
60 65
61 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 69 in as arguments.
65 70
66 71 Equivalent to::
@@ -68,6 +73,8 b' class CustomTestResponse(TestResponse):'
68 73 assert string in res
69 74 """
70 75 print_body = kw.pop('print_body', False)
76 print_to = kw.pop('print_to', sys.stderr)
77
71 78 if 'no' in kw:
72 79 no = kw['no']
73 80 del kw['no']
@@ -82,18 +89,18 b' class CustomTestResponse(TestResponse):'
82 89
83 90 for s in strings:
84 91 if s not in self:
85 print_stderr(f"Actual response (no {s!r}):")
86 print_stderr(f"body output saved as `{f}`")
92 print_to_func(f"Actual response (no {s!r}):", print_to=print_to)
93 print_to_func(f"body output saved as `{f}`", print_to=print_to)
87 94 if print_body:
88 print_stderr(str(self))
95 print_to_func(str(self), print_to=print_to)
89 96 raise IndexError(f"Body does not contain string {s!r}, body output saved as {f}")
90 97
91 98 for no_s in no:
92 99 if no_s in self:
93 print_stderr(f"Actual response (has {no_s!r})")
94 print_stderr(f"body output saved as `{f}`")
100 print_to_func(f"Actual response (has {no_s!r})", print_to=print_to)
101 print_to_func(f"body output saved as `{f}`", print_to=print_to)
95 102 if print_body:
96 print_stderr(str(self))
103 print_to_func(str(self), print_to=print_to)
97 104 raise IndexError(f"Body contains bad string {no_s!r}, body output saved as {f}")
98 105
99 106 def assert_response(self):
General Comments 0
You need to be logged in to leave comments. Login now