示例#1
0
        def it_should_create_the_requested_adapter() -> None:
            a = MainArguments("some/path", DbEngine.MSSQL, LOG_LEVELS[0],
                              "server", "database", 0)
            a.build_mssql_adapter_with_integrated_security()
            actual = a.get_db_operations_adapter()

            assert type(actual) is SqlLmsOperations
        def it_should_create_the_requested_adapter() -> None:
            a = MainArguments("some/path", DbEngine.MSSQL, LOG_LEVELS[0])
            a.set_connection_string("server", None, "database", "username",
                                    "password")
            actual = a.get_db_operations_adapter()

            assert type(actual) is MssqlLmsOperations
示例#3
0
def main_arguments(adapter: MssqlLmsOperations,
                   csv_path: str) -> MainArguments:
    args = MainArguments(csv_path=csv_path, engine="mssql", log_level="INFO")
    args.set_connection_string_using_integrated_security(
        "localhost", 1433, "test_integration_lms_toolkit")
    # monkey patch the test adapter
    args.get_db_operations_adapter = lambda: adapter  # type: ignore
    return args
                def it_should_use_default_value_of_1433() -> None:
                    expected = "mssql+pyodbc://me:yo@my-server,1433/my-database?driver=ODBC+Driver+17+for+SQL+Server"

                    server = "my-server"
                    database = "my-database"
                    port = None
                    username = "******"
                    password = "******"

                    a = MainArguments("some/path", DbEngine.MSSQL,
                                      LOG_LEVELS[0])
                    a.set_connection_string(server, port, database, username,
                                            password)

                    assert a.connection_string == expected
                def it_should_return_a_pyodbc_connection_string_with_trusted_connection(
                ) -> None:
                    server = "my-server"
                    database = "my-database"
                    port = 1234
                    username = "******"
                    password = "******"
                    expected = "mssql+pyodbc://me:yo@my-server,1234/my-database?driver=ODBC+Driver+17+for+SQL+Server"

                    a = MainArguments("some/path", DbEngine.MSSQL,
                                      LOG_LEVELS[0])
                    a.set_connection_string(server, port, database, username,
                                            password)

                    assert a.connection_string == expected
                def it_should_use_default_value_of_1433() -> None:
                    server = "my-server"
                    database = "my-database"
                    port = None
                    expected = "mssql+pyodbc://my-server,1433/my-database?driver=ODBC+Driver+17+for+SQL+Server?Trusted_Connection=yes"

                    a = MainArguments("some/path", DbEngine.MSSQL,
                                      LOG_LEVELS[0])
                    a.set_connection_string_using_integrated_security(
                        server,
                        port,
                        database,
                    )

                    assert a.connection_string == expected
示例#7
0
    def it_passes_initializer_arguments_into_instance_properties() -> None:
        csv_path = "some/path"
        engine = DbEngine.MSSQL
        logging = LOG_LEVELS[0]
        db_name = "whatever"
        server = "somwehere"
        port = 2343
        encrypt = True
        trust_certificate = True

        a = MainArguments(
            csv_path,
            engine,
            logging,
            server,
            db_name,
            port,
            encrypt,
            trust_certificate,
        )

        assert a.csv_path == csv_path
        assert a.engine == engine
        assert a.log_level == logging
        assert a.server == server
        assert a.port == port
        assert a.engine == engine
        assert a.encrypt == encrypt
        assert a.trust_certificate == trust_certificate
        assert a.db_name == db_name
示例#8
0
def main_arguments(adapter: SqlLmsOperations, csv_path: str) -> MainArguments:
    args = MainArguments(
        csv_path,
        "mssql",
        "INFO",
        "localhost",
        "test_integration_lms_toolkit",
        1433,
        False,
        False,
    )
    args.build_mssql_adapter_with_integrated_security()

    # monkey patch the test adapter
    args.get_db_operations_adapter = lambda: adapter  # type: ignore
    return args
                def it_should_return_a_pyodbc_connection_string_with_trusted_connection(
                ) -> None:
                    server = "my-server"
                    database = "my-database"
                    port = 1234
                    expect = "mssql+pyodbc://my-server,1234/my-database?driver=ODBC+Driver+17+for+SQL+Server?Trusted_Connection=yes"

                    a = MainArguments("some/path", DbEngine.MSSQL,
                                      LOG_LEVELS[0])
                    a.set_connection_string_using_integrated_security(
                        server,
                        port,
                        database,
                    )

                    assert a.connection_string == expect
def main_arguments(
    operations_adapter: SqlLmsOperations, csv_path: str, settings: ConnectionSettings
) -> MainArguments:
    args = MainArguments(
        csv_path,
        "postgresql",
        "INFO",
        settings.host,
        settings.db,
        settings.port,
        False,
        False,
    )
    args.db_adapter = operations_adapter.db_adapter

    # monkey patch the test adapter
    args.get_db_operations_adapter = lambda: operations_adapter  # type: ignore
    return args
示例#11
0
        def it_should_raise_NotImplementedError() -> None:
            with pytest.raises(NotImplementedError):
                a = MainArguments("some/path", DbEngine.MSSQL, LOG_LEVELS[0],
                                  "server", "database", 0)

                a.engine = "PostgreSQL"
                a.build_mssql_adapter_with_integrated_security()
                a.get_db_operations_adapter()
示例#12
0
        def it_should_raise_NotImplementedError() -> None:
            with pytest.raises(NotImplementedError):
                a = MainArguments("some/path", DbEngine.MSSQL, LOG_LEVELS[0])
                a.set_connection_string("server", None, "database", "username",
                                        "password")

                a.engine = "PostgreSQL"
                a.get_db_operations_adapter()
示例#13
0
    def it_passes_initializer_arguments_into_instance_properties() -> None:
        csv_path = "some/path"
        engine = DbEngine.MSSQL
        logging = LOG_LEVELS[0]

        a = MainArguments(csv_path, engine, logging)

        assert a.csv_path == csv_path
        assert a.engine == engine
        assert a.log_level == logging
示例#14
0
def run_loader(arguments: MainArguments) -> None:
    logger.info("Begin loading files into the LMS Data Store (DS)...")

    migrator.migrate(arguments.get_db_engine())

    csv_path = arguments.csv_path

    db_adapter = arguments.get_db_operations_adapter()

    _load_users(csv_path, db_adapter)
    _load_sections(csv_path, db_adapter)
    # Important: run this immediately after loading sections, before loading other section-related resources
    _load_section_associations(csv_path, db_adapter)
    _load_assignments(csv_path, db_adapter)
    _load_assignment_submissions(csv_path, db_adapter)
    _load_attendance_events(csv_path, db_adapter)
    _load_section_activities(csv_path, db_adapter)
    _load_system_activities(csv_path, db_adapter)

    logger.info("Done loading files into the LMS Data Store.")
示例#15
0
 def it_should_set_password_in_the_connection_string(
     fixture: MainArguments, ) -> None:
     # Test the details of the connection string in a more appropriate test
     # suite - test only enough here to prove the point
     assert PASSWORD in str(fixture.get_adapter().engine.url)
示例#16
0
 def describe_given_invalid_engine() -> None:
     with pytest.raises(ValueError):
         MainArguments(
             "bogus", "bogus",
             LOG_LEVELS[0]).set_connection_string_using_integrated_security(
                 "server", 20, "db_name")