Exemplo n.º 1
0
 def test_getattr(self):
     'VersionedStorage getattr method'
     d = VersionedStorage(b=2)
     d['a'] = 1
     self.assertEqual(d.as_dict(), {'a': 1, 'b': 2})
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
Exemplo n.º 2
0
 def test_getattr(self):
     'VersionedStorage getattr method'
     d = VersionedStorage(b=2)
     d['a'] = 1
     self.assertEqual(d.as_dict(), {'a': 1, 'b': 2})
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 2)
Exemplo n.º 3
0
 def test_contains(self):
     'VersionedStorage __contains__ method'
     d = VersionedStorage(a=1)
     d.b = 2
     d['c'] = 3
     self.assert_('a' in d)
     self.assert_('b' in d)
     self.assert_('c' in d)
Exemplo n.º 4
0
 def test_contains(self):
     'VersionedStorage __contains__ method'
     d = VersionedStorage(a=1)
     d.b = 2
     d['c'] = 3
     self.assert_('a' in d)
     self.assert_('b' in d)
     self.assert_('c' in d)
Exemplo n.º 5
0
    def test_functions_chain_call(self):
        'Functions chain call'

        def handler1(env, data, nh):
            return nh(env, data)

        def handler2(env, data, nh):
            return nh(env, data)

        chain = web.handler(handler1) | handler2

        self.assert_(chain(VersionedStorage(), VersionedStorage()) is None)
Exemplo n.º 6
0
    def test_chain_of_lists(self):
        'Chain of lists, data check'

        def h(env, data, nx):
            data.count = 1
            return nx(env, data)

        def h1(env, data, nx):
            self.assert_('count' in data)
            self.assertEqual(data.count, 1)
            return nx(env, data)

        chain = web.cases(h) | web.cases(h1, h1)
        chain(VersionedStorage(), VersionedStorage())
Exemplo n.º 7
0
 def test_property(self):
     'VersionedStorage something_new property'
     d = VersionedStorage()
     self.assert_(not d._modified)
     d['c'] = 2
     self.assert_(d._modified)
     del d['c']
     self.assert_(not d._modified)
Exemplo n.º 8
0
 def test_rollback(self):
     'VersionedStorage "rollback" method'
     d = VersionedStorage()
     d['a'] = 1
     d._commit()
     d['b'] = 2
     self.assertEqual(d.as_dict(), {'a': 1, 'b': 2})
     d._rollback()
     self.assertEqual(d.as_dict(), {'a': 1})
     self.assertEqual(d._VersionedStorage__stack, [{}])
Exemplo n.º 9
0
 def test_init_with_initial(self):
     'VersionedStorage initialization with initial data'
     d = VersionedStorage(a=1, b=2)
     self.assert_(d._modified)
     d['c'] = 2
     self.assert_(d._modified)
     del d['c']
     del d['a']
     del d['b']
     self.assert_(not d._modified)
Exemplo n.º 10
0
    def test_chain_with_list_and_postfix(self):
        'Chain with cases and postfix'

        def h(env, data, nh):
            self.assertEqual(env.count, 0)
            env['count'] = env['count'] + 1
            return nh(env, data)

        def h1(env, data, nh):
            self.assertEqual(env.count, 1)
            env['count'] = env['count'] + 1
            return nh(env, data)

        def h2(env, data, nh):
            self.assertEqual(env.count, 2)
            env['count'] = env['count'] + 1

        chain = web.handler(h) | web.cases(h1, web.handler(h1) | h2) | h2
        count = VersionedStorage(count=0)
        self.assert_(chain(count, VersionedStorage()) is None)
        self.assertEqual(count['count'], 0)
Exemplo n.º 11
0
 def test_rollback(self):
     'VersionedStorage "rollback" method'
     d = VersionedStorage()
     d['a'] = 1
     d._commit()
     d['b'] = 2
     self.assertEqual(d.as_dict(), {'a': 1, 'b': 2})
     d._rollback()
     self.assertEqual(d.as_dict(), {'a': 1})
     self.assertEqual(d._VersionedStorage__stack, [{}])
