def test_B_replacing_non_ascii(): """we replace the offending character with other non ascii one. Since the function distinguishes between the two it should not return the past value """ assert_false(foo(u_('Espaáol'))==u_('Español')) eq_(foo(u_('Espaáol')), u_('Espaáol'))
def test_B_replacing_non_ascii(): """we replace the offending character with other non ascii one. Since the function distinguishes between the two it should not return the past value """ assert_false(foo(u_("Espaáol")) == u_("Español")) eq_(foo(u_("Espaáol")), u_("Espaáol"))
def test_unicode_keys(): cache = make_cache() o = object() cache.set_value(u_('hiŏ'), o) assert u_('hiŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hiŏ')) assert u_('hiŏ') not in cache
def test_unicode_keys(): cache = Cache('test', data_dir='./cache', type='dbm') o = object() cache.set_value(u_('hiŏ'), o) assert u_('hiŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hiŏ')) assert u_('hiŏ') not in cache
def test_spaces_in_unicode_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() cache.set_value(u_('hi ŏ'), o) assert u_('hi ŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hi ŏ')) assert u_('hi ŏ') not in cache
def test_unicode_keys(): cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database') o = object() cache.set_value(u_('hiŏ'), o) assert u_('hiŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hiŏ')) assert u_('hiŏ') not in cache
def test_spaces_in_unicode_keys(): cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached") o = object() cache.set_value(u_("hi ŏ"), o) assert u_("hi ŏ") in cache assert u_("hŏa") not in cache cache.remove_value(u_("hi ŏ")) assert u_("hi ŏ") not in cache
def test_spaces_in_unicode_keys(self): cache = Cache('test', **self.CACHE_ARGS) o = object() cache.set_value(u_('hi ŏ'), o) assert u_('hi ŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hi ŏ')) assert u_('hi ŏ') not in cache
def test_unicode_keys(): cache = make_cache() o = object() cache.set_value(u_("hiŏ"), o) assert u_("hiŏ") in cache assert u_("hŏa") not in cache cache.remove_value(u_("hiŏ")) assert u_("hiŏ") not in cache
def test_unicode_keys(): cache = Cache("test", data_dir="./cache", type="dbm") o = object() cache.set_value(u_("hiŏ"), o) assert u_("hiŏ") in cache assert u_("hŏa") not in cache cache.remove_value(u_("hiŏ")) assert u_("hiŏ") not in cache
def test_spaces_in_unicode_keys(self): cache = Cache("test", **self.CACHE_ARGS) o = object() cache.set_value(u_("hi ŏ"), o) assert u_("hi ŏ") in cache assert u_("hŏa") not in cache cache.remove_value(u_("hi ŏ")) assert u_("hi ŏ") not in cache
def test_regenerate_id(): """Test :meth:`Session.regenerate_id`""" # new session & save setup_cookie_request() session = get_session() orig_id = session.id session[u_('foo')] = u_('bar') session.save() # load session session = get_session(id=session.id) # data should still be there assert session[u_('foo')] == u_('bar') # regenerate the id session.regenerate_id() assert session.id != orig_id # data is still there assert session[u_('foo')] == u_('bar') # should be the new id assert 'beaker.session.id=%s' % session.id in session.request['cookie_out'] # get a new session before calling save bunk_sess = get_session(id=session.id) assert u_('foo') not in bunk_sess # save it session.save() # make sure we get the data back session = get_session(id=session.id) assert session[u_('foo')] == u_('bar')
def test_regenerate_id(): """Test :meth:`Session.regenerate_id`""" # new session & save session = get_session() orig_id = session.id session[u_('foo')] = u_('bar') session.save() # load session session = get_session(id=session.id) # data should still be there assert session[u_('foo')] == u_('bar') # regenerate the id session.regenerate_id() assert session.id != orig_id # data is still there assert session[u_('foo')] == u_('bar') # should be the new id assert 'beaker.session.id=%s' % session.id in session.request['cookie_out'] # get a new session before calling save bunk_sess = get_session(id=session.id) assert u_('foo') not in bunk_sess # save it session.save() # make sure we get the data back session = get_session(id=session.id) assert session[u_('foo')] == u_('bar')
def cached(*args, **kwargs): if not cache[0]: if region is not None: if region not in cache_regions: raise BeakerException( 'Cache region not configured: %s' % region) reg = cache_regions[region] if not reg.get('enabled', True): return func(*args, **kwargs) cache[0] = Cache._get_cache(namespace, reg) elif manager: cache[0] = manager.get_cache(namespace, **options) else: raise Exception("'manager + kwargs' or 'region' " "argument is required") cache_key_kwargs = [] if kwargs: # kwargs provided, merge them in positional args # to avoid having different cache keys. args, kwargs = bindfuncargs(signature, args, kwargs) cache_key_kwargs = [ u_(':').join((u_(key), u_(value))) for key, value in kwargs.items() ] cache_key_args = args if skip_self: cache_key_args = args[1:] cache_key = u_(" ").join( map(u_, chain(deco_args, cache_key_args, cache_key_kwargs))) if region: cachereg = cache_regions[region] key_length = cachereg.get('key_length', util.DEFAULT_CACHE_KEY_LENGTH) else: key_length = options.pop('key_length', util.DEFAULT_CACHE_KEY_LENGTH) # TODO: This is probably a bug as length is checked before converting to UTF8 # which will cause cache_key to grow in size. if len(cache_key) + len(namespace) > int(key_length): cache_key = sha1(cache_key.encode('utf-8')).hexdigest() def go(): return func(*args, **kwargs) # save org function name go.__name__ = '_cached_%s' % (func.__name__, ) return cache[0].get_value(cache_key, createfunc=go)
def test_delete(): """Test :meth:`Session.delete`""" session = get_session() session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.delete() assert u_('Suomi') not in session assert u_('Great Britain') not in session assert u_('Deutchland') not in session
def check_delete(session_getter): """Test :meth:`Session.delete`""" session = session_getter() session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.delete() assert u_('Suomi') not in session assert u_('Great Britain') not in session assert u_('Deutchland') not in session
def test_delete(): """Test :meth:`Session.delete`""" session = get_session() session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.delete() assert u_("Suomi") not in session assert u_("Great Britain") not in session assert u_("Deutchland") not in session
def check_delete(session_getter): """Test :meth:`Session.delete`""" session = session_getter() session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.delete() assert u_("Suomi") not in session assert u_("Great Britain") not in session assert u_("Deutchland") not in session
def _cache_decorator_invalidate(cache, key_length, args): """Invalidate a cache key based on function arguments.""" cache_key = u_(" ").join(map(u_, args)) if len(cache_key) + len(cache.namespace_name) > key_length: cache_key = sha1(cache_key.encode("utf-8")).hexdigest() cache.remove_value(cache_key)
def test_long_unicode_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() long_str = u_('Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!') cache.set_value(long_str, o) assert long_str in cache cache.remove_value(long_str) assert long_str not in cache
def cached(*args, **kwargs): if not cache[0]: if region is not None: if region not in cache_regions: raise BeakerException( 'Cache region not configured: %s' % region) reg = cache_regions[region] if not reg.get('enabled', True): return func(*args, **kwargs) cache[0] = Cache._get_cache(namespace, reg) elif manager: cache[0] = manager.get_cache(namespace, **options) else: raise Exception("'manager + kwargs' or 'region' " "argument is required") cache_key_kwargs = [] if kwargs: # kwargs provided, merge them in positional args # to avoid having different cache keys. args, kwargs = bindfuncargs(signature, args, kwargs) cache_key_kwargs = [u_(':').join((u_(key), u_(value))) for key, value in kwargs.items()] cache_key_args = args if skip_self: cache_key_args = args[1:] cache_key = u_(" ").join(map(u_, chain(deco_args, cache_key_args, cache_key_kwargs))) if region: cachereg = cache_regions[region] key_length = cachereg.get('key_length', util.DEFAULT_CACHE_KEY_LENGTH) else: key_length = options.pop('key_length', util.DEFAULT_CACHE_KEY_LENGTH) # TODO: This is probably a bug as length is checked before converting to UTF8 # which will cause cache_key to grow in size. if len(cache_key) + len(namespace) > int(key_length): cache_key = sha1(cache_key.encode('utf-8')).hexdigest() def go(): return func(*args, **kwargs) # save org function name go.__name__ = '_cached_%s' % (func.__name__,) return cache[0].get_value(cache_key, createfunc=go)
def test_invalidate(): """Test :meth:`Session.invalidate`""" session = get_session() id = session.id created = session.created session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.invalidate() assert session.id != id assert session.created != created assert u_("Suomi") not in session assert u_("Great Britain") not in session assert u_("Deutchland") not in session
def test_invalidate(): """Test :meth:`Session.invalidate`""" session = get_session() id = session.id created = session.created session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.invalidate() assert session.id != id assert session.created != created assert u_('Suomi') not in session assert u_('Great Britain') not in session assert u_('Deutchland') not in session
def test_long_unicode_keys(self): cache = Cache('test', **self.CACHE_ARGS) o = object() long_str = u_( 'Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!' ) cache.set_value(long_str, o) assert long_str in cache cache.remove_value(long_str) assert long_str not in cache
def test_long_unicode_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() long_str = u_( 'Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!' ) cache.set_value(long_str, o) assert long_str in cache cache.remove_value(long_str) assert long_str not in cache
def check_decryption_failure(session_getter): """Test if the data fails without the right keys""" session = session_getter(encrypt_key='666a19cf7f61c64c', validate_key='hoobermas') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter(id=session.id, encrypt_key='asfdasdfadsfsadf', validate_key='hoobermas', invalidate_corrupt=True) assert u_('Suomi') not in session assert u_('Great Britain') not in session
def check_invalidate(session_getter): """Test :meth:`Session.invalidate`""" session = session_getter() session.save() id = session.id created = session.created session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.invalidate() session.save() assert session.id != id assert session.created != created assert u_("Suomi") not in session assert u_("Great Britain") not in session assert u_("Deutchland") not in session
def test_decryption_failure(): """Test if the data fails without the right keys""" if not has_aes: raise SkipTest() session = get_session(encrypt_key='666a19cf7f61c64c', validate_key='hoobermas') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = get_session(id=session.id, encrypt_key='asfdasdfadsfsadf', validate_key='hoobermas', invalidate_corrupt=True) assert u_('Suomi') not in session assert u_('Great Britain') not in session
def test_decryption_failure(): """Test if the data fails without the right keys""" if not has_aes: raise SkipTest() session = get_session(encrypt_key="666a19cf7f61c64c", validate_key="hoobermas") session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.save() session = get_session( id=session.id, encrypt_key="asfdasdfadsfsadf", validate_key="hoobermas", invalidate_corrupt=True ) assert u_("Suomi") not in session assert u_("Great Britain") not in session
def check_decryption_failure(session_getter): """Test if the data fails without the right keys""" if not get_crypto_module("default").has_aes: raise SkipTest() session = session_getter(encrypt_key="666a19cf7f61c64c", validate_key="hoobermas") session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.save() session = session_getter( id=session.id, encrypt_key="asfdasdfadsfsadf", validate_key="hoobermas", invalidate_corrupt=True, ) assert u_("Suomi") not in session assert u_("Great Britain") not in session
def cached(*args): if not cache[0]: if region is not None: if region not in cache_regions: raise BeakerException( 'Cache region not configured: %s' % region) reg = cache_regions[region] if not reg.get('enabled', True): return func(*args) cache[0] = Cache._get_cache(namespace, reg) elif manager: cache[0] = manager.get_cache(namespace, **kwargs) else: raise Exception("'manager + kwargs' or 'region' " "argument is required") cache_key_args = args if skip_self: cache_key_args = args[1:] cache_key = u_(" ").join(map(u_, deco_args + cache_key_args)) if region: cachereg = cache_regions[region] key_length = cachereg.get('key_length', util.DEFAULT_CACHE_KEY_LENGTH) else: key_length = kwargs.pop('key_length', util.DEFAULT_CACHE_KEY_LENGTH) # TODO: This is probably a bug as length is checked before converting to UTF8 # which will cause cache_key to grow in size. if len(cache_key) + len(namespace) > int(key_length): cache_key = sha1(cache_key.encode('utf-8')).hexdigest() def go(): return func(*args) return cache[0].get_value(cache_key, createfunc=go)
def check_timeout(session_getter): """Test if the session times out properly""" session = session_getter(timeout=2) session.save() id = session.id created = session.created session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter(id=session.id, timeout=2) assert session.id == id assert session.created == created assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel') time.sleep(2) session = session_getter(id=session.id, timeout=2) assert session.id != id assert session.created != created assert u_('Suomi') not in session assert u_('Great Britain') not in session assert u_('Deutchland') not in session
def check_revert(session_getter): """Test :meth:`Session.revert`""" session = session_getter() session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter(id=session.id) del session[u_('Suomi')] session[u_('Great Britain')] = u_('Lewis Hamilton') session[u_('Deutchland')] = u_('Michael Schumacher') session[u_('España')] = u_('Fernando Alonso') session.revert() assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel') assert u_('España') not in session
def test_save_load(): """Test if the data is actually persistent across requests""" session = get_session() session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.save() session = get_session(id=session.id) assert u_("Suomi") in session assert u_("Great Britain") in session assert u_("Deutchland") in session assert session[u_("Suomi")] == u_("Kimi Räikkönen") assert session[u_("Great Britain")] == u_("Jenson Button") assert session[u_("Deutchland")] == u_("Sebastian Vettel")
def test_revert(): """Test :meth:`Session.revert`""" session = get_session() session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.save() session = get_session(id=session.id) del session[u_("Suomi")] session[u_("Great Britain")] = u_("Lewis Hamilton") session[u_("Deutchland")] = u_("Michael Schumacher") session[u_("España")] = u_("Fernando Alonso") session.revert() assert session[u_("Suomi")] == u_("Kimi Räikkönen") assert session[u_("Great Britain")] == u_("Jenson Button") assert session[u_("Deutchland")] == u_("Sebastian Vettel") assert u_("España") not in session
def test_save_load_encryption(): """Test if the data is actually persistent across requests""" if not has_aes: raise SkipTest() session = get_session(encrypt_key="666a19cf7f61c64c", validate_key="hoobermas") session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.save() session = get_session(id=session.id, encrypt_key="666a19cf7f61c64c", validate_key="hoobermas") assert u_("Suomi") in session assert u_("Great Britain") in session assert u_("Deutchland") in session assert session[u_("Suomi")] == u_("Kimi Räikkönen") assert session[u_("Great Britain")] == u_("Jenson Button") assert session[u_("Deutchland")] == u_("Sebastian Vettel")
def test_timeout(): """Test if the session times out properly""" session = get_session(timeout=2) id = session.id created = session.created session[u_("Suomi")] = u_("Kimi Räikkönen") session[u_("Great Britain")] = u_("Jenson Button") session[u_("Deutchland")] = u_("Sebastian Vettel") session.save() session = get_session(id=session.id, timeout=2) assert session.id == id assert session.created == created assert session[u_("Suomi")] == u_("Kimi Räikkönen") assert session[u_("Great Britain")] == u_("Jenson Button") assert session[u_("Deutchland")] == u_("Sebastian Vettel") time.sleep(2) session = get_session(id=session.id, timeout=2) assert session.id != id assert session.created != created assert u_("Suomi") not in session assert u_("Great Britain") not in session assert u_("Deutchland") not in session
def test_A_unicode_encode_key_str(): eq_(foo("Espanol"), "Espanol") eq_(foo(12334), 12334) eq_(foo(u_("Espanol")), u_("Espanol")) eq_(foo(u_("Español")), u_("Español")) b = bar() eq_(b.baz("Espanol"), "Espanol") eq_(b.baz(12334), 12334) eq_(b.baz(u_("Espanol")), u_("Espanol")) eq_(b.baz(u_("Español")), u_("Español")) eq_(b.quux("Espanol"), "Espanol") eq_(b.quux(12334), 12334) eq_(b.quux(u_("Espanol")), u_("Espanol")) eq_(b.quux(u_("Español")), u_("Español"))
def test_save_load(): """Test if the data is actually persistent across requests""" session = get_session() session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = get_session(id=session.id) assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def test_timeout(): """Test if the session times out properly""" session = get_session(timeout=2) id = session.id created = session.created session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = get_session(id=session.id, timeout=2) assert session.id == id assert session.created == created assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel') time.sleep(2) session = get_session(id=session.id, timeout=2) assert session.id != id assert session.created != created assert u_('Suomi') not in session assert u_('Great Britain') not in session assert u_('Deutchland') not in session
def test_save_load_encryption(): """Test if the data is actually persistent across requests""" if not has_aes: raise SkipTest() session = get_session(encrypt_key='666a19cf7f61c64c', validate_key='hoobermas') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = get_session(id=session.id, encrypt_key='666a19cf7f61c64c', validate_key='hoobermas') assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def check_save_load_encryption_cryptography(session_getter): """Test if the data is actually persistent across requests""" # cryptography only works for py3.3+, so skip for python 3.2 if sys.version_info[0] == 3 and sys.version_info[1] < 3: raise SkipTest("Cryptography not supported on Python 3 lower than 3.3") try: get_crypto_module('cryptography').has_aes except BeakerException: raise SkipTest() session = session_getter(encrypt_key='666a19cf7f61c64c', validate_key='hoobermas', crypto_type='cryptography') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter(id=session.id, encrypt_key='666a19cf7f61c64c', validate_key='hoobermas', crypto_type='cryptography') assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def test_revert(): """Test :meth:`Session.revert`""" session = get_session() session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = get_session(id=session.id) del session[u_('Suomi')] session[u_('Great Britain')] = u_('Lewis Hamilton') session[u_('Deutchland')] = u_('Michael Schumacher') session[u_('España')] = u_('Fernando Alonso') session.revert() assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel') assert u_('España') not in session
def test_bad_values(self): self.assertRaises(ValueError, asbool, ('mommy!')) self.assertRaises(ValueError, asbool, (u_('Blargl?')))
def test_C_more_unicode(): """We again test the same stuff but this time we use http://tools.ietf.org/html/draft-josefsson-idn-test-vectors-00#section-5 as keys""" keys = [ # arabic (egyptian) u_("\u0644\u064a\u0647\u0645\u0627\u0628\u062a\u0643\u0644\u0645\u0648\u0634\u0639\u0631\u0628\u064a\u061f"), # Chinese (simplified) u_("\u4ed6\u4eec\u4e3a\u4ec0\u4e48\u4e0d\u8bf4\u4e2d\u6587"), # Chinese (traditional) u_("\u4ed6\u5011\u7232\u4ec0\u9ebd\u4e0d\u8aaa\u4e2d\u6587"), # czech u_("\u0050\u0072\u006f\u010d\u0070\u0072\u006f\u0073\u0074\u011b\u006e\u0065\u006d\u006c\u0075\u0076\u00ed\u010d\u0065\u0073\u006b\u0079"), # hebrew u_("\u05dc\u05de\u05d4\u05d4\u05dd\u05e4\u05e9\u05d5\u05d8\u05dc\u05d0\u05de\u05d3\u05d1\u05e8\u05d9\u05dd\u05e2\u05d1\u05e8\u05d9\u05ea"), # Hindi (Devanagari) u_("\u092f\u0939\u0932\u094b\u0917\u0939\u093f\u0928\u094d\u0926\u0940\u0915\u094d\u092f\u094b\u0902\u0928\u0939\u0940\u0902\u092c\u094b\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902"), # Japanese (kanji and hiragana) u_("\u306a\u305c\u307f\u3093\u306a\u65e5\u672c\u8a9e\u3092\u8a71\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u304b"), # Russian (Cyrillic) u_("\u043f\u043e\u0447\u0435\u043c\u0443\u0436\u0435\u043e\u043d\u0438\u043d\u0435\u0433\u043e\u0432\u043e\u0440\u044f\u0442\u043f\u043e\u0440\u0443\u0441\u0441\u043a\u0438"), # Spanish u_("\u0050\u006f\u0072\u0071\u0075\u00e9\u006e\u006f\u0070\u0075\u0065\u0064\u0065\u006e\u0073\u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0068\u0061\u0062\u006c\u0061\u0072\u0065\u006e\u0045\u0073\u0070\u0061\u00f1\u006f\u006c"), # Vietnamese u_("\u0054\u1ea1\u0069\u0073\u0061\u006f\u0068\u1ecd\u006b\u0068\u00f4\u006e\u0067\u0074\u0068\u1ec3\u0063\u0068\u1ec9\u006e\u00f3\u0069\u0074\u0069\u1ebf\u006e\u0067\u0056\u0069\u1ec7\u0074"), # Japanese u_("\u0033\u5e74\u0042\u7d44\u91d1\u516b\u5148\u751f"), # Japanese u_("\u5b89\u5ba4\u5948\u7f8e\u6075\u002d\u0077\u0069\u0074\u0068\u002d\u0053\u0055\u0050\u0045\u0052\u002d\u004d\u004f\u004e\u004b\u0045\u0059\u0053"), # Japanese u_("\u0048\u0065\u006c\u006c\u006f\u002d\u0041\u006e\u006f\u0074\u0068\u0065\u0072\u002d\u0057\u0061\u0079\u002d\u305d\u308c\u305e\u308c\u306e\u5834\u6240"), # Japanese u_("\u3072\u3068\u3064\u5c4b\u6839\u306e\u4e0b\u0032"), # Japanese u_("\u004d\u0061\u006a\u0069\u3067\u004b\u006f\u0069\u3059\u308b\u0035\u79d2\u524d"), # Japanese u_("\u30d1\u30d5\u30a3\u30fc\u0064\u0065\u30eb\u30f3\u30d0"), # Japanese u_("\u305d\u306e\u30b9\u30d4\u30fc\u30c9\u3067"), # greek u_("\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac"), # Maltese (Malti) u_("\u0062\u006f\u006e\u0121\u0075\u0073\u0061\u0127\u0127\u0061"), # Russian (Cyrillic) u_("\u043f\u043e\u0447\u0435\u043c\u0443\u0436\u0435\u043e\u043d\u0438\u043d\u0435\u0433\u043e\u0432\u043e\u0440\u044f\u0442\u043f\u043e\u0440\u0443\u0441\u0441\u043a\u0438") ] for i in keys: eq_(foo(i),i)
def check_save_load(session_getter): """Test if the data is actually persistent across requests""" session = session_getter() session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter(id=session.id) assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def check_save_load_encryption_cryptography(session_getter): """Test if the data is actually persistent across requests""" # cryptography only works for py3.3+, so skip for python 3.2 if sys.version_info[0] == 3 and sys.version_info[1] < 3: raise SkipTest("Cryptography not supported on Python 3 lower than 3.3") try: get_crypto_module('cryptography').has_aes except BeakerException: raise SkipTest() session = session_getter( encrypt_key='666a19cf7f61c64c', validate_key='hoobermas', crypto_type='cryptography') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter( id=session.id, encrypt_key='666a19cf7f61c64c', validate_key='hoobermas', crypto_type='cryptography') assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def check_save_load_encryption(session_getter): """Test if the data is actually persistent across requests""" session = session_getter(encrypt_key='666a19cf7f61c64c', validate_key='hoobermas') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter(id=session.id, encrypt_key='666a19cf7f61c64c', validate_key='hoobermas') assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def check_save_load_encryption_cryptography(session_getter): """Test if the data is actually persistent across requests""" try: get_crypto_module('cryptography').has_aes except BeakerException: raise unittest.SkipTest() session = session_getter( encrypt_key='666a19cf7f61c64c', validate_key='hoobermas', crypto_type='cryptography') session[u_('Suomi')] = u_('Kimi Räikkönen') session[u_('Great Britain')] = u_('Jenson Button') session[u_('Deutchland')] = u_('Sebastian Vettel') session.save() session = session_getter( id=session.id, encrypt_key='666a19cf7f61c64c', validate_key='hoobermas', crypto_type='cryptography') assert u_('Suomi') in session assert u_('Great Britain') in session assert u_('Deutchland') in session assert session[u_('Suomi')] == u_('Kimi Räikkönen') assert session[u_('Great Britain')] == u_('Jenson Button') assert session[u_('Deutchland')] == u_('Sebastian Vettel')
def test_A_unicode_encode_key_str(): eq_(foo('Espanol'), 'Espanol') eq_(foo(12334), 12334) eq_(foo(u_('Espanol')), u_('Espanol')) eq_(foo(u_('Español')), u_('Español')) b = bar() eq_(b.baz('Espanol'), 'Espanol') eq_(b.baz(12334), 12334) eq_(b.baz(u_('Espanol')), u_('Espanol')) eq_(b.baz(u_('Español')), u_('Español')) eq_(b.quux('Espanol'), 'Espanol') eq_(b.quux(12334), 12334) eq_(b.quux(u_('Espanol')), u_('Espanol')) eq_(b.quux(u_('Español')), u_('Español'))
def test_C_more_unicode(): """We again test the same stuff but this time we use http://tools.ietf.org/html/draft-josefsson-idn-test-vectors-00#section-5 as keys""" keys = [ # arabic (egyptian) u_("\u0644\u064a\u0647\u0645\u0627\u0628\u062a\u0643\u0644\u0645\u0648\u0634\u0639\u0631\u0628\u064a\u061f" ), # Chinese (simplified) u_("\u4ed6\u4eec\u4e3a\u4ec0\u4e48\u4e0d\u8bf4\u4e2d\u6587"), # Chinese (traditional) u_("\u4ed6\u5011\u7232\u4ec0\u9ebd\u4e0d\u8aaa\u4e2d\u6587"), # czech u_("\u0050\u0072\u006f\u010d\u0070\u0072\u006f\u0073\u0074\u011b\u006e\u0065\u006d\u006c\u0075\u0076\u00ed\u010d\u0065\u0073\u006b\u0079" ), # hebrew u_("\u05dc\u05de\u05d4\u05d4\u05dd\u05e4\u05e9\u05d5\u05d8\u05dc\u05d0\u05de\u05d3\u05d1\u05e8\u05d9\u05dd\u05e2\u05d1\u05e8\u05d9\u05ea" ), # Hindi (Devanagari) u_("\u092f\u0939\u0932\u094b\u0917\u0939\u093f\u0928\u094d\u0926\u0940\u0915\u094d\u092f\u094b\u0902\u0928\u0939\u0940\u0902\u092c\u094b\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902" ), # Japanese (kanji and hiragana) u_("\u306a\u305c\u307f\u3093\u306a\u65e5\u672c\u8a9e\u3092\u8a71\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u304b" ), # Russian (Cyrillic) u_("\u043f\u043e\u0447\u0435\u043c\u0443\u0436\u0435\u043e\u043d\u0438\u043d\u0435\u0433\u043e\u0432\u043e\u0440\u044f\u0442\u043f\u043e\u0440\u0443\u0441\u0441\u043a\u0438" ), # Spanish u_("\u0050\u006f\u0072\u0071\u0075\u00e9\u006e\u006f\u0070\u0075\u0065\u0064\u0065\u006e\u0073\u0069\u006d\u0070\u006c\u0065\u006d\u0065\u006e\u0074\u0065\u0068\u0061\u0062\u006c\u0061\u0072\u0065\u006e\u0045\u0073\u0070\u0061\u00f1\u006f\u006c" ), # Vietnamese u_("\u0054\u1ea1\u0069\u0073\u0061\u006f\u0068\u1ecd\u006b\u0068\u00f4\u006e\u0067\u0074\u0068\u1ec3\u0063\u0068\u1ec9\u006e\u00f3\u0069\u0074\u0069\u1ebf\u006e\u0067\u0056\u0069\u1ec7\u0074" ), # Japanese u_("\u0033\u5e74\u0042\u7d44\u91d1\u516b\u5148\u751f"), # Japanese u_("\u5b89\u5ba4\u5948\u7f8e\u6075\u002d\u0077\u0069\u0074\u0068\u002d\u0053\u0055\u0050\u0045\u0052\u002d\u004d\u004f\u004e\u004b\u0045\u0059\u0053" ), # Japanese u_("\u0048\u0065\u006c\u006c\u006f\u002d\u0041\u006e\u006f\u0074\u0068\u0065\u0072\u002d\u0057\u0061\u0079\u002d\u305d\u308c\u305e\u308c\u306e\u5834\u6240" ), # Japanese u_("\u3072\u3068\u3064\u5c4b\u6839\u306e\u4e0b\u0032"), # Japanese u_("\u004d\u0061\u006a\u0069\u3067\u004b\u006f\u0069\u3059\u308b\u0035\u79d2\u524d" ), # Japanese u_("\u30d1\u30d5\u30a3\u30fc\u0064\u0065\u30eb\u30f3\u30d0"), # Japanese u_("\u305d\u306e\u30b9\u30d4\u30fc\u30c9\u3067"), # greek u_("\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac"), # Maltese (Malti) u_("\u0062\u006f\u006e\u0121\u0075\u0073\u0061\u0127\u0127\u0061"), # Russian (Cyrillic) u_("\u043f\u043e\u0447\u0435\u043c\u0443\u0436\u0435\u043e\u043d\u0438\u043d\u0435\u0433\u043e\u0432\u043e\u0440\u044f\u0442\u043f\u043e\u0440\u0443\u0441\u0441\u043a\u0438" ), ] for i in keys: eq_(foo(i), i)