Best Python code snippet using refurb_python
test_sanicparser.py
Source:test_sanicparser.py
...19 return app20 # testing of file uploads is made through sanic.test_client21 # please check test_parse_files function below22 @pytest.mark.skip(reason="files location not supported for aiohttpparser")23 def test_parse_files(self, testapp):24 pass25 def create_testapp(self, app):26 loop = asyncio.get_event_loop()27 self.loop = loop28 return TestApp(app, loop=self.loop)29 def after_create_app(self):30 self.loop.close()31 def test_parsing_view_args(self, testapp):32 res = testapp.get("/echo_view_arg/42")33 assert res.json == {"view_arg": 42}34 def test_parsing_invalid_view_arg(self, testapp):35 res = testapp.get("/echo_view_arg/foo", expect_errors=True)36 print(res.body)37 assert res.status_code == 42238 assert res.content_type == "application/json"39 assert res.json == {'view_args': {'view_arg': ['Not a valid integer.']}}40 def test_use_args_with_view_args_parsing(self, testapp):41 res = testapp.get("/echo_view_arg_use_args/42")42 assert res.json == {"view_arg": 42}43 def test_use_args_on_a_method_view(self, testapp):44 res = testapp.post("/echo_method_view_use_args", {"val": 42})45 assert res.json == {"val": 42}46 def test_use_args_on_a_LOLgather_view(self, testapp):47 res = testapp.post("/echo_lol")48 assert res.json == {'name': 'World'}49 def test_use_kwargs_on_a_method_view(self, testapp):50 res = testapp.post("/echo_method_view_use_kwargs", {"val": 42})51 assert res.json == {"val": 42}52 def test_use_kwargs_with_missing_data(self, testapp):53 res = testapp.post("/echo_use_kwargs_missing", {"username": "foo"}, expect_errors=True)54 assert res.json == {"username": "foo"}55 def test_invalid_json(self, testapp):56 res = testapp.post(57 "/echo_json",58 '{"foo": "bar", jdhfjdhjsd}',59 headers={"Accept": "application/json", "Content-Type": "application/json"},60 expect_errors=True,61 )62 assert res.status_code == 40063 assert res.json == {'json': ['Invalid JSON body.']}64 # regression test for https://github.com/sloria/webargs/issues/14565 def test_nested_many_with_data_key(self, testapp):66 post_with_raw_fieldname_args = (67 "/echo_nested_many_data_key",68 {"x_field": [{"id": 42}]},69 )70 res = testapp.post_json(*post_with_raw_fieldname_args, expect_errors=True)71 assert res.status_code == 42272 res = testapp.post_json("/echo_nested_many_data_key", {"X-Field": [{"id": 24}]})73 assert res.json == {"x_field": [{"id": 24}]}74 res = testapp.post_json("/echo_nested_many_data_key", {})75 assert res.json == {}76 def test_abort_called_on_validation_error(self, testapp):77 res = testapp.get(78 "/echo_use_args_validated",79 params={"value": 41},80 headers={"Content-Type": "application/json"},81 expect_errors=True82 )83 assert res.status_code == 42284 assert res.json == {'query': ['Invalid value.']}85 # def test_parse_files(self, testapp):86 #87 # # if (version.parse(sanic_version) < version.parse("19.0.0")):88 # # res = app.test_client.post(89 # # "/echo_file", data={"myfile": io.BytesIO(b"data")}, gather_request=False90 # # )91 # # else:92 # # res = app.test_client.post(93 # # "/echo_file", {"myfile": io.BytesIO(b"data")}94 # # )95 #96 # assert res.json == {"myfile": "data"}97def test_abort_with_message():98 with pytest.raises(SanicException) as excinfo:99 abort(400, message="custom error message")...
parse_sids_and_save_to_file.py
Source:parse_sids_and_save_to_file.py
...29 return False30 if str(path).count(r'\.') or str(path).count(r'\_'):31 return False32 return True33def test_parse_files(sid_file, is_ok_callback=None):34 """35 Recursively traverses the project directories, and fetches all compatible Sids into a file.36 is_ok_callback is a function to filter out paths that do not need to be Sid tested.37 """38 print('Sids will be written to : {}'.format(sid_file))39 if is_ok_callback:40 is_ok = is_ok_callback41 else:42 def is_ok(path):43 return True44 if sid_file.exists():45 raise SpilException('The parse file "{}" already exists. Skipped'.format(sid_file))46 for project in projects[:]:47 project_root = Path( Sid(project).path )48 print('Root path : {}'.format(project_root))49 with open(str(sid_file), 'a') as f:50 for path in project_root.rglob('*'):51 if not is_ok(path):52 continue53 print(path)54 sid = Sid(path=path)55 if str(sid):56 f.write(str(sid) + '\n')57if __name__ == '__main__':58 setLevel(ERROR) # Set to ERROR if file system contains a lot of non Sid translatable files.59 from spil_tests.utils.save_sid_list_to_file import sid_file_path60 sid_file = sid_file_path().parent / 'sids.parsed.txt'...
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!!