Пример #1
0
 def test_GenerateSelectQuery(self):
     mc = ModelCollection()
     mc._table_name = 'test'
     mc._table_definition = TableDefinition('test', {'id': 'TEXT', 'name': 'TEXT'})
     query = mc._generate_select_query()
     expected = 'SELECT * FROM test'
     self.assertEqual(query, expected)
Пример #2
0
    def test_GenerateQueryData(self):
        mc = ModelCollection()
        mc._table_name = 'test'
        mc._table_definition = TableDefinition('test', {'id': 'TEXT', 'name': 'TEXT'})

        entity = MockModel(id='test')
        expected = OrderedDict()
        expected['id'] = 'test'
        data = mc._generate_query_data(entity)
        self.assertEqual(data, expected)

        entity = MockModel(id='test', bad_column='trololol')
        expected = OrderedDict()
        expected['id'] = 'test'
        data = mc._generate_query_data(entity)
        self.assertEqual(data, expected)

        entity = MockModel(id='test', bad_column='trololol', name='ello')
        expected = OrderedDict()
        expected['id'] = 'test'
        expected['name'] = 'ello'
        data = mc._generate_query_data(entity)
        self.assertEqual(data, expected)

        # Whitelist test
        entity = MockModel(id='test', bad_column='trololol', name='ello')
        expected = OrderedDict()
        expected['name'] = 'ello'
        data = mc._generate_query_data(entity, ['name'])
        self.assertEqual(data, expected)
Пример #3
0
    def test_GenerateDeleteQuery(self):
        mc = ModelCollection()
        mc._table_name = 'test'
        mc._table_definition = TableDefinition('test', {'id': 'TEXT', 'name': 'TEXT'})

        query = mc._generate_delete_query(['lol'])
        expected = 'DELETE FROM test WHERE id = ?'
        self.assertEqual(query, expected)
Пример #4
0
 def test_GenerateInsertQuery(self):
     mc = ModelCollection()
     mc._table_name = 'test'
     mc._table_definition = TableDefinition('test', {'id': 'TEXT', 'name': 'TEXT'})
     insert_data = {'id': 'derp', 'name': 'ello'}
     query = mc._generate_insert_query(insert_data)
     expected = 'INSERT INTO test(id,name) VALUES (?,?)'
     self.assertEqual(query, expected)
Пример #5
0
    def test_GenerateUpdateQuery(self):
        mc = ModelCollection()
        mc._table_name = 'test'
        mc._table_definition = TableDefinition('test', {'id': 'TEXT', 'name': 'TEXT'})

        update_data = {'id': 'lol', 'name': 'ello'}
        query = mc._generate_update_query(['lol'], update_data)
        expected = 'UPDATE test SET name = ? WHERE id IN (?)'
        self.assertEqual(query, expected)

        query = mc._generate_update_query(['lol', 'ello', 'derp'], update_data)
        expected = 'UPDATE test SET name = ? WHERE id IN (?,?,?)'
        self.assertEqual(query, expected)

        update_data = {'id': 'lol', 'name': 'ello', 'desc': 'Nope'}
        query = mc._generate_update_query(['lol'], update_data)
        expected = 'UPDATE test SET desc = ?,name = ? WHERE id IN (?)'
        self.assertEqual(query, expected)