def _drop_all_ddl_packages(conn):
    pkgs = _get_sql_package_table(conn)
    for pkg in pkgs:
        try:
            SQLPackageManager(conn)._drop_sql_package(pkg['name'], scope=Scope.private_scope())
        except Exception:
            pass
예제 #2
0
def test_scope():

    _remove_all_new_packages(pkgmanager)

    package = os.path.join(path_to_packages, "testpackageA-0.0.1.zip")

    def get_location():
        import testpackageA
        return testpackageA.__file__

    _revotesterconnection = sqlmlutils.ConnectionInfo(server="localhost",
                                                      database="AirlineTestDB",
                                                      uid="Tester",
                                                      pwd="FakeT3sterPwd!")
    revopkgmanager = SQLPackageManager(_revotesterconnection)
    revoexecutor = SQLPythonExecutor(_revotesterconnection)

    revopkgmanager.install(package, scope=Scope.private_scope())
    private_location = revoexecutor.execute_function_in_sql(get_location)

    pkg_name = "testpackageA"

    pyexecutor.execute_function_in_sql(check_package,
                                       package_name=pkg_name,
                                       exists=False)

    revopkgmanager.uninstall(pkg_name, scope=Scope.private_scope())

    revopkgmanager.install(package, scope=Scope.public_scope())
    public_location = revoexecutor.execute_function_in_sql(get_location)

    assert private_location != public_location
    pyexecutor.execute_function_in_sql(check_package,
                                       package_name=pkg_name,
                                       exists=True,
                                       class_to_check='ClassA')

    revopkgmanager.uninstall(pkg_name, scope=Scope.public_scope())

    revoexecutor.execute_function_in_sql(check_package,
                                         package_name=pkg_name,
                                         exists=False)
    pyexecutor.execute_function_in_sql(check_package,
                                       package_name=pkg_name,
                                       exists=False)
예제 #3
0
def _drop_all_ddl_packages(conn, scope):
    pkgs = _get_sql_package_table(conn)
    if (len(pkgs.index) > 0):
        for pkg in pkgs['name']:
            if pkg not in initial_list:
                try:
                    SQLPackageManager(conn)._drop_sql_package(pkg, scope=scope)
                except Exception as e:
                    pass
def test_scope():
    """Test installing in a private scope with a db_owner (not dbo) user"""
    _remove_all_new_packages(pkgmanager)

    package = os.path.join(path_to_packages, "testpackageA-0.0.1.zip")

    def get_location():
        import testpackageA
        return testpackageA.__file__

    # The airline_user_connection is NOT dbo, so it has access to both Private and Public scopes
    # 
    revopkgmanager = SQLPackageManager(airline_user_connection)
    revoexecutor = SQLPythonExecutor(airline_user_connection)

    # Install a package into the private scope
    #
    revopkgmanager.install(package, scope=Scope.private_scope())
    private_location = revoexecutor.execute_function_in_sql(get_location)

    pkg_name = "testpackageA"

    pyexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=False)

    revopkgmanager.uninstall(pkg_name, scope=Scope.private_scope())

    # Try the same installation in public scope
    #
    revopkgmanager.install(package, scope=Scope.public_scope())
    public_location = revoexecutor.execute_function_in_sql(get_location)

    assert private_location != public_location
    pyexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=True, class_to_check='ClassA')

    revopkgmanager.uninstall(pkg_name, scope=Scope.public_scope())

    # Make sure the package was removed properly
    #
    revoexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=False)
    pyexecutor.execute_function_in_sql(check_package, package_name=pkg_name, exists=False)
from conftest import connection


def _drop_all_ddl_packages(conn):
    pkgs = _get_sql_package_table(conn)
    for pkg in pkgs:
        try:
            SQLPackageManager(conn)._drop_sql_package(
                pkg['name'], scope=Scope.private_scope())
        except Exception:
            pass


pyexecutor = SQLPythonExecutor(connection)
pkgmanager = SQLPackageManager(connection)
_drop_all_ddl_packages(connection)


def _package_exists(module_name: str):
    mod = __import__(module_name)
    return mod is not None


def _package_no_exist(module_name: str):
    import pytest
    with pytest.raises(Exception):
        __import__(module_name)
    return True