예제 #1
0
    def test_get_password(self):
        """Unit tests for method get_password."""

        # Authenticate user
        authorization = get_authorization()

        # Get password for Cloudera Hive data source
        data_source = DataSource()
        password = data_source.get_password(authorization, 1)

        # Assert query result
        self.assertEqual(password, 'cloudera')
예제 #2
0
    def test_get_connection_sqlite(self):
        """Unit tests for method get_connection for SQLite database."""

        # Set connection parameters
        data_source_type_id = DataSourceType.SQLITE_ID
        connection_string = './star_wars.db'

        # Connect to test Database
        data_source = DataSource()
        connection = data_source.get_connection(data_source_type_id,
                                                connection_string)
        cursor = connection.cursor()
        result = cursor.execute(
            "SELECT name FROM planet WHERE name='Tatooine';").fetchone()
        result = result[0]
        cursor.close()
        connection.close()

        # Assert query result
        self.assertEqual(result, 'Tatooine')
예제 #3
0
    def test_get_connection_postgresql(self):
        """Unit tests for method get_connection for PostgreSQL database."""

        # Set connection parameters
        data_source_type_id = DataSourceType.POSTGRESQL_ID
        connection_string = 'driver={PostgreSQL Unicode};server=db-postgresql;port=5432;Database=star_wars;'
        login = '******'
        password = '******'

        # Connect to test Database
        data_source = DataSource()
        connection = data_source.get_connection(data_source_type_id,
                                                connection_string, login,
                                                password)
        cursor = connection.cursor()
        result = cursor.execute(
            "SELECT name FROM public.planet WHERE name='Tatooine';").fetchone(
            )
        result = result[0]
        cursor.close()
        connection.close()

        # Assert query result
        self.assertEqual(result, 'Tatooine')
예제 #4
0
    def test_get_connection_hive(self):
        """Unit tests for method get_connection for Hive database."""

        # Set connection parameters
        data_source_type_id = DataSourceType.HIVE_ID
        connection_string = 'driver=Cloudera Hive;Host=db-hive;Port=10000;'
        login = '******'
        password = '******'

        # Connect to test Database
        data_source = DataSource()
        connection = data_source.get_connection(data_source_type_id,
                                                connection_string, login,
                                                password)
        cursor = connection.cursor()
        result = cursor.execute(
            "SELECT name FROM star_wars.planet WHERE name='Tatooine'"
        ).fetchone()
        result = result[0]
        cursor.close()
        connection.close()

        # Assert query result
        self.assertEqual(result, 'Tatooine')
예제 #5
0
    def test_get_connection_mariadb(self):
        """Unit tests for method get_connection for MariaDB database."""

        # Set connection parameters
        data_source_type_id = DataSourceType.MARIADB_ID
        connection_string = 'driver={MariaDB Unicode};server=db-mariadb;port=3306;Database=star_wars;'
        login = '******'
        password = '******'

        # Connect to test Database
        data_source = DataSource()
        connection = data_source.get_connection(data_source_type_id,
                                                connection_string, login,
                                                password)
        cursor = connection.cursor()
        result = cursor.execute(
            "SELECT name FROM star_wars.planet WHERE name='Tatooine';"
        ).fetchone()
        result = result[0]
        cursor.close()
        connection.close()

        # Assert query result
        self.assertEqual(result, 'Tatooine')
예제 #6
0
    def test_get_connection_sql_server(self):
        """Unit tests for method get_connection for Microsoft SQL Server database."""

        # Set connection parameters
        data_source_type_id = DataSourceType.MSSQL_ID
        connection_string = 'driver={FreeTDS};server=db-sql-server;port=1433;Database=star_wars;tds_version=8.0;'
        login = '******'
        password = '******'

        # Connect to test Database
        data_source = DataSource()
        connection = data_source.get_connection(data_source_type_id,
                                                connection_string, login,
                                                password)
        cursor = connection.cursor()
        result = cursor.execute(
            "SELECT name FROM star_wars.dbo.planet WHERE name='Tatooine';"
        ).fetchone()
        result = result[0]
        cursor.close()
        connection.close()

        # Assert query result
        self.assertEqual(result, 'Tatooine')