Ejemplo n.º 1
0
    def test_cluster_databases(self):
        """Method `cluster_databases` returns a list of the databases"""
        db = database.Database()
        cluster_dbs = db.cluster_databases()
        expected = ['foo', 'bar']

        self.assertEqual(cluster_dbs, expected)
Ejemplo n.º 2
0
    def test_isolation_level_getter(self):
        """Property Database.isolation_level returns connection's isolation level"""
        self.mocked_connection.isolation_level = 1
        db = database.Database()
        isolation_level = db.isolation_level

        self.assertTrue(isolation_level is 1)
Ejemplo n.º 3
0
    def test_tables(self):
        """Method `tables` returns a list of tables in the databases"""
        db = database.Database()
        tables = db.tables()
        expected = ['foo', 'bar']

        self.assertEqual(tables, expected)
Ejemplo n.º 4
0
    def test_table_schema(self):
        """Method `table_schema` returns a tuple of database.Column objects"""
        db = database.Database()
        schema = db.table_schema(table='sometable')
        expected = (database.Column('foo', 'string'),
                    database.Column('bar', 'string'))

        self.assertEqual(schema, expected)
Ejemplo n.º 5
0
    def test_primary_key(self):
        """Method `primary_key` returns a tuple of database.Column objects"""
        db = database.Database()
        primary_key = db.primary_key(table='sometable')
        expected = (database.Column('foo', 'string'),
                    database.Column('bar', 'string'))

        self.assertEqual(primary_key, expected)
Ejemplo n.º 6
0
    def test_isolation_level_setter(self):
        """Property Database.isolation_level can set value"""
        db = database.Database()
        db.isolation_level = 7

        args, _ = self.mocked_connection.set_isolation_level.call_args
        sent_level = args[0]
        expected = 7

        self.assertEqual(sent_level, expected)
Ejemplo n.º 7
0
 def test_executemany(self):
     """Happy path test for the Database.executemany method"""
     db = database.Database()
     result = db.executemany(sql="SELECT * from FOO WHERE bar = %s",
                             params=('bat', ))
     self.assertTrue(isinstance(result, types.GeneratorType))
Ejemplo n.º 8
0
 def test_close(self):
     """Calling Database.close() closes the connection to the DB"""
     db = database.Database()
     db.close()
     self.assertTrue(self.mocked_connection.close.call_count is 1)
Ejemplo n.º 9
0
 def test_context_manager(self):
     """Database support use of `with` statement and auto-closes connection"""
     with database.Database() as db:
         pass
     self.assertTrue(self.mocked_connection.close.call_count is 1)
Ejemplo n.º 10
0
 def test_init(self):
     """Simple test that we can instantiate Database class for testing"""
     db = database.Database()
     self.assertTrue(isinstance(db, database.Database))
     self.assertTrue(db._connection is self.mocked_connection)
     self.assertTrue(db._cursor is self.mocked_cursor)