test: add cookie tests#142
Conversation
Pull Request Test Coverage Report for Build 195514391
💛 - Coveralls |
| async def test_should_roundtrip_cookie(context, page, server): | ||
| await page.goto(server.EMPTY_PAGE) | ||
| # @see https://en.wikipedia.org/wiki/Year_2038_problem | ||
| date = int(datetime.datetime(2038, 1, 1).timestamp() * 1000) |
There was a problem hiding this comment.
I manually checked this matches the date from the JS version, but someone should double check since dates are always fun!
| page_1 = await context.newPage() | ||
| await page_1.goto(server.PREFIX + "/setcookie.html") | ||
| ## | ||
| page_2 = await context.newPage() | ||
| await page_2.goto(server.EMPTY_PAGE) | ||
| cookies_2 = await context.cookies() | ||
| assert len(cookies_2) == 1 | ||
| assert ",".join(list(map(lambda c: c["value"], cookies_2))) == "value" | ||
| ## | ||
| context_b = await browser.newContext() | ||
| page_3 = await context_b.newPage() | ||
| await page_3.goto(server.EMPTY_PAGE) | ||
| cookies_3 = await context_b.cookies() | ||
| assert cookies_3 == [] | ||
| await context_b.close() |
There was a problem hiding this comment.
The javascript version used scoping; I've manually appended subscripts to (hopefully) achieve the same thing. The few tests with ## should be double checked by someone else to ensure the logic is preserved. 👀
| cookie = [] | ||
|
|
||
| def handler(request): | ||
| cookie.extend(request.requestHeaders.getRawHeaders("cookie") or []) |
There was a problem hiding this comment.
In the JS version, cookie was simply assigned to. In Python, that didn't work so I used a mutable list.
|
@mxschmitt and @pavelfeldman: This is now ready for review. Like the other PRs, this is almost a 1:1 port from the JS. I've left a few comments where there should be some extra eyes in the cases that the 1:1 port had to be modified slightly. |
No description provided.