-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: AppSyncResolver Context not set in tests #3546
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Looking at this now |
Hi @averypelle thank you for opening this issue! I've tested some code and noticed that because you are calling the resolver directly, the Two ways I can think to solve this:
lambda_handler(event=mock_event, context=mock_lambda_context) This way the context will be appended.
app.append_context(is_admin=True)
app(event=mock_event, context=mock_lambda_context) Both of this should solve your problem. I'm closing the bug report for now, but please feel free to re-open if you need additional support! |
|
@rubenfonseca Thank you very much!! I appreciate the response. I can confirm that your solution worked for me. |
Expected Behaviour
My expectation is that setting
app.appendContext
like the example in the docs will work in both a deployed application and in testing.Docs for Sharing contextual data
Docs for Testing your code
Current Behaviour
The current behavior is that the app context is properly set in my deployed application and retrievable in the Router but is not properly set when using the app under the pytest configuration described in the docs.
Code snippet
I adapted an example from the docs to be reproducible with a simple Pytest file.
I am using Python 3.9 and pipenv version 2023.11.15 with the Pipfile and lockfile below, just to be certain it's not something with my env. In production, I am using the AWS Lambda powertools layer with ARN
arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:32
.Pipfile and Pipfile.lock
Pipfile
Pipfile.lock
Possible Solution
No response
Steps to Reproduce
Please copy the files indicated above into their requisite file paths and then run the testing suite above to reproduce
pipenv install --dev
pipenv run pytest -vv chat_graphql_api_tests
When this command is run, it gives the following assertion error, indicating that
is_admin
is not being set.Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
4.9
Packaging format used
Lambda Layers
Debugging logs
No response
The text was updated successfully, but these errors were encountered: