tests/test_rowdict.py
author Radek Brich <radek.brich@devl.cz>
Wed, 24 Jul 2013 13:11:37 +0200
changeset 84 3b5dd9efba35
parent 81 f709b1c7ca0c
child 104 d8ff52a0390f
permissions -rw-r--r--
Fix.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from pgtoolkit.pgmanager import RowDict
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
import unittest
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
class TestRowDict(unittest.TestCase):
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
    def setUp(self):
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
        self.rowdict = RowDict([('id', 123), ('name', 'hello')])
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    def test_rowdict_as_kwargs(self):
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        rowdict_id = (lambda **kwargs: kwargs['id']) (**self.rowdict)
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
        self.assertEqual(rowdict_id, 123)
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
    def test_rowdict_key_access(self):
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        self.assertEqual(self.rowdict['id'], 123)
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
    def test_rowdict_attr_access(self):
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
        self.assertEqual(self.rowdict.name, 'hello')
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
    def test_rowdict_index_access(self):
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        self.assertEqual(self.rowdict[0], 123)
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
    def test_rowdict_unpack(self):
81
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    26
        _id, name = self.rowdict.values()
48
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
        self.assertEqual(name, 'hello')
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
81
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    29
    def test_rowdict_repr(self):
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    30
        repr_text = "RowDict([('id', 123), ('name', 'hello')])"
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    31
        self.assertEqual(repr(self.rowdict), repr_text)
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    32
        self.assertEqual(str(self.rowdict), repr_text)
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    33
48
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
if __name__ == '__main__':
b82c7c2fb5af PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
    unittest.main()
81
f709b1c7ca0c PgManager: Update RowDict, add write support.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
    37