Exemple #1
0
def init_test_env():
    """
    This method prepares all necessary data for tests execution
    """
    # Set a default test profile, for when running tests from dev-env.
    from tvb.basic.profile import TvbProfile
    if TvbProfile.CURRENT_PROFILE_NAME is None:
        profile = TvbProfile.TEST_SQLITE_PROFILE
        if len(sys.argv) > 1:
            for i in range(1, len(sys.argv) - 1):
                if "--profile=" in sys.argv[i]:
                    profile = sys.argv[i].split("=")[1]
        TvbProfile.set_profile(profile)
        print("Not expected to happen except from PyCharm: setting profile",
              TvbProfile.CURRENT_PROFILE_NAME)
        db_file = TvbProfile.current.db.DB_URL.replace('sqlite:///', '')
        if os.path.exists(db_file):
            os.remove(db_file)

    from tvb.config.init.model_manager import reset_database
    from tvb.config.init.initializer import initialize

    reset_database()
    initialize(skip_import=True)

    # Add Dummy DataType
    REGISTRY.register_datatype(DummyDataType, DummyDataTypeH5,
                               DummyDataTypeIndex)
    REGISTRY.register_datatype(None, None, DummyDataType2Index)
    def test_initialize_startup(self):
        """
        Test "reset_database" and "initialize_startup" calls.
        """
        reset_database()
        # Table USERS should not exist:
        with pytest.raises(Exception):
            dao.get_all_users()

        initialize_startup()
        # Table exists, but no rows
        assert 0 == len(dao.get_all_users())
        assert None == dao.get_system_user()
        # DB revisions folder should exist:
        assert os.path.exists(TvbProfile.current.db.DB_VERSIONING_REPO)
Exemple #3
0
def reset():
    """
    Service Layer for Database reset.
    """
    reset_database()