Пример #1
0
    def test_it_should_accept_a_schema_version_option_if_current_version_is_a_file(self, cli_mock, _execution_log_mock, simplevirtuosomigrate_mock, virtuoso_mock, execute_migrations_mock):
        self.initial_config.update({"schema_version":"version", "file_migration":None})
        main = Main(Config(self.initial_config))
        main.execute()

        expected_calls = [
            call('\nStarting Virtuoso migration...', 'PINK', log_level_limit=1),
            call('\nDone.\n', 'PINK', log_level_limit=1)
        ]
        self.assertEqual(expected_calls, _execution_log_mock.mock_calls)
        execute_migrations_mock.assert_called_with('sparql_up', 'sparql_down', 'current_file', 'version')
Пример #2
0
    def test_it_should_migrate_db_if_create_migration_option_is_not_activated_by_user(self, migrate_mock, _execution_log_mock):
        config = Config(self.initial_config)
        main = Main(config)
        main.execute()

        expected_calls = [
            call('\nStarting Virtuoso migration...', 'PINK', log_level_limit=1),
            call('\nDone.\n', 'PINK', log_level_limit=1)
        ]
        self.assertEqual(expected_calls, _execution_log_mock.mock_calls)
        self.assertEqual(1, migrate_mock.call_count)
Пример #3
0
    def test_it_should_not_accept_file_migration_option_if_current_version_is_already_a_file(self, cli_mock, _execution_log_mock, virtuoso_mock, execute_migrations_mock):
        self.initial_config.update({"file_migration":"migration"})
        main = Main(Config(self.initial_config))
        try:
            main.execute()
        except SystemExit:
            pass

        expected_calls = [
            call('\nStarting Virtuoso migration...', 'PINK', log_level_limit=1),
            call('- Current version is: current_file', 'GREEN', log_level_limit=1),
            call('- Destination version is: migration', 'GREEN', log_level_limit=1)
        ]
        self.assertEqual(expected_calls, _execution_log_mock.mock_calls)
        cli_mock.assert_called_with("[ERROR] Can't execute migration FROM File TO File (TIP: version it using git --tag and then use -m)\n", 'RED')
        self.assertEqual(0, execute_migrations_mock.call_count)
Пример #4
0
    def test_it_should_add_triples_if_the_database_is_not_empty_and_the_option_is_activated_by_the_user(self, run_isql_mock, current_version_mock, execute_change_mock, _execution_log_mock):
        self.initial_config.update({'load_ttl':'new_triple.ttl', 'show_sparql_only':None})
        main = Main(Config(self.initial_config))
        main.execute()

        expected_calls = [
            call('\nStarting Virtuoso migration...', 'PINK', log_level_limit=1),
            call("- TTL(s) to upload: ['new_triple.ttl']", 'GREEN', log_level_limit=1),
            call('- Current version is: 0.1', 'GREEN', log_level_limit=1),
            call('- Destination version is: 0.1', 'GREEN', log_level_limit=1),
            call('\nStarting Migration!', log_level_limit=1),
            call('===== executing =====', log_level_limit=1),
            call('', log_level_limit=1),
            call('\nDone.\n', 'PINK', log_level_limit=1)
        ]
        self.assertEqual(expected_calls, _execution_log_mock.mock_calls)
    def test_it_should_add_triples_if_the_database_is_not_empty_and_the_option_is_activated_by_the_user(self, current_version_mock, statements_mock, execute_change_mock, _execution_log_mock):
        self.initial_config.update({'add_ttl':'new_triples', 'show_sparql_only':None})
        main = Main(Config(self.initial_config))
        main.execute()

        expected_calls = [
            call('\nStarting Virtuoso migration...', 'PINK', log_level_limit=1),
            call('- TTL to insert is: new_triples', 'GREEN', log_level_limit=1),
            call('- Current version is: 0.1', 'GREEN', log_level_limit=1),
            call('- Destination version is: new_triples', 'GREEN', log_level_limit=1),
            call('\nStarting Migration!', log_level_limit=1),
            call('===== executing =====', log_level_limit=1),
            call('\nDone.\n', 'PINK', log_level_limit=1)
        ]
        self.assertEqual(expected_calls, _execution_log_mock.mock_calls)
        statements_mock.assert_called_with('new_triples', '0.1', 'git')
        execute_change_mock.assert_called_with('sparql_up', 'sparql_down', execution_log=_execution_log_mock)
Пример #6
0
    def test_it_should_not_add_triples_if_show_sparql_only_option_is_activated_by_the_user(self, current_version_mock, execute_change_mock, _execution_log_mock):
        self.initial_config.update({'load_ttl':'new_triple.ttl', 'show_sparql_only':True})
        main = Main(Config(self.initial_config))
        main.execute()

        expected_calls = [
            call('\nStarting Virtuoso migration...', 'PINK', log_level_limit=1),
            call("- TTL(s) to upload: ['new_triple.ttl']", 'GREEN', log_level_limit=1),
#            call('- Current version is: 0.1', 'GREEN', log_level_limit=1),
#            call('- Destination version is: 0.1', 'GREEN', log_level_limit=1),
#            call("\nWARNING: commands are not being executed ('--show_sparql_only' activated)", 'RED', log_level_limit=1),
#            call('__________ SPARQL statements executed __________', 'YELLOW', log_level_limit=1),
#            call('sparql_up', 'YELLOW', log_level_limit=1),
#            call('_____________________________________________', 'YELLOW', log_level_limit=1),
            call('\nDone.\n', 'PINK', log_level_limit=1)
        ]
        self.assertEqual(expected_calls, _execution_log_mock.mock_calls)
        self.assertEqual(0, execute_change_mock.call_count)
Пример #7
0
 def test_it_should_get_current_and_destination_versions_and_execute_migrations(self, virtuoso_mock, _get_destination_version_mock, execute_migrations_mock):
     main = Main(Config(self.initial_config))
     main.execute()
     execute_migrations_mock.assert_called_with('sparql_up', 'sparql_down', 'current_version', 'destination_version')
Пример #8
0
 def test_should_exec_and_fail_with_invalid_after_script(self, load_triples_mock, execution_log_mock):
     self.initial_config.update({'load_ttl':'', 'run_after': 'tests/samples/invalid_run_after.py'})
     main = Main(Config(self.initial_config))
     main.execute()
     execution_log_mock.mock_calls[-2].called_with('\nRun after script tests/samples/invalid_run_after.py does not have run_after() function .\n', 'PINK', 1)
Пример #9
0
 def test_should_exec_and_call_run_after_script(self, valid_version_mock, load_triples_mock, execution_log_mock):
     self.initial_config.update({'load_ttl':'', 'run_after': 'tests/samples/validate_run_after.py'})
     main = Main(Config(self.initial_config))
     main.execute()
     self.assertEqual(valid_version_mock.call_count, 2)
Пример #10
0
 def test_it_should_call_run_after_method_after_calling_execute(self, load_triples_mock, run_after_mock, execution_log_mock):
     self.initial_config.update({'load_ttl':'', 'run_after': 'some_script_name'})
     main = Main(Config(self.initial_config))
     main.execute()
     self.assertEqual(execution_log_mock.call_count, 3)
     run_after_mock.assert_called_with('some_script_name', None)