def test_gitrevert(self): '''Make sure we can revert file.''' gitpath = self.get_tmpdir() git = GitIntegration(gitpath) # create a new file newfile, oldcontent = self.create_file(gitpath) git.update_file(newfile) # change file content newcontent = self.change_content(gitpath, newfile) git.update_file(newfile) # check changes is not empty commits = git.get_changes(newfile) self.assertEqual(type(commits), list) self.assertTrue(len(commits) > 0) # revert the file and get content commit = commits[0]['commit'] git.revert_file(newfile, commit) revcontent = self.get_content(gitpath, newfile) # check reverted file's content is the same as initial content self.assertEqual(revcontent, oldcontent) self.clean(gitpath)
def test_gitcommit(self): '''Test git commits new file.''' gitpath = self.get_tmpdir() git = GitIntegration(gitpath) # create a new file newfile, _ = self.create_file(gitpath) git.update_file(newfile) # make sure the file is referenced in HEAD head = self.get_content(gitpath, self.MASTERPATH) self.assertTrue(newfile in head) self.clean(gitpath)
def test_gitadduntracked(self): '''Test git adds untracked files.''' gitpath = self.get_tmpdir() newfile, _ = self.create_file(gitpath) # check new file is in git git = GitIntegration(gitpath) head = self.get_content(gitpath, self.MASTERPATH) self.assertTrue(newfile in head) self.clean(gitpath)
def test_gitinit(self): '''Test git init is done properly by checking git config file.''' gitpath = self.get_tmpdir() git = GitIntegration(gitpath) subpath = os.path.join(gitpath, '.git') self.assertTrue(os.path.exists(subpath)) cfgpath = os.path.join(subpath, 'config') self.assertTrue(os.path.exists(cfgpath)) # check we have markwiki in config (user.name) cfg = open(cfgpath, 'r').read() self.assertTrue('markwiki' in cfg) self.clean(gitpath)
def test_githistory(self): '''Make sure we're able to retrieve old version of files.''' gitpath = self.get_tmpdir() git = GitIntegration(gitpath) # create a new file newfile, _ = self.create_file(gitpath) git.update_file(newfile) # change file's content newcontent = self.change_content(gitpath, newfile) git.update_file(newfile) # check file history is not empty self.assertTrue(git.get_changes(newfile) != []) self.clean(gitpath)
def build_app(app_name): '''Build the application and extend it with various services.''' app = MarkWikiApp(app_name) if not app.is_bootstrapped(): print('This appears to be a new MarkWiki. Adding initial content ...') util.bootstrap(app) # Extend the app with the search engine. app.search_engine = SearchEngine(app.config['MARKWIKI_HOME']) if not app.search_engine.has_index(): app.search_engine.create_index(app.config['WIKI_PATH']) user_storage_factory = UserStorageFactory() app.user_storage = user_storage_factory.get_storage(app.config) app.gitint = None if app.config['GIT_ENABLED']: app.gitint = GitIntegration(app.config['WIKI_PATH']) return app