Best Python code snippet using lemoncheesecake
test_filter.py
Source:test_filter.py
...973 lcc.set_step("some step")974 lcc.log_info("something")975 lcc.log_check("check", True, "1")976 lcc.log_url("http://www.example.com")977 lcc.save_attachment_content("A" * 100, "file.txt")978 _test_result_filter(979 suite,980 ResultFilter(grep=re.compile(r"foobar")),981 expected=()982 )983def test_result_filter_grep_step():984 @lcc.suite("suite")985 class suite(object):986 @lcc.test("test")987 def test(self):988 lcc.set_step("foobar")989 lcc.log_info("something")990 _test_result_filter(991 suite,992 ResultFilter(grep=re.compile(r"foobar")),993 expected=("suite.test",)994 )995def test_result_filter_grep_log():996 @lcc.suite("suite")997 class suite(object):998 @lcc.test("test")999 def test(self):1000 lcc.log_info("foobar")1001 _test_result_filter(1002 suite,1003 ResultFilter(grep=re.compile(r"foobar")),1004 expected=("suite.test",)1005 )1006def test_result_filter_grep_check_description():1007 @lcc.suite("suite")1008 class suite(object):1009 @lcc.test("test")1010 def test(self):1011 lcc.log_check("foobar", True)1012 _test_result_filter(1013 suite,1014 ResultFilter(grep=re.compile(r"foobar")),1015 expected=("suite.test",)1016 )1017def test_result_filter_grep_check_details():1018 @lcc.suite("suite")1019 class suite(object):1020 @lcc.test("test")1021 def test(self):1022 lcc.log_check("something", True, "foobar")1023 _test_result_filter(1024 suite,1025 ResultFilter(grep=re.compile(r"foobar")),1026 expected=("suite.test",)1027 )1028def test_result_filter_grep_url():1029 @lcc.suite("suite")1030 class suite(object):1031 @lcc.test("test")1032 def test(self):1033 lcc.log_url("http://example.com/foobar")1034 _test_result_filter(1035 suite,1036 ResultFilter(grep=re.compile(r"foobar")),1037 expected=("suite.test",)1038 )1039def test_result_filter_grep_attachment_filename():1040 @lcc.suite("suite")1041 class suite(object):1042 @lcc.test("test")1043 def test(self):1044 lcc.save_attachment_content("hello world", "foobar.txt")1045 _test_result_filter(1046 suite,1047 ResultFilter(grep=re.compile(r"foobar")),1048 expected=("suite.test",)1049 )1050def test_result_filter_grep_attachment_description():1051 @lcc.suite("suite")1052 class suite(object):1053 @lcc.test("test")1054 def test(self):1055 lcc.save_attachment_content("hello world", "file.txt", "foobar")1056 _test_result_filter(1057 suite,1058 ResultFilter(grep=re.compile(r"foobar")),1059 expected=("suite.test",)1060 )1061def test_result_filter_grep_url_description():1062 @lcc.suite("suite")1063 class suite(object):1064 @lcc.test("test")1065 def test(self):1066 lcc.log_url("http://example.com", "foobar")1067 _test_result_filter(1068 suite,1069 ResultFilter(grep=re.compile(r"foobar")),...
test_report_writer.py
Source:test_report_writer.py
...424 assert_attachment(425 get_last_attachment(report), osp.basename(SAMPLE_IMAGE_PATH), "some other file", True, SAMPLE_IMAGE_CONTENT,426 make_file_reader(binary=True)427 )428def _test_save_attachment_content(tmpdir, file_name, file_content, file_reader):429 def do():430 lcc.save_attachment_content(file_content, file_name)431 report = run_func_in_test(do, tmpdir=tmpdir)432 assert_attachment(get_last_attachment(report), file_name, file_name, False, file_content, file_reader)433def test_save_attachment_text_ascii(tmpdir):434 _test_save_attachment_content(tmpdir, "foobar.txt", "foobar", make_file_reader())435def test_save_attachment_text_utf8(tmpdir):436 _test_save_attachment_content(tmpdir, "foobar.txt", u"éééçççà à à ", make_file_reader(encoding="utf-8"))437def test_save_attachment_binary(tmpdir):438 _test_save_attachment_content(tmpdir, "foobar.png", SAMPLE_IMAGE_CONTENT, make_file_reader(binary=True))439def test_save_image_content(tmpdir):440 def do():441 lcc.save_image_content(SAMPLE_IMAGE_CONTENT, "somefile.png", "some file")442 report = run_func_in_test(do, tmpdir=tmpdir)443 assert_attachment(444 get_last_attachment(report), "somefile.png", "some file", True, SAMPLE_IMAGE_CONTENT,445 make_file_reader(binary=True)446 )447def test_log_url():448 @lcc.suite("MySuite")449 class mysuite:450 @lcc.test("Some test")451 def sometest(self):452 lcc.log_url("http://example.com", "example")453 report = run_suite_class(mysuite)454 test = get_last_test(report)455 step = test.get_steps()[0]456 assert step.get_logs()[0].description == "example"457 assert step.get_logs()[0].url == "http://example.com"458def test_unicode(tmpdir):459 @lcc.suite("MySuite")460 class mysuite:461 @lcc.test("some test")462 def sometest(self):463 lcc.set_step(u"éééà à à ")464 check_that(u"éééà à à ", 1, equal_to(1))465 lcc.log_info(u"éééà à à ")466 lcc.save_attachment_content("A" * 1024, u"somefileà à à ", u"éééà à à ")467 report = run_suite_class(mysuite, tmpdir=tmpdir)468 test = get_last_test(report)469 assert test.status == "passed"470 step = test.get_steps()[0]471 assert step.description == u"éééà à à "472 assert u"éééà à à " in step.get_logs()[0].description473 assert "1" in step.get_logs()[0].description474 assert step.get_logs()[1].message == u"éééà à à "475 assert_attachment(step.get_logs()[2], u"somefileà à à ", u"éééà à à ", False, "A" * 1024, make_file_reader(encoding="utf8"))476def test_setup_suite_success():477 @lcc.suite("MySuite")478 class mysuite:479 def setup_suite(self):480 lcc.log_info("some log")...
test_lemoncheesecake_requests.py
Source:test_lemoncheesecake_requests.py
1import re2import io3import base644import callee5import pytest6import requests_mock7from callee import Regex8from lemoncheesecake_requests import Session, Logger, Response, StatusCodeMismatch, \9 is_2xx, is_3xx, is_4xx, is_5xx10from lemoncheesecake_requests.__version__ import __version__11from lemoncheesecake.exceptions import AbortTest12REGEXP_CLASS = re.compile("dummy").__class__13def test_is_2xx():14 assert is_2xx().matches(204)15 assert not is_2xx().matches(199)16 assert not is_2xx().matches(300)17def test_is_3xx():18 assert is_3xx().matches(301)19 assert not is_3xx().matches(299)20 assert not is_3xx().matches(400)21def test_is_4xx():22 assert is_4xx().matches(404)23 assert not is_4xx().matches(399)24 assert not is_4xx().matches(500)25def test_is_5xx():26 assert is_5xx().matches(503)27 assert not is_5xx().matches(499)28 assert not is_5xx().matches(600)29@pytest.mark.parametrize("debug,expected", ((None, False), (False, False), (True, True)))30def test_logger_on(debug, expected):31 logger = Logger.on() if debug is None else Logger.on(debug)32 assert logger.request_line_logging is True33 assert logger.request_headers_logging is True34 assert logger.request_body_logging is True35 assert logger.response_code_logging is True36 assert logger.response_headers_logging is True37 assert logger.response_body_logging is True38 assert logger.debug is expected39def test_logger_off():40 logger = Logger.off()41 assert logger.request_line_logging is False42 assert logger.request_headers_logging is False43 assert logger.request_body_logging is False44 assert logger.response_code_logging is False45 assert logger.response_headers_logging is False46 assert logger.response_body_logging is False47 assert logger.debug is False48@pytest.mark.parametrize("debug,expected", ((None, False), (False, False), (True, True)))49def test_logger_no_headers(debug, expected):50 logger = Logger.no_headers() if debug is None else Logger.no_headers(debug)51 assert logger.request_line_logging is True52 assert logger.request_headers_logging is False53 assert logger.request_body_logging is True54 assert logger.response_code_logging is True55 assert logger.response_headers_logging is False56 assert logger.response_body_logging is True57 assert logger.debug is expected58@pytest.mark.parametrize("debug,expected", ((None, False), (False, False), (True, True)))59def test_logger_no_response_body(debug, expected):60 logger = Logger.no_response_body() if debug is None else Logger.no_response_body(debug)61 assert logger.request_line_logging is True62 assert logger.request_headers_logging is True63 assert logger.request_body_logging is True64 assert logger.response_code_logging is True65 assert logger.response_headers_logging is True66 assert logger.response_body_logging is False67 assert logger.debug is expected68@pytest.fixture69def lcc_mock(mocker):70 return mocker.patch("lemoncheesecake_requests.lcc")71@pytest.fixture72def log_check_mock(mocker):73 return mocker.patch("lemoncheesecake.matching.operations.log_check")74def mock_session(session=None, **kwargs):75 if not session:76 session = Session(logger=Logger.off())77 adapter = requests_mock.Adapter()78 adapter.register_uri(requests_mock.ANY, requests_mock.ANY, **kwargs)79 session.mount('http://', adapter)80 return session81def assert_logs(mock, *expected, as_debug=False):82 log_mock = mock.log_debug if as_debug else mock.log_info83 for val in expected:84 if type(val) is str:85 val = Regex(val, re.DOTALL | re.IGNORECASE)86 if isinstance(val, REGEXP_CLASS):87 val = Regex(val)88 log_mock.assert_any_call(val)89 assert len(log_mock.mock_calls) == len(expected)90@pytest.mark.parametrize("as_debug", ([False], [True]))91def test_session_default(lcc_mock, as_debug):92 session = mock_session(Session(), status_code=201, headers={"Foo": "bar"}, text="foobar")93 if as_debug:94 session.logger.debug = True95 session.post("http://www.example.net", data="foobar")96 assert_logs(97 lcc_mock,98 r"HTTP request.+POST http://www\.example\.net",99 "HTTP request headers",100 "HTTP request body",101 r".+status.+201",102 "HTTP response headers.+foo.+bar",103 "HTTP response body.+foobar",104 as_debug=as_debug105 )106def test_session_no_logging_at_all(lcc_mock):107 session = mock_session()108 session.get("http://www.example.net")109 assert_logs(lcc_mock)110def test_session_log_only_request_line(lcc_mock):111 session = mock_session()112 session.logger.request_line_logging = True113 session.get("http://www.example.net")114 assert_logs(115 lcc_mock,116 r"HTTP request.+GET http://www\.example\.net",117 )118def test_session_log_only_request_line_with_params(lcc_mock):119 session = mock_session()120 session.logger.request_line_logging = True121 session.get("http://www.example.net", params={"foo": "bar"})122 assert_logs(123 lcc_mock,124 r"HTTP request.+GET http://www\.example\.net\?foo=bar",125 )126def test_session_log_only_request_header(lcc_mock):127 session = mock_session()128 session.logger.request_headers_logging = True129 session.get("http://www.example.net", headers={"foo": "bar"})130 assert_logs(131 lcc_mock,132 "HTTP request headers.+foo.+bar"133 )134def test_session_log_only_request_body_json(lcc_mock):135 session = mock_session()136 session.logger.request_body_logging = True137 session.post("http://www.example.net", json={"foo": "bar"})138 assert_logs(139 lcc_mock,140 "HTTP request body.+JSON.+foo.+bar"141 )142def test_session_log_only_request_body_data_as_dict(lcc_mock):143 session = mock_session()144 session.logger.request_body_logging = True145 session.post("http://www.example.net", data={"foo": "bar"})146 assert_logs(147 lcc_mock,148 "HTTP request body.+foo.+bar"149 )150def test_session_log_only_request_body_data_as_text(lcc_mock):151 session = mock_session()152 session.logger.request_body_logging = True153 session.post("http://www.example.net", data="foobar")154 assert_logs(155 lcc_mock,156 "HTTP request body.+foobar"157 )158def test_session_log_only_request_body_data_as_binary(lcc_mock):159 session = mock_session()160 session.logger.request_body_logging = True161 session.post("http://www.example.net", data=b"foobar")162 assert_logs(163 lcc_mock,164 "HTTP request body.+Zm9vYmFy" # NB: Zm9vYmFy is base64-ified "foobar"165 )166def test_session_log_only_request_body_data_as_stream(lcc_mock):167 session = mock_session()168 session.logger.request_body_logging = True169 session.post("http://www.example.net", data=io.StringIO("foobar"))170 assert_logs(171 lcc_mock,172 "HTTP request body.+IO stream"173 )174def test_session_log_only_request_body_data_as_generator(lcc_mock):175 def mygen():176 yield "foo"177 yield "bar"178 session = mock_session()179 session.logger.request_body_logging = True180 session.post("http://www.example.net", data=mygen())181 assert_logs(182 lcc_mock,183 "HTTP request body.+generator"184 )185def test_session_log_only_request_body_files_as_list(lcc_mock):186 session = mock_session()187 session.logger.request_body_logging = True188 session.post("http://www.example.net", files=[("file", ("plain.txt", "sometextdata", "text/plain"))])189 assert_logs(190 lcc_mock,191 r"HTTP request body.+plain\.txt.+text/plain"192 )193def test_session_log_only_request_body_files_as_dict(lcc_mock):194 session = mock_session()195 session.logger.request_body_logging = True196 session.post("http://www.example.net", files={"file": ("plain.txt", "sometextdata", "text/plain")})197 assert_logs(198 lcc_mock,199 r"HTTP request body.+plain\.txt.+text/plain"200 )201def test_session_log_only_request_body_files_as_2_tuple(lcc_mock):202 session = mock_session()203 session.logger.request_body_logging = True204 session.post("http://www.example.net", files=[("file", ("plain.txt", "sometextdata"))])205 assert_logs(206 lcc_mock,207 r"HTTP request body.+plain\.txt"208 )209def test_session_log_hints(lcc_mock):210 session = mock_session(Session(logger=Logger.off(), hint="this is hint"))211 session.logger.request_line_logging = True212 session.logger.response_code_logging = True213 session.get("http://www.example.net")214 assert_logs(215 lcc_mock,216 r"HTTP request \(this is hint\)",217 r"HTTP response \(this is hint\)"218 )219def test_session_log_only_response_line(lcc_mock):220 session = mock_session(status_code=204)221 session.logger.response_code_logging = True222 session.get("http://www.example.net")223 assert_logs(224 lcc_mock,225 r"HTTP response.+204"226 )227def test_session_log_only_response_header(lcc_mock):228 session = mock_session(headers={"Foo": "bar"})229 session.logger.response_headers_logging = True230 session.get("http://www.example.net")231 assert_logs(232 lcc_mock,233 r"HTTP response headers.+Foo.+bar"234 )235def test_session_log_only_response_body_text(lcc_mock):236 session = mock_session(text="foobar")237 session.logger.response_body_logging = True238 session.get("http://www.example.net")239 assert_logs(240 lcc_mock,241 r"HTTP response body.+foobar"242 )243def test_session_log_only_response_body_json(lcc_mock):244 session = mock_session(json={"foo": "bar"})245 session.logger.response_body_logging = True246 session.get("http://www.example.net")247 assert_logs(248 lcc_mock,249 r'HTTP response body.+"foo": "bar"'250 )251def test_session_log_only_response_body_binary(lcc_mock):252 # This is https://docs.python.org/3/_static/py.png:253 data = b"""\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f\xf3\xffa\x00\254\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\x06bKGD\x00\xff\x00\xff\x00\xff\xa0\xbd\xa7\x93\x00\x00\x00\tpHYs\x00\255\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\x00\x07tIME\x07\xd8\x04\x1b\x118!\x063\'^\x00\x00\x027IDAT8\256\xcbe\x93OHUA\x14\x87\xbf{\xdf\xb3w{"\x94\x10\xa5\xd1&hS\x8b6\xadZ\xb4\x10\x1emB*xP\xdb\xc0MQ\xae\xdd\x04A\x8b "\xda)\257mZH\x1b\x17\x91 F\x11EF\x98\x96\xb6\xb5\x88\xcc2\x15\xd4\xfc\xf3\xee\x9dy3g\xe6\xb6\xf0\xde\xbc\xea\x81\xc3\xc0\xcc\xf7\258;\xe77\xcc\x9c\x80]\xd1\xfd\xe0\xed3i\x9as\xde\x99v\xb1M\xc4\x18\xa4\xa9\xb4U\xfa\xf1\xc7\xfe\xeb}\x80\x06\\\xce\x87\xbb\259\x0bx\'\x17G\xfaj\xedN,\xceZ\xbcX\xbcwQ\x1a\xf8\x9b\xc01 *\xf2{\n8k9\x7fg\x18\'v;\xad\xcd\x8f;\x80j\x91/\x03t?|\x7f\xdb\260[{\\\xac\n\x8cN\x06\x8dj\x94E\xc7%g\x0c\xe1\xbeJ=M}\xceW\x80\xd2\x8e\x02\x97\x1f}x\xed\xc4v\xa5^\xc0{\x02\xa0Tn\x81J\x15\261\x82\x12N\xec\x0e\x87\xe9\\}\xc1\xdbX\x8bn\xdc\xaf\x9czw/\xf4\xdeumY5;mg\x99\x87\xa8\xcdQ\xc0"\t\xa1SQ\x19}\x03\xe8,\262\xe7\xa0/\x88|\xe1\xdei\xea\xb5\xd3\xf1\x9b\xa9\'}\x03\xcbS\xb5\x1a\xa2@\x12B\xaf\xda\x81\x8e\xf2\x0e\xb1\xb5\xe8\xc6\263\xda\xe8\xfc\xf8\xf0\xd3\xf9\xe9Wk\x80\x00)`\xe6\xc6j\'\x0f\xb6J/N\x81K@\x12\x80\xfde1M\xed\xc5FN,j}yhb\xa0wp\xe3\xe7\264\xad+\xad\xd1\x89K\xa1S\xd1\x7fXb\xf2\xee\x88\xc2\x8b\xd6@\x10:\x91\xd9\xdc\xfa\x9f\xc9\x97\xcf\xe3_\xbd=mU\x7f5\xf4EqR\265\x10\'\xe04I\x92N\x02&t:\xee\x17c\xb4\x13\xcb\xef\xa9\x91\xb5j\xe4.l\x0b\n\xa2\x82\x18`zF\xbf\x006\x83\xecgu\x00G\x81f\266\xbapm"\x87\x97\x16\xff\x0e\x95\xbcJ\xb7\x9c(p\n\x80o\xb3\xe6\xcb\xd9\x9e\xd5q\xe0G\x190\xc0"\xb0\x01\xa4\xc5n\x87\x0f\267\xb8:"\xe0,\x88%8\xb3\xd8\x054\x00\x95\xf1+!\xe0\xb3\x8d\x15`\xd5\xdbDoY-\xe4\xe9\xaf\xf84\xd5\xd9\x8b,\x00\xdf\xb35\xd93\268\x0b\x8d\x8d\xf5\xba\xd5\xf1gob\x9d;\xb1\xe3\x9d3c\x9f\xd4]\xc0\x02I\xd6\xd0\x02i\xc0\xde\x88\x80C\xc0\x11\xa0\rh\xc9\269\\nf]\x97\xb2\x91\x06\xe0\x1f\x01\xbf\xaf\xff\xfc\x8c\x00\x9a\x00\x00\x00\x00IEND\xaeB`\x82"""270 data_b64 = base64.encodebytes(data).decode()271 session = mock_session(headers={"Content-Type": "image/png"}, content=data)272 session.logger.response_body_logging = True273 session.get("http://www.example.net")274 assert_logs(275 lcc_mock,276 r'HTTP response body.+' + re.escape(data_b64)277 )278def test_session_logger_switching(lcc_mock):279 session = mock_session(Session(logger=Logger.on()))280 # First call, using the session.logger281 session.get("http://www.example.net")282 assert_logs(283 lcc_mock,284 callee.Any(), callee.Any(), callee.Any(), callee.Any(), callee.Any()285 )286 lcc_mock.reset_mock()287 # Second call, using the logger passed as argument288 session.get("http://www.example.net", logger=Logger.off())289 assert_logs(lcc_mock)290 lcc_mock.reset_mock()291 # Third call, back to the session.logger292 session.get("http://www.example.net")293 assert_logs(294 lcc_mock,295 callee.Any(), callee.Any(), callee.Any(), callee.Any(), callee.Any()296 )297def test_bodies_saved_as_attachments(lcc_mock):298 request_body = "A" * 20299 response_body = "B" * 20300 session = mock_session(text=response_body)301 session.logger = Logger.on()302 session.logger.max_inlined_body_size = 10303 session.post("http://www.example.net", data=request_body)304 assert_logs(lcc_mock, callee.Any(), callee.Any(), callee.Any(), callee.Any())305 lcc_mock.save_attachment_content.assert_any_call(306 callee.Regex(f".*{request_body}.*", re.DOTALL), callee.Any(), "HTTP request body"307 )308 lcc_mock.save_attachment_content.assert_any_call(309 callee.Regex(f".*{response_body}.*", re.DOTALL), callee.Any(), "HTTP response body"310 )311def test_max_inlined_body_size_and_debug(lcc_mock):312 request_body = "A" * 20313 response_body = "B" * 20314 session = mock_session(text=response_body)315 session.logger = Logger.on()316 session.logger.max_inlined_body_size = 10317 session.logger.debug = True318 session.post("http://www.example.net", data=request_body)319 assert_logs(320 lcc_mock,321 callee.Any(), callee.Any(), callee.Any(), callee.Any(), callee.Any(), callee.Any(),322 as_debug=True323 )324@pytest.mark.parametrize("method", ("get", "options", "head", "post", "put", "patch", "delete"))325def test_method(lcc_mock, method):326 session = mock_session()327 session.logger.request_line_logging = True328 getattr(session, method)("http://www.example.net")329 assert_logs(lcc_mock, rf".+{method.upper()} http://www\.example\.net")330def test_request(lcc_mock):331 session = mock_session()332 session.logger.request_line_logging = True333 session.request("GET", "http://www.example.net")334 assert_logs(lcc_mock, rf".+GET http://www\.example\.net")335def test_response_constructor():336 # see comment in Response.__init__337 # this test is here to make test coverage happy338 Response()339def test_response_check_status_code_success(lcc_mock, log_check_mock):340 session = mock_session(status_code=200)341 resp = session.get("http://www.example.net")342 assert resp.check_status_code(200) is resp343 log_check_mock.assert_called_with(callee.Regex(".*200.*"), True, callee.Any())344def test_response_check_status_code_failure(lcc_mock, log_check_mock):345 session = mock_session(status_code=200)346 resp = session.get("http://www.example.net")347 assert resp.check_status_code(201) is resp348 log_check_mock.assert_called_with(callee.Regex(".*201.*"), False, callee.Regex(".*200.*"))349def test_response_check_ok(lcc_mock, log_check_mock):350 session = mock_session(status_code=200)351 resp = session.get("http://www.example.net")352 assert resp.check_ok() is resp353 log_check_mock.assert_called_with(callee.Regex(".*200.+299.*"), True, callee.Any())354def test_response_require_status_code_success(lcc_mock, log_check_mock):355 session = mock_session(status_code=200)356 resp = session.get("http://www.example.net")357 assert resp.require_status_code(200) is resp358 log_check_mock.assert_called_with(callee.Regex(".*200.*"), True, callee.Any())359def test_response_require_status_code_failure(lcc_mock, log_check_mock):360 session = mock_session(status_code=200)361 resp = session.get("http://www.example.net")362 with pytest.raises(AbortTest):363 resp.require_status_code(201)364 log_check_mock.assert_called_with(callee.Regex(".*201.*"), False, callee.Regex(".*200.*"))365def test_response_require_ok(lcc_mock, log_check_mock):366 session = mock_session(status_code=200)367 resp = session.get("http://www.example.net")368 assert resp.require_ok() is resp369 log_check_mock.assert_called_with(callee.Regex(".*200.+299.*"), True, callee.Any())370def test_response_assert_status_code_success(lcc_mock, log_check_mock):371 session = mock_session(status_code=200)372 resp = session.get("http://www.example.net")373 assert resp.assert_status_code(200) is resp374 log_check_mock.assert_not_called()375def test_response_assert_status_code_failure(lcc_mock, log_check_mock):376 session = mock_session(status_code=200)377 resp = session.get("http://www.example.net")378 with pytest.raises(AbortTest):379 resp.assert_status_code(201)380 log_check_mock.assert_called_with(callee.Regex(".*201.*"), False, callee.Regex(".*200.*"))381def test_response_assert_ok(lcc_mock, log_check_mock):382 session = mock_session(status_code=200)383 resp = session.get("http://www.example.net")384 assert resp.assert_ok() is resp385 log_check_mock.assert_not_called()386def test_raise_unless_status_code_success(lcc_mock):387 session = mock_session(status_code=200)388 resp = session.get("http://www.example.net")389 assert resp.raise_unless_status_code(200) is resp390def test_raise_unless_status_code_failure(lcc_mock):391 session = mock_session(status_code=200)392 resp = session.get("http://www.example.net")393 with pytest.raises(StatusCodeMismatch) as excinfo:394 resp.raise_unless_status_code(201)395 assert re.search(r"expected .+ 201, .+ 200", str(excinfo.value))396def test_raise_unless_ok(lcc_mock):397 session = mock_session(status_code=200)398 resp = session.get("http://www.example.net")399 assert resp.raise_unless_ok() is resp400def test_version():...
reporttests.py
Source:reporttests.py
...76 def sometest(self):77 lcc.set_step(u"éééà à à ")78 check_that(u"éééà à à ", 1, equal_to(1))79 lcc.log_info(u"éééà à à ")80 lcc.save_attachment_content("A" * 1024, u"somefileà à à ", u"éééà à à ")81 lcc.log_url("http://example.com", "example")82 self.do_test_reporting_session(MySuite)83 def test_multiple_suites_and_tests(self):84 @lcc.suite("MySuite1")85 class MySuite1:86 @lcc.tags("foo")87 @lcc.test("Some test 1")88 def test_1_1(self):89 check_that("foo", 2, equal_to(2))90 @lcc.tags("bar")91 @lcc.test("Some test 2")92 def test_1_2(self):93 check_that("foo", 2, equal_to(2))94 @lcc.tags("baz")95 @lcc.test("Some test 3")96 def test_1_3(self):97 check_that("foo", 3, equal_to(2))98 @lcc.suite("MySuite2")99 class MySuite2:100 @lcc.prop("foo", "bar")101 @lcc.test("Some test 1")102 def test_2_1(self):103 1 / 0104 @lcc.prop("foo", "baz")105 @lcc.test("Some test 2")106 def test_2_2(self):107 check_that("foo", 2, equal_to(2))108 @lcc.test("Some test 3")109 def test_2_3(self):110 check_that("foo", 2, equal_to(2))111 # suite3 is a sub suite of suite3112 @lcc.suite("MySuite3")113 class MySuite3:114 @lcc.prop("foo", "bar")115 @lcc.test("Some test 1")116 def test_3_1(self):117 check_that("foo", 1, equal_to(1))118 @lcc.prop("foo", "baz")119 @lcc.test("Some test 2")120 def test_3_2(self):121 raise lcc.AbortTest("")122 @lcc.test("Some test 3")123 def test_3_3(self):124 check_that("foo", 1, equal_to(1))125 self.do_test_reporting_session((MySuite1, MySuite2))126 def test_check_success(self):127 @lcc.suite("MySuite")128 class MySuite:129 @lcc.test("Test 1")130 def test_1(self):131 check_that("somevalue", "foo", equal_to("foo"))132 self.do_test_reporting_session(MySuite)133 def test_check_failure(self):134 @lcc.suite("MySuite")135 class MySuite:136 @lcc.test("Test 1")137 def test_1(self):138 check_that("somevalue", "foo", equal_to("bar"))139 self.do_test_reporting_session(MySuite)140 def test_require_success(self):141 @lcc.suite("MySuite")142 class MySuite:143 @lcc.test("Test 1")144 def test_1(self):145 require_that("somevalue", "foo", equal_to("foo"))146 self.do_test_reporting_session(MySuite)147 def test_require_failure(self):148 @lcc.suite("MySuite")149 class MySuite:150 @lcc.test("Test 1")151 def test_1(self):152 require_that("somevalue", "foo", equal_to("bar"))153 self.do_test_reporting_session(MySuite)154 def test_assert_failure(self):155 @lcc.suite("MySuite")156 class MySuite:157 @lcc.test("Test 1")158 def test_1(self):159 assert_that("somevalue", "foo", equal_to("bar"))160 self.do_test_reporting_session(MySuite)161 def test_all_types_of_logs(self):162 @lcc.suite("MySuite")163 class MySuite:164 @lcc.test("Test 1")165 def test_1(self):166 lcc.log_debug("some debug message")167 lcc.log_info("some info message")168 lcc.log_warning("some warning message")169 @lcc.test("Test 2")170 def test_2(self):171 lcc.log_error("some error message")172 self.do_test_reporting_session(MySuite)173 def test_multiple_steps(self):174 @lcc.suite("MySuite")175 class MySuite:176 @lcc.test("Some test")177 def sometest(self):178 lcc.set_step("step 1")179 lcc.log_info("do something")180 lcc.set_step("step 2")181 lcc.log_info("do something else")182 self.do_test_reporting_session(MySuite)183 def test_attachment(self):184 @lcc.suite("MySuite")185 class MySuite:186 @lcc.test("Some test")187 def sometest(self):188 lcc.save_attachment_content("foobar", "foobar.txt")189 self.do_test_reporting_session(MySuite)190 def test_image(self):191 @lcc.suite("MySuite")192 class MySuite:193 @lcc.test("Some test")194 def sometest(self):195 lcc.save_image_content("foobar", "foobar.txt") # not actual image content, but it does not matter here196 self.do_test_reporting_session(MySuite)197 def test_log_url(self):198 @lcc.suite("MySuite")199 class MySuite:200 @lcc.test("Some test")201 def sometest(self):202 lcc.log_url("http://www.example.com", "example")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!