|
| 1 | +from my_requests.cookies import RequestsCookieJar |
| 2 | + |
| 3 | + |
| 4 | +def test_cookie_empty_value_bug(): |
| 5 | + jar = RequestsCookieJar() |
| 6 | + jar.set('token', 0, domain='example.com', path='/') |
| 7 | + |
| 8 | + assert list(jar.items()) == [('token', 0)] |
| 9 | + assert jar.get('token', domain='example.com', path='/') == 0 |
| 10 | + |
| 11 | + |
| 12 | +def test_cookie_zero_value_among_others(): |
| 13 | + jar = RequestsCookieJar() |
| 14 | + jar.set('token', 0, domain='example.com', path='/') |
| 15 | + jar.set('session', 'abc', domain='example.com', path='/') |
| 16 | + |
| 17 | + assert jar.get('token', domain='example.com', path='/') == 0 |
| 18 | + |
| 19 | + |
| 20 | +def test_cookie_string_zero_value(): |
| 21 | + jar = RequestsCookieJar() |
| 22 | + jar.set('code', '0', domain='example.com', path='/') |
| 23 | + |
| 24 | + assert jar.get('code', domain='example.com', path='/') == '0' |
| 25 | + |
| 26 | + |
| 27 | +def test_cookie_empty_string_value(): |
| 28 | + jar = RequestsCookieJar() |
| 29 | + jar.set('empty', '', domain='example.com', path='/') |
| 30 | + |
| 31 | + assert jar.get('empty', domain='example.com', path='/') == '' |
| 32 | + |
| 33 | + |
| 34 | +def test_cookie_none_value(): |
| 35 | + jar = RequestsCookieJar() |
| 36 | + jar.set('missing', None, domain='example.com', path='/') |
| 37 | + |
| 38 | + assert jar.get('missing', domain='example.com', path='/') is None |
| 39 | + |
| 40 | + |
| 41 | +def test_cookie_zero_value_with_domain_and_path_matching(): |
| 42 | + jar = RequestsCookieJar() |
| 43 | + jar.set('token', 0, domain='example.com', path='/api') |
| 44 | + |
| 45 | + assert jar.get('token', domain='example.com', path='/api') == 0 |
| 46 | + |
| 47 | + |
| 48 | +def test_cookie_overwrite_zero_value(): |
| 49 | + jar = RequestsCookieJar() |
| 50 | + jar.set('token', 'old', domain='example.com', path='/') |
| 51 | + jar.set('token', 0, domain='example.com', path='/') |
| 52 | + |
| 53 | + assert jar.get('token', domain='example.com', path='/') == 0 |
| 54 | + |
| 55 | + |
| 56 | +def test_cookie_zero_value_persists_after_update(): |
| 57 | + jar = RequestsCookieJar() |
| 58 | + jar.set('token', 0, domain='example.com', path='/') |
| 59 | + |
| 60 | + jar.update(jar) |
| 61 | + |
| 62 | + assert jar.get('token', domain='example.com', path='/') == 0 |
0 commit comments