subrepo: subdir: "apps/twscrape" merged: "e4dce5d3" upstream: origin: "https://github.com/vladkens/twscrape" branch: "main" commit: "e4dce5d3" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
import pytest
|
|
|
|
from twscrape.utils import parse_cookies
|
|
|
|
|
|
def test_cookies_parse():
|
|
val = "abc=123; def=456; ghi=789"
|
|
assert parse_cookies(val) == {"abc": "123", "def": "456", "ghi": "789"}
|
|
|
|
val = '{"abc": "123", "def": "456", "ghi": "789"}'
|
|
assert parse_cookies(val) == {"abc": "123", "def": "456", "ghi": "789"}
|
|
|
|
val = '[{"name": "abc", "value": "123"}, {"name": "def", "value": "456"}, {"name": "ghi", "value": "789"}]'
|
|
assert parse_cookies(val) == {"abc": "123", "def": "456", "ghi": "789"}
|
|
|
|
val = "eyJhYmMiOiAiMTIzIiwgImRlZiI6ICI0NTYiLCAiZ2hpIjogIjc4OSJ9"
|
|
assert parse_cookies(val) == {"abc": "123", "def": "456", "ghi": "789"}
|
|
|
|
val = "W3sibmFtZSI6ICJhYmMiLCAidmFsdWUiOiAiMTIzIn0sIHsibmFtZSI6ICJkZWYiLCAidmFsdWUiOiAiNDU2In0sIHsibmFtZSI6ICJnaGkiLCAidmFsdWUiOiAiNzg5In1d"
|
|
assert parse_cookies(val) == {"abc": "123", "def": "456", "ghi": "789"}
|
|
|
|
val = '{"cookies": {"abc": "123", "def": "456", "ghi": "789"}}'
|
|
assert parse_cookies(val) == {"abc": "123", "def": "456", "ghi": "789"}
|
|
|
|
with pytest.raises(ValueError, match=r"Invalid cookie value: .+"):
|
|
val = "{invalid}"
|
|
assert parse_cookies(val) == {}
|