def testCheckVersion(self): script = File("checkversion.sql") properties = Properties() properties.set_property('name', 'app_prop') properties.set_property('previous', '1.0.0') stream = PreProcessor.parse(script, properties) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = "mysql --show-warnings --host=localhost --user=apps --password=apps acme" call = CallFactory.new_call(statement) call['stdin'] = script_reader call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) print "result", result
def testDropPass(self): NOORA_DIR = os.path.dirname(noora.__file__) CURRENT_DIR = os.path.abspath('.') properties = Properties() properties.set_property("noora.dir", NOORA_DIR) properties.set_property("current.dir", CURRENT_DIR) properties.set_property("plugin.dir", os.path.join(NOORA_DIR, 'plugins')) properties.set_property("project.file", "myproject.json") app = App() f = app.get_config_file(properties) f = open(f.get_url()) data = json.load(f) for key in data.keys(): properties.set_property(key, data[key]) parser = argparse.ArgumentParser( description="mynoora, a sql deployment tool", add_help=False) parser.add_argument("commands", help="display a square of a given number", type=str, nargs='+') parser.add_argument('-r', action='store_true', help='show the revision') parser.add_argument('-t', type=str, help='version', required=False) arguments = parser.parse_args(['generate', '-t=mssql']) plugin = GeneratePlugin() plugin.execute(arguments, properties)
def testDropPass(self): NOORA_DIR = os.path.dirname(noora.__file__) CURRENT_DIR = os.path.abspath('.') properties = Properties() properties.set_property("noora.dir", NOORA_DIR) properties.set_property("current.dir", CURRENT_DIR) properties.set_property("plugin.dir", os.path.join(NOORA_DIR, 'plugins')) properties.set_property("project.file", "myproject.json") app = App() f = app.get_config_file(properties) f = open(f.get_url()) data = json.load(f) for key in data.keys(): properties.set_property(key, data[key]) parser = argparse.ArgumentParser(description="mynoora, a sql deployment tool", add_help=False) parser.add_argument("commands", help="display a square of a given number", type=str, nargs='+') parser.add_argument('-r', action='store_true', help='show the revision') parser.add_argument('-h', type=str, help='host', required=False) parser.add_argument('-s', type=str, help='schema', required=False) parser.add_argument('-e', type=str, help='environment', required=False) parser.add_argument('-a', type=str, help='alias', required=False) arguments = parser.parse_args(['drop', '-h=elsevierdb4.c07v9zv3jhxs.eu-west-1.rds.amazonaws.com,1433']) plugin = DropPlugin() plugin.execute(arguments, properties)
def testProcessor(self): script = File("drop_tables.sql") properties = Properties() properties.set_property('database', 'orcl') stream = PreProcessor.parse(script, properties) self.assertEqual(stream, 'orcl', "invalid transformation")
def execute(self, executable, properties): script = executable['script'] cp = Properties() cp.set_property('database', executable['database']) if 'schema' in executable.keys(): cp.set_property('schema', executable['schema']) if 'environment' in properties.keys(): cp.set_property('environment', properties.get_property('environment')) if 'previous' in properties.keys(): cp.set_property('previous', properties.get_property('previous')) stream = PreProcessor.parse(script, cp) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() #script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = "sqlcmd -b -S " + executable['host'] + " -U " + executable[ 'username'] + ' -P ' + executable['password'] + " -d " + executable[ 'database'] + " -i " + tmp.get_url() call = CallFactory.new_call(statement) call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) self.set_result(result)
def testEnvironment(self): noora_dir = os.path.dirname(noora.__file__) current_dir = os.path.abspath('.') properties = Properties() properties.set_property("noora.dir", noora_dir) properties.set_property("current.dir", current_dir) executable = {} executable['script'] = File("exec_get_environment.sql") executable['host'] = "elsevierdb4.c07v9zv3jhxs.eu-west-1.rds.amazonaws.com,1433" executable['user'] = "******" executable['password'] = "******" executable['database'] = "ElsevierDB" connector = MssqlConnector() connector.execute(executable, properties)
def main(args=None): properties = Properties() properties.set_property("noora.dir", NOORA_DIR) properties.set_property("current.dir", CURRENT_DIR) properties.set_property("plugin.dir", os.path.join(NOORA_DIR, 'plugins')) properties.set_property("project.file", "myproject.json") # find the project config file myproject.json, in the current folder or in the noora folder app = App() f = app.get_config_file(properties) f = open(f.get_url()) data = json.load(f) for key in data.keys(): properties.set_property(key, data[key]) # Instantiate the argument parser parser = argparse.ArgumentParser(description="mynoora, a sql deployment tool", add_help=False) parser.add_argument("commands", help="display a square of a given number", type=str, nargs='+') parser.add_argument('-r', action='store_true', help='show the revision') parser.add_argument('-v', type=str, help='version', required=False) parser.add_argument('-h', type=str, help='host', required=False) parser.add_argument('-d', type=str, help='database', required=False) parser.add_argument('-e', type=str, help='environment', required=False) parser.add_argument('-a', type=str, help='alias', required=False) parser.add_argument('-s', type=str, help='schema', required=False) parser.add_argument('-t', type=str, help='technology', required=False) args = parser.parse_args(args) # show the revision if args.r: print noora.__title__ + " version " + noora.__version__ exit(0) # execute the given commands commands = args.commands Fail.fail_on_no_command(commands) for command in commands: plugin = App.find_plugin(command, properties) Fail.fail_on_invalid_plugin(plugin) plugin.execute(args, properties)
def execute(self, executable, properties): script = executable['script'] cp = Properties() cp.set_property('database', executable['database']) if 'environment' in properties.keys(): cp.set_property('environment', properties.get_property('environment')) if 'previous' in properties.keys(): cp.set_property('previous', properties.get_property('previous')) stream = PreProcessor.parse(script, cp) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = "mysql --show-warnings --host=" + executable[ 'host'] + " --user="******" --password="******" " + executable['database'] call = CallFactory.new_call(statement) call['stdin'] = script_reader call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) self.set_result(result)
def testCheckVersion(self): properties = Properties() properties.set_property("current.dir", os.path.abspath('.')) properties.set_property('create.dir', os.path.join(properties.get_property('current.dir'), 'create')) properties.set_property('alter.dir', os.path.join(properties.get_property('current.dir'), 'alter')) properties.set_property('default_version', '1.0.0') versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() previous = versions.previous(Version('1.0.2')) self.assertEqual(previous.get_value(), '1.0.1', 'invalid version') previous = versions.previous(Version('1.0.1')) self.assertEqual(previous.get_value(), '1.0.0', 'invalid version') # this is the odd one. Given is the first version, because off the fact that there is no previous version, # the first version is returned. previous = versions.previous(Version('1.0.0')) self.assertEqual(previous.get_value(), '1.0.0', 'invalid version')