def migrate_db(source_string, dest_string): osfd, tmpfilename = mkstemp() session = getSession(source_string) saveYAML(session, tmpfilename) session.close() session2 = getSession(dest_string) loadYAML(session2, tmpfilename) os.remove(tmpfilename)
def setUp(self): super(base.TestCase, self).setUp() self.db_fd, filepath = tempfile.mkstemp() self.session = db.getSession("sqlite:///%s" % filepath) utils.loadYAML(self.session, './dlrn/tests/samples/commits_components.yaml') self.datadir = tempfile.mkdtemp() self.repodir = os.path.join(self.datadir, 'repos/component/tripleo/test1') os.makedirs(self.repodir) with open(os.path.join(self.repodir, "delorean.repo"), 'w') as fp: fp.write("TESTING ONE TWO THREE")
def create_db(self): """ Injects the database initial tables to the database using the existing utils offered by dlrn itself :return: None """ self.log.debug("Injecting %s data to %s", self.db_data, self.db_file) session = dlrn_db.getSession("sqlite:///%s" % self.db_file) try: utils.loadYAML(session, self.db_data) except sql_a_exc.IntegrityError: self.log.info("DB is not empty, not injecting data")
def setUp(self): super(TestBuild, self).setUp() config = configparser.RawConfigParser(default_options) config.read("projects.ini") config.set('DEFAULT', 'datadir', tempfile.mkdtemp()) config.set('DEFAULT', 'scriptsdir', tempfile.mkdtemp()) config.set('DEFAULT', 'baseurl', "file://%s" % config.get('DEFAULT', 'datadir')) self.config = ConfigOptions(config) shutil.copyfile(os.path.join("scripts", "centos.cfg"), os.path.join(self.config.scriptsdir, "centos.cfg")) with open(os.path.join(self.config.datadir, "delorean-deps.repo"), "w") as fp: fp.write("[test]\nname=test\nenabled=0\n") self.db_fd, filepath = tempfile.mkstemp() self.session = db.getSession("sqlite:///%s" % filepath) utils.loadYAML(self.session, './dlrn/tests/samples/commits_1.yaml')
def setUp(self): super(TestBuild, self).setUp() self.configfile = configparser.RawConfigParser() self.configfile.read("projects.ini") self.configfile.set('DEFAULT', 'datadir', tempfile.mkdtemp()) self.configfile.set('DEFAULT', 'scriptsdir', tempfile.mkdtemp()) self.configfile.set('DEFAULT', 'baseurl', "file://%s" % self.configfile.get('DEFAULT', 'datadir')) self.config = ConfigOptions(self.configfile) shutil.copyfile(os.path.join("scripts", "centos.cfg"), os.path.join(self.config.scriptsdir, "centos.cfg")) with open(os.path.join(self.config.datadir, "delorean-deps.repo"), "w") as fp: fp.write("[test]\nname=test\nenabled=0\n") self.db_fd, filepath = tempfile.mkstemp() self.session = db.getSession("sqlite:///%s" % filepath) utils.loadYAML(self.session, './dlrn/tests/samples/commits_1.yaml')
def inject_dlrn_fixtures(self): """ Injects the fixture to the database using the existing utils offered by dlrn itself """ session = dlrn_db.getSession( "sqlite:///%s" % self.config['db_filepath']) db_filepath = self.config['db_filepath'] self.config['results']['inject-dlrn-fixtures'] = db_filepath self.config['results']['dlrn_host'] = self.config['dlrn_host'] if self.config['dry-run']: return os.makedirs(os.path.join(self.dlrn_repo_dir, 'repos')) try: utils.loadYAML(session, self.config['db_fixtures']) except sqlite3.IntegrityError: self.log.info("DB is not empty, not injecting fixtures")
def setUp(self): super(TestUser, self).setUp() self.db_fd, filepath = tempfile.mkstemp() self.session = db.getSession("sqlite:///%s" % filepath) utils.loadYAML(self.session, './dlrn/tests/samples/commits_2.yaml')
def mocked_session(url): db_fd, filepath = tempfile.mkstemp() session = db.getSession("sqlite:///%s" % filepath) utils.loadYAML(session, './dlrn/tests/samples/commits_2.yaml') return session
def setUp(self): super(TestsWithData, self).setUp() self.session = db.getSession(new=True) utils.loadYAML(self.session, './dlrn/tests/samples/commits_1.yaml')
def mocked_session(url): db_fd, filepath = tempfile.mkstemp() session = db.getSession("sqlite:///%s" % filepath) utils.loadYAML(session, './dlrn/tests/samples/commits_1.yaml') return session
def mocked_session(url): session = db.getSession(url) utils.loadYAML(session, './dlrn/tests/samples/commits_1.yaml') return session
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from dlrn.db import getSession from dlrn.utils import loadYAML session = getSession('sqlite:////data/commits.sqlite') loadYAML(session, '/DLRN/dlrn/tests/samples/commits_2.yaml') session.close()