def test_dispatch_config(): conf = DispatchingConfig() conf.push_process_config({'key':'default'}) conf.push_thread_config({'key':'value'}) assert conf.current()['key'] == 'value' conf.pop_thread_config() assert conf.current()['key'] == 'default' try: conf.pop_process_config({'another':'one'}) pop_failed = False except AssertionError: pop_failed = True assert pop_failed, 'It should have failed due to different config popped' try: conf.current() assert False, 'It should fail due to empty objects stack' except AttributeError: pass
Saves a signed cookie of the pickled data. All other keyword arguments that ``WebOb.set_cookie`` accepts are usable and passed to the WebOb set_cookie method after creating the signed cookie value. """ secret = secret.encode('ascii') pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL) sig = hmac.new(secret, pickled, sha1).hexdigest().encode('ascii') cookie_value = sig + base64.encodestring(pickled) self.set_cookie(name, cookie_value, **kwargs) config = DispatchingConfig() context = StackedObjectProxy(name="context") class TurboGearsContextMember(TurboGearsObjectProxy): """Member of the TurboGears request context. Provides access to turbogears context members like request, response, template context and so on """ def __init__(self, name): self.__dict__['name'] = name def _current_obj(self): return getattr(context, self.name)
def test_dispatch_config(): conf = DispatchingConfig() conf.push_process_config({'key': 'default'}) conf.push_thread_config({'key': 'value'}) assert conf.current()['key'] == 'value' conf.pop_thread_config() assert conf.current()['key'] == 'default' try: conf.pop_process_config({'another': 'one'}) pop_failed = False except AssertionError: pop_failed = True assert pop_failed, 'It should have failed due to different config popped' try: conf.current() assert False, 'It should fail due to empty objects stack' except AttributeError: pass