How to use get_request_context method in localstack

Best Python code snippet using localstack_python

test_app.py

Source:test_app.py Github

copy

Full Screen

...25def fill_db(empty_db):26 with open("data_dump.cypher") as file_object:27 queries = file_object.read()28 graph.run(queries)29def get_request_context():30 app2 = MyTest.create_app(MyTest)31 return app2.test_request_context()32def test_find_actor(fill_db):33 with get_request_context():34 actor = app.find_actor("na2")35 assert actor['name'] == 'Kyla Pratt'36 for title in actor['titles']:37 if "Alien vs. Predator" == title['title']:38 return39 assert 0, "Alien vs. Predator not in actor's titles"40def test_actor_text_search_exist_in_db(fill_db):41 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):42 mock.patch('coactors.app.request.args', MagicMock())43 with mock.patch('coactors.app.request.args.get', MagicMock(side_effect =['s', None])):44 response = app.actor_text_search()45 assert "uid" in response['results'][0]46 assert "name" in response['results'][0]47 assert (response['results'][0]['name'] == "Sanaa Lathan"48 or response['results'][0]['name'] == "Simon Baker")49 assert response['known'] == True50 assert response['query'] == 's'51def test_actor_text_search_exist_in_db_any_order(fill_db):52 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):53 mock.patch('coactors.app.request.args', MagicMock())54 with mock.patch('coactors.app.request.args.get', MagicMock(side_effect =['lathan s', None])):55 response = app.actor_text_search()56 assert "uid" in response['results'][0]57 assert "name" in response['results'][0]58 assert response['results'][0]['name'] == "Sanaa Lathan"59 assert response['known'] == True60 assert response['query'] == 'lathan s'61def test_actor_text_search_doesnt_exist_in_db():62 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):63 mock.patch('coactors.app.request.args', MagicMock())64 # coactors.app.request.args.get = MagicMock(return_value = 's')65 mock.patch('coactors.app.request.args.get', MagicMock(return_value = 's'))66 # coactors.app.parse_search_results = MagicMock(return_value = {})67 68 with mock.patch('coactors.app.parse_search_results', MagicMock(return_value = {})):69 # print(coactors.app.request.args.get('query'))70 response = app.actor_text_search()71 assert response['known'] == False72 assert response['results'] == {}73 # coactors.app.parse_search_results.reset_mock(True)74def test_parse_actor_search_results():75 with open("resources/annouckQuery.txt") as file_object:76 response = file_object.read()77 parsed = coactors.app.parse_search_results(response, "actors")78 assert "uid" in parsed[0]79 assert "name" in parsed[0]80 81 assert ("Annouck Hautbois" in parsed[0]['name'] 82 or "Annouck Dupont" in parsed[0]['name'])83 assert len(parsed) == 284def test_get_actors(fill_db):85 with get_request_context():86 actors = app.get_actors()87 actors = actors.json88 assert len(actors) == 1089def test_find_title(fill_db):90 with get_request_context():91 title = app.find_title("mo3")92 assert title['title'] == 'Something New'93 assert title['released'] == "2006"94 for actor in title['cast']:95 if "Sanaa Lathan" == actor['name']:96 return97 assert 0, "Sanaa Lathan not in title's cast"98def test_tv_text_search_exist_in_db(fill_db):99 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):100 mock.patch('coactors.app.request.args', MagicMock())101 with mock.patch('coactors.app.request.args.get', MagicMock(side_effect =['m', None])):102 response = app.title_text_search()103 assert response['results'][0]['uid'] == "tv1"104 assert response['results'][0]['title'] == "The Mentalist"105 assert response['results'][0]['released'] == "2008"106 assert response['known'] == True107 assert response['query'] == 'm'108def test_movie_text_search_exist_in_db(fill_db):109 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):110 mock.patch('coactors.app.request.args', MagicMock())111 with mock.patch('coactors.app.request.args.get', MagicMock(side_effect =['p', None])):112 response = app.title_text_search()113 assert response['results'][0]['uid'] == "mo1"114 assert response['results'][0]['title'] == "Alien vs. Predator"115 assert response['results'][0]['released'] == "2004"116 assert response['known'] == True117 assert response['query'] == 'p'118def test_movie_text_search_exist_in_db_any_order(fill_db):119 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):120 mock.patch('coactors.app.request.args', MagicMock())121 with mock.patch('coactors.app.request.args.get', MagicMock(side_effect =['predator alien', None])):122 response = app.title_text_search()123 assert response['results'][0]['uid'] == "mo1"124 assert response['results'][0]['title'] == "Alien vs. Predator"125 assert response['results'][0]['released'] == "2004"126 assert response['known'] == True127 assert response['query'] == 'predator alien'128def test_title_text_search_doesnt_exist_in_db():129 with get_request_context(), mock.patch('coactors.app.request', MagicMock()):130 mock.patch('coactors.app.request.args', MagicMock())131 mock.patch('coactors.app.request.args.get', MagicMock(return_value = 'p'))132 133 with mock.patch('coactors.app.parse_search_results', MagicMock(return_value = {})):134 response = app.title_text_search()135 assert response['known'] == False136 assert response['results'] == {}137def test_parse_title_search_results():138 with open("resources/littleMermaidQuery.txt") as file_object:139 response = file_object.read()140 parsed = coactors.app.parse_search_results(response, "titles")141 assert "uid" in parsed[0]142 assert "title" in parsed[0]143 assert "released" in parsed[0]144 assert "title_type" in parsed[0]145 assert len(parsed) == 19146 147 for el in parsed:148 if el['title'] == "The Little Mermaid II: Return to the Sea":149 return150 151 assert 0, "The Little Mermaid II: Return to the Sea not in results"152def test_get_titles(fill_db):153 with get_request_context():154 titles = app.get_titles()155 titles = titles.json...