Exemplo n.º 12
0
    def test_list_of_chains(self):
        'cases of chains'

        def h1(env, data, nh):
            self.assertEqual(env.count, 0)
            env['count'] = env['count'] + 1
            return nh(env, data)

        def h2(env, data, nh):
            self.assertEqual(env.count, 0)
            env['count'] = env['count'] + 1
            return nh(env, data)

        def h3(env, data, nh):
            self.assertEqual(env.count, 1)
            env['count'] = env['count'] + 1
            return nh(env, data)

        chain = web.cases(h1, web.handler(h2) | h3)
        count = VersionedStorage(count=0)
        self.assert_(chain(count, VersionedStorage()) is None)
        self.assertEqual(count['count'], 0)
Exemplo n.º 13
0
    def test_List(self):
        'cases handle'

        def h1(env, data, nh):
            self.assertEqual(env.count, 0)
            env['count'] = env['count'] + 1
            return nh(env, data)

        def h2(env, data, nh):
            self.assertEqual(env.count, 0)
            env['count'] = env['count'] + 1
            return nh(env, data)

        def h3(env, data, nh):
            self.assertEqual(env.count, 0)
            env['count'] = env['count'] + 1
            return nh(env, data)

        chain = web.cases(h1, h2, h3)
        count = VersionedStorage(count=0)
        self.assert_(chain(count, VersionedStorage()) is None)
        self.assertEqual(count['count'], 0)
Exemplo n.º 14
0
    def test_commit(self):
        'VersionedStorage "commit" method'
        d = VersionedStorage()
        d['a'] = 1
        d._commit()
        self.assert_(not d._modified)
        self.assertEqual(d._VersionedStorage__stack, [{}, {
            'a': 1
        }], 'Incorrect stack state')
        self.assertEqual(d['a'], 1)
        self.assertRaises(KeyError, lambda: d['b'])

        # second commit do nothing
        d._commit()
        self.assert_(not d._modified)
        self.assertEqual(d._VersionedStorage__stack, [{}, {'a': 1}])
        self.assertEqual(d.as_dict(), {'a': 1})
        self.assertRaises(KeyError, lambda: d['b'])
Exemplo n.º 15
0
    def test_commit(self):
        'VersionedStorage "commit" method'
        d = VersionedStorage()
        d['a'] = 1
        d._commit()
        self.assert_(not d._modified)
        self.assertEqual(d._VersionedStorage__stack, [{}, {'a': 1}], 'Incorrect stack state')
        self.assertEqual(d['a'] , 1)
        self.assertRaises(KeyError, lambda: d['b'])

        # second commit do nothing
        d._commit()
        self.assert_(not d._modified)
        self.assertEqual(d._VersionedStorage__stack, [{}, {'a': 1}])
        self.assertEqual(d.as_dict(), {'a': 1})
        self.assertRaises(KeyError, lambda: d['b'])
Exemplo n.º 16
0
 def test_setattr(self):
     'VersionedStorage __setattr__ method'
     d = VersionedStorage()
     d.c = 3
     self.assertEqual(d.c, 3)
     self.assert_(d._modified)
Exemplo n.º 17
0
 def test_delattr(self):
     'VersionedStorage __delattr__ method'
     d = VersionedStorage(a=1)
     self.assertEqual(d.a, 1)
     del d.a
     self.assertEqual(d.as_dict(), {})
Exemplo n.º 18
0
 def test_namespace_from_env(self):
     'Reverse namespace from env'
     self.assertEqual(
         web.Reverse({}, env=VersionedStorage(namespace='ns')).namespace,
         'ns')
Exemplo n.º 19
0
 def test_rollback_empty(self):
     'VersionedStorage "rollback" method on empty dict'
     d = VersionedStorage()
     d._rollback()
     self.assertEqual(d._VersionedStorage__stack, [{}])
     self.assert_(not d._modified)
Exemplo n.º 20
0
 def test_rollback_empty(self):
     'VersionedStorage "rollback" method on empty dict'
     d = VersionedStorage()
     d._rollback()
     self.assertEqual(d._VersionedStorage__stack, [{}])
     self.assert_(not d._modified)
Exemplo n.º 21
0
 def test_delattr(self):
     'VersionedStorage __delattr__ method'
     d = VersionedStorage(a=1)
     self.assertEqual(d.a, 1)
     del d.a
     self.assertEqual(d.as_dict(), {})
Exemplo n.º 22
0
 def test_setattr(self):
     'VersionedStorage __setattr__ method'
     d = VersionedStorage()
     d.c = 3
     self.assertEqual(d.c, 3)
     self.assert_(d._modified)