def test_applyUpdatesLastUpdateSuccess(self): self.dir += "update_test" inc_updates = self.getListofIncludedUpdates() updates = self.getListOfUpdates() last_update = updates[-2] self.connection.setResultList([((Constants.XALANIH_TABLE, ), )]) self.connection.setRowcountList([(1 if i <= len(inc_updates) else 0) for i in range(5)]) self.dbupdator = DBUpdator(self.dir, self.connection, self.req_handler, self.logger) self.dbupdator.applyUpdates(last_update) queries = self.connection.getQueries() expectedQueries = 1 + (len(updates) - 1) + 2 * (len(updates) - len(inc_updates) - 1) self.assertEqual(len(queries), expectedQueries, "Not the expected number of queries") for update in inc_updates: self.assertEqual( self.getNbRequested(queries, update), 1, "Wrong amount of request linked to" " the included update: {0}".format(update)) for update in [ u for u in updates if u not in inc_updates and u <= last_update ]: self.assertEqual( self.getNbRequested(queries, update), 2, "Wrong amount of request linked to" " the update: {0}".format(update))
def setUp(self): self.connection = Connection() self.logger = Logger() self.dir = os.path.dirname(__file__) + "/data/" self.req_handler = MysqlRequestHandler() self.dbupdator = DBUpdator(self.dir, self.connection, self.req_handler, self.logger)
def test_applyUpdatesNoUpdates(self): self.connection.setResultList([((Constants.XALANIH_TABLE, ), )]) self.dir += "creation_test" self.dbupdator = DBUpdator(self.dir, self.connection, self.req_handler, self.logger) self.dbupdator.applyUpdates(None) queries = self.connection.getQueries() self.assertEqual(len(queries), 1)
def test_applyUpdatesLastUpdateNotExist(self): self.dir += "update_test" inc_updates = self.getListofIncludedUpdates() updates = self.getListOfUpdates() last_update = "INVALID_UPDATE" self.connection.setResultList([((Constants.XALANIH_TABLE, ), )]) self.dbupdator = DBUpdator(self.dir, self.connection, self.req_handler, self.logger) with self.assertRaises(XalanihException) as cm: self.dbupdator.applyUpdates(last_update) self.assertEqual(cm.exception.getErrorCode(), XalanihException.UPDATE_NOT_FOUND, "Wrong error code.")
# Creating database if required if (action == Constants.ACTION_CREATE): creator = DBCreator(params.getDirectory(), connection, request_handler, logger) creator.createDatabase() logger.debug("Committing transaction.") connection.commit() # Updating database if required no_update = params.getNoUpdate() if no_update and action == Constants.ACTION_CREATE: logger.info("The flag 'no update' is set. Skipping the updates.") if (action == Constants.ACTION_UPDATE or (action == Constants.ACTION_CREATE and not no_update)): updator = DBUpdator(params.getDirectory(),connection,request_handler, logger) updator.applyUpdates(params.getLastUpdate()) connection.commit() logger.debug("Committing transaction.") logger.info("Done.") except XalanihException as e: logger.error(e.args[0]) logger.error("Stopping the execution of Xalanih.") if 'connection' in vars(): logger.debug("Rollbacking transaction.") connection.rollback() sys.exit(e.getErrorCode()) except Exception as e: logger.error("Unexpected exception:\n {0}".format(traceback.format_exc()))