def test_it_should_delete_the_temporary_file_with_sparql_down_when_executing_change(self, run_isql_mock, write_temporary_file_mock): create_file('filename_down.ttl', 'content') run_isql_mock.side_effect = command_call_side_effect write_temporary_file_mock.side_effect = temp_file_side_effect virtuoso = Virtuoso(self.config) self.assertRaisesWithMessage(MigrationException, '\nerror executing migration statement: err\n\nRollback done successfully!!!', virtuoso.execute_change, "sparql_up", "sparql_down") self.assertFalse(os.path.exists('filename_down.ttl'))
def test_it_should_get_sql_command_containing_unicode_characters(self): file_name = '20090508155742_test_migration.migration' create_file( file_name, content='SQL_UP=u"some sql command"\nSQL_DOWN=u"other sql command"' ) migration = Migration(file_name) self.assertEqual(u"some sql command", migration.sql_up) self.assertEqual(u"other sql command", migration.sql_down)
def test_it_should_get_sql_command_containing_non_ascii_characters(self): file_name = '20090508155742_test_migration.migration' create_file( file_name, content= 'SQL_UP=u"some sql command ç"\nSQL_DOWN=u"other sql command ã"', encoding='utf-8') migration = Migration(file_name) self.assertEqual(u"some sql command ç", migration.sql_up) self.assertEqual(u"other sql command ã", migration.sql_down)
def test_it_should_get_sql_command_containing_non_ascii_characters_with_non_utf8_encoding( self): file_name = '20090508155742_test_migration.migration' create_file( file_name, content= 'SQL_UP=u"some sql command ç"\nSQL_DOWN=u"other sql command ã"'. decode('iso8859-1'), encoding='iso8859-1') migration = Migration(file_name, script_encoding='iso8859-1') self.assertEqual(u"some sql command \xc3\xa7", migration.sql_up) self.assertEqual(u"other sql command \xc3\xa3", migration.sql_down)
def test_it_should_get_sql_command_containing_non_ascii_characters_and_python_code_without_scope( self): file_name = '20090508155742_test_migration.migration' create_file( file_name, content= 'SQL_UP=u"some sql command ç %s" % os.path.abspath(\'.\')\nSQL_DOWN=u"other sql command ã %s" % os.path.abspath(\'.\')', encoding='utf-8') migration = Migration(file_name) self.assertEqual(u"some sql command ç %s" % os.path.abspath('.'), migration.sql_up) self.assertEqual(u"other sql command ã %s" % os.path.abspath('.'), migration.sql_down)
def test_it_should_get_sql_command_containing_unicode_characters_and_python_code( self): file_name = '20090508155742_test_migration.migration' create_file( file_name, content= 'import os\nSQL_UP=u"some sql command %s" % os.path.abspath(\'.\')\nSQL_DOWN=u"other sql command %s" % os.path.abspath(\'.\')' ) migration = Migration(file_name) self.assertEqual(u"some sql command %s" % os.path.abspath('.'), migration.sql_up) self.assertEqual(u"other sql command %s" % os.path.abspath('.'), migration.sql_down)
def setUp(self): config_file = ''' DATABASE_HOST = 'localhost' DATABASE_USER = '******' DATABASE_PASSWORD = '' DATABASE_NAME = 'migration_example' ENV1_DATABASE_NAME = 'migration_example_env1' DATABASE_MIGRATIONS_DIR = 'example' UTC_TIMESTAMP = True DATABASE_ANY_CUSTOM_VARIABLE = 'Some Value' SOME_ENV_DATABASE_ANY_CUSTOM_VARIABLE = 'Other Value' DATABASE_OTHER_CUSTOM_VARIABLE = 'Value' ''' create_file('sample.conf', config_file) create_file('sample.py', "import os\n%s" % config_file)
def test_it_should_get_sql_command_containing_non_ascii_characters_and_python_code_with_non_utf8_encoding( self): file_name = '20090508155742_test_migration.migration' create_file( file_name, content= 'import os\nSQL_UP=u"some sql command ç %s" % os.path.abspath(\'.\')\nSQL_DOWN=u"other sql command ã %s" % os.path.abspath(\'.\')' .decode('iso8859-1'), encoding='iso8859-1') migration = Migration(file_name, script_encoding='iso8859-1') self.assertEqual( u"some sql command \xc3\xa7 %s" % os.path.abspath('.'), migration.sql_up) self.assertEqual( u"other sql command \xc3\xa3 %s" % os.path.abspath('.'), migration.sql_down)
def setUp(self): config_file = ''' DATABASE_HOST = 'localhost' DATABASE_USER = '******' DATABASE_PASSWORD = '' DATABASE_PORT = 'port' DATABASE_ENDPOINT = 'migration_example' DATABASE_GRAPH = 'graph' DATABASE_ONTOLOGY = 'ontology' ENV1_DATABASE_ENDPOINT = 'migration_example_env1' DATABASE_MIGRATIONS_DIR = 'example' DATABASE_ANY_CUSTOM_VARIABLE = 'Some Value' SOME_ENV_DATABASE_ANY_CUSTOM_VARIABLE = 'Other Value' DATABASE_OTHER_CUSTOM_VARIABLE = 'Value' ''' create_file('sample.conf', config_file)
def setUp(self): super(MainTest, self).setUp() self.initial_config = { 'database_host': 'localhost', 'database_port': 'port', 'database_endpoint': 'test', 'database_user': '******', 'database_password': '******', 'database_migrations_dir': '.', 'database_graph': 'graph', 'database_ontology': 'ontology.ttl', 'file_migration': None, 'show_sparql_only': None } create_file("ontology.ttl", "content")
def setUp(self): super(MainTest, self).setUp() self.initial_config = { 'database_host': 'localhost', 'database_port': 'port', 'database_endpoint': 'test', 'database_user': '******', 'database_password': '******', 'database_migrations_dir': '.', 'database_graph': 'graph', 'database_ontology': 'ontology.ttl', 'host_user': '******', 'host_password': '******', 'file_migration': None, 'migration_graph': 'http://example.com', 'show_sparql_only': None, 'virtuoso_dirs_allowed': '/tmp' } create_file("ontology.ttl", "content") create_file("new_triple.ttl")
def setUp(self): create_migration_file('20090214120600_example_file_name_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727104700_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141400_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141503_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727113900_empty_sql_up_test_migration.migration', sql_up='', sql_down='zzz') create_migration_file('20090727113900_empty_sql_down_test_migration.migration', sql_up='zzz', sql_down='') create_file('20090727114700_empty_file_test_migration.migration') create_file('20090727114700_without_sql_down_test_migration.migration', 'SQL_UP=""') create_file('20090727114700_without_sql_up_test_migration.migration', 'SQL_DOWN=""')
def setUp(self): create_migration_file('20090214120600_example_file_name_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727104700_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141400_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141503_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141505_01_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141505_02_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727113900_empty_sql_up_test_migration.migration', sql_up='', sql_down='zzz') create_migration_file('20090727113900_empty_sql_down_test_migration.migration', sql_up='zzz', sql_down='') create_file('20090727114700_empty_file_test_migration.migration') create_file('20090727114700_without_sql_down_test_migration.migration', 'SQL_UP=""') create_file('20090727114700_without_sql_up_test_migration.migration', 'SQL_DOWN=""')
def setUp(self): create_migration_file('20090214120600_example_file_name_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727104700_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141400_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141503_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141505_01_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727141505_02_test_migration.migration', sql_up='xxx', sql_down='yyy') create_migration_file('20090727113900_empty_sql_up_test_migration.migration', sql_up='', sql_down='zzz') create_migration_file('20090727113900_empty_sql_down_test_migration.migration', sql_up='zzz', sql_down='') create_file('20090727114700_empty_file_test_migration.migration') create_file('20090727114700_without_sql_down_test_migration.migration', 'SQL_UP=""') create_file('20090727114700_without_sql_up_test_migration.migration', 'SQL_DOWN=""') self.migration = Migration(label="generate_test_migration", version="20120101010100", sql_up="some_sql", sql_down="some_sql_down")
def setUp(self): config_file = ''' DATABASE_HOST = 'localhost' DATABASE_USER = '******' DATABASE_PASSWORD = '' DATABASE_NAME = 'migration_example' ENV1_DATABASE_NAME = 'migration_example_env1' UTC_TIMESTAMP = True DATABASE_ANY_CUSTOM_VARIABLE = 'Some Value' SOME_ENV_DATABASE_ANY_CUSTOM_VARIABLE = 'Other Value' DATABASE_OTHER_CUSTOM_VARIABLE = 'Value' RUN_AFTER = './some_dummy_action.py' RUN_AFTER_PARAMS = {'key': 'value'} ''' create_file('sample.conf', "%s\nDATABASE_MIGRATIONS_DIR = 'example'" % config_file) create_file('sample2.conf', "%s" % config_file) create_file('sample.py', "import os\n%s\nDATABASE_MIGRATIONS_DIR = 'example'" % config_file)
def test_it_should_get_sql_command_containing_non_ascii_characters_and_python_code_without_scope_with_non_utf8_encoding(self): file_name = '20090508155742_test_migration.migration' create_file(file_name, content='SQL_UP=u"some sql command ç %s" % os.path.abspath(\'.\')\nSQL_DOWN=u"other sql command ã %s" % os.path.abspath(\'.\')'.decode('iso8859-1'), encoding='iso8859-1') migration = Migration(file_name, script_encoding='iso8859-1') self.assertEqual(u"some sql command \xc3\xa7 %s" % os.path.abspath('.'), migration.sql_up) self.assertEqual(u"other sql command \xc3\xa3 %s" % os.path.abspath('.'), migration.sql_down)
def test_it_should_get_sql_command_containing_non_ascii_characters_with_non_utf8_encoding(self): file_name = '20090508155742_test_migration.migration' create_file(file_name, content='SQL_UP=u"some sql command ç"\nSQL_DOWN=u"other sql command ã"'.decode('iso8859-1'), encoding='iso8859-1') migration = Migration(file_name, script_encoding='iso8859-1') self.assertEqual(u"some sql command \xc3\xa7", migration.sql_up) self.assertEqual(u"other sql command \xc3\xa3", migration.sql_down)
def test_it_should_get_sql_command_containing_non_ascii_characters_and_python_code_without_scope(self): file_name = '20090508155742_test_migration.migration' create_file(file_name, content='SQL_UP=u"some sql command ç %s" % os.path.abspath(\'.\')\nSQL_DOWN=u"other sql command ã %s" % os.path.abspath(\'.\')'.decode('utf-8')) migration = Migration(file_name) self.assertEqual(u"some sql command ç %s" % os.path.abspath('.'), migration.sql_up) self.assertEqual(u"other sql command ã %s" % os.path.abspath('.'), migration.sql_down)
def test_it_should_get_sql_command_containing_non_ascii_characters(self): file_name = '20090508155742_test_migration.migration' create_file(file_name, content='SQL_UP=u"some sql command ç"\nSQL_DOWN=u"other sql command ã"'.decode('utf-8')) migration = Migration(file_name) self.assertEqual(u"some sql command ç", migration.sql_up) self.assertEqual(u"other sql command ã", migration.sql_down)
def test_it_should_get_sql_command_containing_unicode_characters_and_python_code(self): file_name = '20090508155742_test_migration.migration' create_file(file_name, content='import os\nSQL_UP=u"some sql command %s" % os.path.abspath(\'.\')\nSQL_DOWN=u"other sql command %s" % os.path.abspath(\'.\')') migration = Migration(file_name) self.assertEqual(u"some sql command %s" % os.path.abspath('.'), migration.sql_up) self.assertEqual(u"other sql command %s" % os.path.abspath('.'), migration.sql_down)
def test_it_should_get_sql_command_containing_unicode_characters(self): file_name = '20090508155742_test_migration.migration' create_file(file_name, content='SQL_UP=u"some sql command"\nSQL_DOWN=u"other sql command"') migration = Migration(file_name) self.assertEqual(u"some sql command", migration.sql_up) self.assertEqual(u"other sql command", migration.sql_down)
def test_it_should_delete_the_temporary_file_with_sparql_up_when_executing_change_raise_an_error(self, run_isql_mock, write_temporary_file_mock): create_file('filename.ttl', 'content') virtuoso = Virtuoso(self.config) self.assertRaisesWithMessage(Exception, 'some error', virtuoso.execute_change, "sparql_up", "sparql_down") self.assertFalse(os.path.exists('filename.ttl'))
def test_it_should_delete_the_temporary_file_with_sparql_up_when_executing_change(self, run_isql_mock, write_temporary_file_mock): create_file('filename.ttl', 'content') virtuoso = Virtuoso(self.config) virtuoso.execute_change("sparql_up", "sparql_down") self.assertFalse(os.path.exists('filename.ttl'))
def setUp(self): super(VirtuosoTest, self).setUp() self.config = Config() self.config.put("database_migrations_dir", ".") self.config.put("database_ontology", "test.ttl") self.config.put("database_graph", "test") self.config.put("database_host", "localhost") self.config.put("database_user", "user") self.config.put("database_password", "password") self.config.put("database_port", 9999) self.config.put("database_endpoint", "endpoint") self.config.put("host_user", "host-user") self.config.put("host_password", "host-passwd") self.config.put("virtuoso_dirs_allowed", "/tmp") self.config.put("migration_graph", "http://example.com/") create_file("test.ttl", "") self.data_ttl_content = """ @prefix : <http://example.com/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . <http://example.com/John> rdf:type <http://example.com/Person>. """ create_file("data.ttl", self.data_ttl_content) self.structure_01_ttl_content = """ @prefix : <http://example.com/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . :Actor rdf:type owl:Class . :SoapOpera rdf:type owl:Class . """ create_file("structure_01.ttl", self.structure_01_ttl_content) self.structure_02_ttl_content = """ @prefix : <http://example.com/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . :Actor rdf:type owl:Class . :SoapOpera rdf:type owl:Class . :RoleOnSoapOpera rdf:type owl:Class . :role rdf:type owl:Class ; rdfs:subClassOf [ rdf:type owl:Restriction ; owl:onProperty :play_a_role ; owl:onClass :RoleOnSoapOpera ; owl:minQualifiedCardinality "1"^^xsd:nonNegativeInteger ; owl:maxQualifiedCardinality "1"^^xsd:nonNegativeInteger ] . """ create_file("structure_02.ttl", self.structure_02_ttl_content) self.structure_03_ttl_content = """ @prefix : <http://example.com/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . :Actor rdf:type owl:Class . :SoapOpera rdf:type owl:Class . :RoleOnSoapOpera rdf:type owl:Class . :role rdf:type owl:Class ; rdfs:subClassOf [ rdf:type owl:Restriction ; owl:onProperty :play_a_role ; owl:onClass :RoleOnSoapOpera ; owl:minQualifiedCardinality "1111"^^xsd:nonNegativeInteger ] , [ rdf:type owl:Restriction ; owl:onProperty :play_a_role ; owl:onClass :RoleOnSoapOpera ; owl:maxQualifiedCardinality "3333"^^xsd:nonNegativeInteger ] . """ create_file("structure_03.ttl", self.structure_03_ttl_content) self.structure_04_ttl_content = """ @prefix : <http://example.com/> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . :Actor rdf:type owl:Class . :SoapOpera rdf:type owl:Class . :RoleOnSoapOpera rdf:type owl:Class . :role rdf:type owl:Class ; rdfs:subClassOf [ rdf:type owl:Restriction ; owl:onProperty :play_a_role ; owl:onClass :RoleOnSoapOpera ; owl:minQualifiedCardinality "1"^^xsd:nonNegativeInteger ] . """ create_file("structure_04.ttl", self.structure_02_ttl_content)
def test_it_should_use_file_size_as_the_command_buffer_size_on_isql_calls(self, popen_mock, communicate_mock): virtuoso = Virtuoso(self.config) create_file("big_file.ttl", "0123456789" * 480000) virtuoso._run_isql("big_file.ttl", True) popen_mock.assert_called_with('isql -U user -P password -H localhost -S 9999 -b 4800 < "big_file.ttl"', shell=True, stderr=-1, stdout=-1)