Skip to content
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

Add documentation for writing tests with signed actor cookies #1830

Closed
Tracked by #2251
simonw opened this issue Oct 4, 2022 · 2 comments
Closed
Tracked by #2251

Add documentation for writing tests with signed actor cookies #1830

simonw opened this issue Oct 4, 2022 · 2 comments

Comments

@simonw
Copy link
Owner

simonw commented Oct 4, 2022

I use this pattern in a lot of plugin tests, e.g. https://github.com/simonw/datasette-edit-templates/blob/087f6a6cabc20020f2b0524f11aa3a7836320848/tests/test_edit_templates.py#L55-L58

    actor = ds.sign({"a": {"id": "root"}}, "actor")
    response1 = await ds.client.get(
        "/-/edit-templates/_footer.html", cookies={"ds_actor": actor}
    )

I should add this to the documentation on this page: https://docs.datasette.io/en/latest/testing_plugins.html

@simonw
Copy link
Owner Author

simonw commented Jan 10, 2024

This can now be done with datasette.client.actor_cookie({"id": "root"}).

datasette/datasette/app.py

Lines 1884 to 1891 in 48148e6

class DatasetteClient:
def __init__(self, ds):
self.ds = ds
self.app = ds.app()
def actor_cookie(self, actor):
# Utility method, mainly for tests
return self.ds.sign({"a": actor}, "actor")

@simonw
Copy link
Owner Author

simonw commented Jan 10, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant