def setup(): """Setup function for tests.""" # global variable shouldn't be used but is quite useful here # pylint: disable=W0603 global TEMP_DIR TEMP_DIR = mkdtemp() if not os.path.exists(FAKE_DIR): os.mkdir(FAKE_DIR) Git(os.path.join(FAKE_DIR, 'documents.git')).init() app = Flask( __name__, static_folder=os.path.join(PATH, 'static'), template_folder=os.path.join(PATH, 'templates')) app.config.from_object(config) app.db = SQLAlchemy(app) nuts = application.Koztumize(app) application.app = app application.nuts = nuts app.config['MODELS'] = os.path.join(TEMP_DIR, 'models') git = Git(app.config['MODELS']) git.init() git.remote('add', '-t', 'models', 'origin', app.config['GIT_REMOTE']) git.pull() git.checkout('models') execute_sql(app, 'db.sql') import koztumize.routes import koztumize.tests.document
class GitCommandList: _repo = None _local_git_path = None _repo_url = None # to initialize the repository variable def init_git(self, local_git_path, repo_url): try: self._local_git_path = local_git_path self._repo_url = repo_url self._repo = Git(self._local_git_path, self._repo_url) self._repo.pull() return True except: return False # to make a commit, without doing a push on the remote repository on git def commit(self, message='Auto-commit: ' + str(datetime.now())): try: for file in local_tree(self._local_git_path): self._repo.add(file) self._repo.commit(message) return True except: return False # To push che files in the local repository. # A commit is generated automatically def push(self): try: self.commit() self._repo.pretty_log() r = self._repo.push() return '[*] Pushing at: ' + str(datetime.now()) + '\n' + r except: return False # to pull in the local from the remote repository def pull(self): try: self._repo.pretty_log() r = self._repo.pull() return '[*] Pulling at: ' + str(datetime.now()) + '\n' + r except Exception as e: print(e) return False
def setup(): """Set up the git repository for the all the tests""" # global variable shouldn't be used but is quite useful here # pylint: disable=W0603 global TEMP_DIR TEMP_DIR = mkdtemp() koztumize.app.config.from_pyfile( os.environ.get('KOZTUMIZE_CONFIG', 'test/config_test.py')) koztumize.db_model.init(koztumize.app) Git.push = lambda *args, **kwargs: None for repo in ('archive', 'model'): koztumize.app.config[repo.upper()] = os.path.join(TEMP_DIR, repo) git = Git(koztumize.app.config[repo.upper()]) git.init() git.remote( 'add', '-t', repo, 'origin', koztumize.app.config['GIT_REMOTE']) git.pull() git.checkout(repo)