Esempio n. 1
0
 def testAdd(self):
     jail_types = JailTypes()
     before_count = len(jail_types.all())
     self.assertTrue(jail_types.add(jail_types.new(), persist=False))
     after_count = len(jail_types.all())
     self.assertGreater(after_count, before_count)
     self.assertEqual(before_count + 1, after_count)
Esempio n. 2
0
    def testInit(self):
        jail_types = JailTypes()
        self.assertIsInstance(jail_types, ModelCollection)
        self.assertGreater(jail_types._items, 0)
        self.assertIsInstance(jail_types.all(), list)

        for i in jail_types.all():
            self.assertIsInstance(i, JailType)
Esempio n. 3
0
    def test_InsertQuery(self):
        jail_types = JailTypes()
        entity = jail_types.new()

        expected = OrderedDict([('id', None), ('ip', None), ('netmask', None)])
        data = jail_types._generate_query_data(entity)
        self.assertEqual(expected, data)

        expected = 'INSERT INTO jail_types(id,ip,netmask) VALUES (?,?,?)'
        self.assertEqual(jail_types._generate_insert_query(data), expected)
Esempio n. 4
0
    def testFirst(self):
        jail_types = JailTypes()
        self.assertIsNone(jail_types.first())

        jail_types.add(jail_types.new(), persist=False)
        first = jail_types._items[0]
        self.assertEqual(jail_types.first(), first)
Esempio n. 5
0
    def testDelete(self):
        jail_types = JailTypes()
        entity = jail_types.new()

        expected = 'DELETE FROM jail_types WHERE id = ?'
        self.assertEqual(jail_types._generate_delete_query(entity.id), expected)
Esempio n. 6
0
 def testTableDefinition(self):
     jail_types = JailTypes()
     expected = 'CREATE TABLE jail_types (id TEXT PRIMARY KEY,ip TEXT,netmask TEXT)'
     self.assertEqual(str(jail_types.table_definition()), expected)
Esempio n. 7
0
 def test_GenerateSelectQuery(self):
     jail_types = JailTypes()
     expected = 'SELECT * FROM jail_types'
     self.assertEqual(jail_types._generate_select_query(), expected)
Esempio n. 8
0
    def testNew(self):
        jail_types = JailTypes()
        self.assertIsInstance(jail_types.new(), JailType)

        e = jail_types.new(id="lol")
        self.assertEqual(e.id, 'lol')