Full Screen

Full Screen

asgi.py

Source:asgi.py Github

copy

Full Screen

...4from starlette.applications import Starlette5from starlette.templating import Jinja2Templates6templates = Jinja2Templates(directory="templates")7app = Starlette(debug=True)8def get_request_context(request) -> dict:9 return {"request": request, "s3_url_for": s3_url_for}10@app.route("/")11async def homepage(request):12 template = "index.html"13 context = get_request_context(request)14 return templates.TemplateResponse(template, context)15@app.route("/error")16async def error(request):17 """18 An example error.19 Switch the `debug` setting to see either tracebacks or 500 pages.20 """21 raise RuntimeError("Oh no")22@app.exception_handler(404)23async def not_found(request, exc):24 """25 Return an HTTP 404 page.26 """27 template = "404.html"28 context = get_request_context(request)29 return templates.TemplateResponse(template, context, status_code=404)30@app.exception_handler(500)31async def server_error(request, exc):32 """33 Return an HTTP 500 page.34 """35 template = "500.html"36 context = get_request_context(request)37 return templates.TemplateResponse(template, context, status_code=500)38BUCKET_NAME = os.environ.get("BUCKET_NAME", None)39REGION_NAME = os.environ.get("REGION_NAME", None)40S3_AWS_ACCESS_KEY_ID = os.environ.get("S3_AWS_ACCESS_KEY_ID")41S3_AWS_SECRET_ACCESS_KEY = os.environ.get("S3_AWS_SECRET_ACCESS_KEY")42app.add_middleware(43 S3StorageMiddleware,44 bucket_name=BUCKET_NAME,45 region_name=REGION_NAME,46 aws_access_key_id=S3_AWS_ACCESS_KEY_ID,47 aws_secret_access_key=S3_AWS_SECRET_ACCESS_KEY,48 static_dir="static",49)50handler = Mangum(app)

Full Screen

Full Screen

renderers.py

Source:renderers.py Github

copy

Full Screen

1from django.template.loader import render_to_string2from django.template import RequestContext3def get_request_context(request):4 return RequestContext(request)5def render(template, context, request=None):6 if request:7 return render_to_string(template, context, context_instance=get_request_context(request))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful