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()
def reset_should_clear_data(): storage = CookieStorage('name', 'namespace') storage.steps = {'step1': Step('step1')} expected = '{"current_step":null,"steps":{"step1":{"files":null,"data":null}}}' assert storage.encode() == '%s$%s' % (storage.hmac(expected), expected) storage.reset() expected = '{"current_step":null,"steps":{}}' assert storage.encode() == '%s$%s' % (storage.hmac(expected), expected)
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()