Пример #1
0
def test_set_existing_response_cookie():
    headers = Headers({
        'set-cookie': [
            {
                'key': 'set-cookie',
                'value': 'bar=baz'
            },
        ],
        'set-cookiE': [
            {
                'key': 'set-cookiE',
                'value': 'foo=bar'
            },
        ],
        'set-cookIe': [
            {
                'key': 'set-cookIe',
                'value': 'boo=baz'
            },
        ],
    })

    cookie = ResponseCookie(
        name='foo',
        value='new',
    )
    headers.set_response_cookie(cookie)

    assert headers.get_response_cookie(name='bar').value() == 'baz'
    assert headers.get_response_cookie(name='foo').value() == 'new'
    assert headers.get_response_cookie(name='boo').value() == 'baz'
Пример #2
0
def test_get_response_cookie_returns_ResponseCookie():
    headers = Headers({
        'set-cookie': [
            {
                'key': 'set-cookie',
                'value': 'bar=baz'
            },
        ],
        'set-cookiE': [
            {
                'key': 'set-cookiE',
                'value': 'foo=bar'
            },
        ],
        'set-cookIe': [
            {
                'key': 'set-cookIe',
                'value': 'boo=baz'
            },
        ],
    })

    cookie = headers.get_response_cookie(name='foo')

    assert isinstance(cookie, ResponseCookie)
    assert cookie.name() == 'foo'
    assert cookie.value() == 'bar'
Пример #3
0
def test_set_new_response_cookie_no_cookies_present():
    headers = Headers()
    cookie = ResponseCookie(
        name='foo',
        value='bar',
    )
    headers.set_response_cookie(cookie)

    assert headers.get_response_cookie(name='foo').value() == 'bar'
Пример #4
0
def test_set_response_cookie_sets_all_cookie_fields():
    headers = Headers()

    expires_at = datetime.datetime.utcnow() + datetime.timedelta(days=3.1415)

    cookie = ResponseCookie(
        name='foo',
        value='bar',
        expires_at=expires_at,
        path='/path',
        domain='mydomain.com',
    )
    headers.set_response_cookie(cookie)

    assert headers.get_response_cookie(name='foo').name() == 'foo'
    assert headers.get_response_cookie(name='foo').value() == 'bar'
    assert headers.get_response_cookie(name='foo').expires_at() == expires_at
    assert headers.get_response_cookie(name='foo').path() == '/path'
    assert headers.get_response_cookie(name='foo').domain() == 'mydomain.com'
Пример #5
0
def test_get_response_cookie_missing_returns_None():
    headers = Headers()
    assert headers.get_response_cookie(name='foo') is None