Best Python code snippet using localstack_python
test_lib_url.py
Source:test_lib_url.py
1from lib import nhk_api, url2# Valid URLs3def test_check_url_exists():4 assert url.check_url_exists("https://www3.nhk.or.jp/nhkworld/") is True5def test_get_API_request_params():6 assert url.get_api_request_params(nhk_api.rest_url["get_livestream"]) is not None7def test_request_url():8 assert url.request_url("https://www3.nhk.or.jp/nhkworld/", False).status_code == 2009def test_get_url():10 assert url.get_url("https://www3.nhk.or.jp/nhkworld/", False).status_code == 20011# Non-existing URLs12def test_request_url_notexists():13 assert url.request_url("http://doesnotexist", False).status_code == 1000114def test_get_url_notexists():15 assert url.get_url("http://doesnotexist", False).status_code == 1000116# Not found URLs17def test_request_url_notfound():18 assert url.get_url("https://www3.nhk.or.jp/doesnotexist/", False).status_code == 40419# JSON20def test_get_JSON_cached():21 assert isinstance(url.get_json(nhk_api.rest_url["get_livestream"]), dict)22def test_get_JSON_non_cached():23 assert isinstance(url.get_json(nhk_api.rest_url["get_livestream"], False), dict)24def test_get_JSON_invalid():25 assert url.get_json("https://www3.nhk.or.jp/nhkworld/") is None26def test_get_JSON_notexists():27 assert url.get_json("http://doesnotexist") is None28def test_get_NHK_website_url():...
test_request.py
Source:test_request.py
...11 assert r.json == {"foo": "bar", "baz": 420}12def test_get_json_force():13 r = Request("POST", "/", body=b'{"foo": "bar", "baz": 420}')14 assert r.get_json(force=True) == {"foo": "bar", "baz": 420}15def test_get_json_invalid():16 r = Request("POST", "/", body=b'{"foo": "')17 with pytest.raises(JSONDecodeError):18 assert r.get_json(force=True)19 assert r.get_json(force=True, silent=True) is None20def test_get_data():21 r = Request("GET", "/", body="foobar")22 assert r.data == b"foobar"23def test_get_data_as_text():24 r = Request("GET", "/", body="foobar")25 assert r.get_data(as_text=True) == "foobar"26def test_get_stream():27 r = Request("GET", "/", body=b"foobar")28 assert r.stream.read(3) == b"foo"29 assert r.stream.read(3) == b"bar"
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!!