示例#1
0
def should_add_cookies_to_response():
    storage = CookieStorage('name', 'namespace')
    request, response = factory.get('/'), HttpResponse('')
    storage.process_request(request)
    storage.steps = {'step1': Step('step1')}
    storage.process_response(response)
    assert response.cookies[storage.key].value == storage.encode()
示例#2
0
def should_add_cookies_to_response():
    storage = CookieStorage('name', 'namespace')
    request, response = factory.get('/'), HttpResponse('')
    storage.process_request(request)
    storage.steps = {'step1': Step('step1')}
    storage.process_response(response)
    assert response.cookies[storage.key].value == storage.encode()
示例#3
0
def state_should_be_preserved_between_encode_and_decode():
    original = CookieStorage('name', 'namespace')
    request = factory.get('/')
    original.process_request(request)
    original.steps = {'step1': Step('step1')}
    # create new storage by decoding original
    restored = CookieStorage('name', 'namespace')
    restored.decode(original.encode())
    # they should be the same
    assert restored.encode() == original.encode()
示例#4
0
def state_should_be_preserved_between_encode_and_decode():
    original = CookieStorage('name', 'namespace')
    request = factory.get('/')
    original.process_request(request)
    original.steps = {'step1': Step('step1')}
    # create new storage by decoding original
    restored = CookieStorage('name', 'namespace')
    restored.decode(original.encode())
    # they should be the same
    assert restored.encode() == original.encode()
示例#5
0
def should_completely_remove_data_from_cookies_when_deleted():
    # Do an initial request, to add some data to the storage
    request, response = factory.get('/'), HttpResponse('')
    storage = CookieStorage('name', 'namespace')
    storage.process_request(request)
    step = storage['step1']
    step.data = {'blarg': 'bloog'}
    storage.process_response(response)
    assert 'namespace|name' in response.cookies

    # check deletion
    request = factory.get('/')
    request.COOKIES.update(((k, v.value)
                            for k, v in response.cookies.iteritems()))
    assert 'namespace|name' in request.COOKIES
    storage = CookieStorage('name', 'namespace')
    storage.process_request(request)
    storage.delete()
    response = HttpResponse('')
    storage.process_response(response)
    assert 'namespace|name' not in response.cookies
示例#6
0
def should_completely_remove_data_from_cookies_when_deleted():
    # Do an initial request, to add some data to the storage
    request, response = factory.get('/'), HttpResponse('')
    storage = CookieStorage('name', 'namespace')
    storage.process_request(request)
    step = storage['step1']
    step.data = {'blarg': 'bloog'}
    storage.process_response(response)
    assert 'namespace|name' in response.cookies

    # check deletion
    request = factory.get('/')
    request.COOKIES.update(
        ((k, v.value) for k, v in response.cookies.iteritems()))
    assert 'namespace|name' in request.COOKIES
    storage = CookieStorage('name', 'namespace')
    storage.process_request(request)
    storage.delete()
    response = HttpResponse('')
    storage.process_response(response)
    assert 'namespace|name' not in response.cookies
示例#7
0
def should_complain_when_cookie_is_tampered():
    storage = CookieStorage('name', 'namespace')
    request = factory.get('/')
    request.COOKIES[storage.key] = 'i$am$manipulated'
    with Assert.raises(SuspiciousOperation):
        storage.process_request(request)
示例#8
0
def should_complain_when_cookie_is_tampered():
    storage = CookieStorage('name', 'namespace')
    request = factory.get('/')
    request.COOKIES[storage.key] = 'i$am$manipulated'
    with Assert.raises(SuspiciousOperation):
        storage.process_request(request)