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()
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 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
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
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)