def test_diverged_remote(self): stage_dir('serve_clone') check_call_silent(['git', 'clone', self.stage, '.']) check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages']) git_config() with pushd(self.stage): with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file( git_utils.FileInfo('file-origin.txt', 'this is some text')) origin_rev = git_utils.get_latest_commit('gh-pages') with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', 'this is some text')) clone_rev = git_utils.get_latest_commit('gh-pages') check_call_silent(['git', 'fetch', 'origin']) self._check_serve(err_output=( 'warning: gh-pages has diverged from origin/gh-pages\n' + ' Pass --ignore to ignore this or --rebase to rebase onto ' + 'remote\n')) self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev) self._check_serve(['--ignore']) self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev) self._check_serve(['--rebase']) self.assertEqual(git_utils.get_latest_commit('gh-pages'), origin_rev)
def test_invalid_email(self): check_call_silent(['git', 'config', 'user.email', '<>']) with self.assertRaises(git_utils.GitError): with git_utils.Commit('master', 'add file'): pass with mock.patch('mike.git_utils.get_config', return_value=''), \ self.assertRaises(git_utils.GitError): with git_utils.Commit('master', 'add file'): pass
def setUp(self): self.stage = stage_dir('read_file') os.chdir(self.stage) git_init() with git_utils.Commit('branch', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', 'this is some text'))
def test_delete_files_from_dir(self): self._add_file(os.path.join('dir', 'file.txt')) self._add_file(os.path.join('dir', 'file2.txt')) with git_utils.Commit('master', 'delete file') as commit: commit.delete_files([os.path.join('dir', 'file.txt')]) check_call_silent(['git', 'checkout', 'master']) assertDirectory('.', {'dir', 'dir/file2.txt'})
def test_context_already_finished(self): with git_utils.Commit('master', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', 'this is some text')) commit.finish() check_call_silent(['git', 'checkout', 'master']) assertDirectory('.', {'file.txt'})
def test_delete_all_files(self): self._add_file('file.txt') self._add_file('file2.txt') with git_utils.Commit('master', 'delete all files') as commit: commit.delete_files('*') check_call_silent(['git', 'checkout', 'master']) assertDirectory('.', set())
def test_404_root(self): with git_utils.Commit('branch', 'remove file') as commit: commit.delete_files(['index.html']) req = MockRequest(path=b'/') self.server.handle_request(req) self.assertRegex( req.response, b'HTTP/1.0 404 File not found. Did you.*\r\n' + b'Server: MikeHTTP.*\r\n' + b'Date: .*\r\n')
def test_finish(self): commit = git_utils.Commit('master', 'add file') commit.add_file(git_utils.FileInfo('file.txt', 'this is some text')) commit.finish() self.assertRaises(git_utils.GitError, commit.finish) self.assertRaises(git_utils.GitError, commit.abort) check_call_silent(['git', 'checkout', 'master']) assertDirectory('.', {'file.txt'})
def test_behind_remote(self): with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', 'this is some text')) stage_dir('deploy_clone') check_call_silent(['git', 'clone', self.stage, '.']) check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages']) git_config() with pushd(self.stage): with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file( git_utils.FileInfo('file2.txt', 'this is some text')) origin_rev = git_utils.get_latest_commit('gh-pages') check_call_silent(['git', 'fetch', 'origin']) assertPopen(['mike', 'deploy', '1.0']) self.assertEqual(git_utils.get_latest_commit('gh-pages^'), origin_rev)
def setUp(self): self.stage = stage_dir('serve') git_init() copytree(os.path.join(test_data_dir, 'basic_theme'), self.stage) check_call_silent(['git', 'add', 'mkdocs.yml', 'docs']) check_call_silent(['git', 'commit', '-m', 'initial commit']) with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo('index.html', 'main page')) commit.add_file(git_utils.FileInfo('dir/index.html', 'sub page'))
def test_versions_exist(self): with git_utils.Commit('gh-pages', 'add versions.json') as commit: commit.add_file( git_utils.FileInfo( 'versions.json', '[{"version": "1.0", "title": "1.0", "aliases": []}]', )) self.assertEqual(list(commands.list_versions()), [ versions.VersionInfo('1.0'), ])
def _mock_commit(self): with git_utils.Commit('gh-pages', 'add versions.json') as commit: commit.add_file( git_utils.FileInfo( 'versions.json', '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]', )) commit.add_file(git_utils.FileInfo('1.0/page.html', '')) commit.add_file(git_utils.FileInfo('1.0/file.txt', '')) commit.add_file(git_utils.FileInfo('1.0/dir/index.html', '')) commit.add_file(git_utils.FileInfo('latest/page.html', '')) commit.add_file(git_utils.FileInfo('latest/dir/index.html', ''))
def setUp(self): self.stage = stage_dir('list') git_init() all_versions = versions.Versions() all_versions.add('1.0') all_versions.add('2.0', '2.0.2') all_versions.add('3.0', '3.0.3', ['stable']) all_versions.add('4.0', aliases=['latest', 'dev']) with git_utils.Commit('gh-pages', 'commit message') as commit: commit.add_file( git_utils.FileInfo('versions.json', all_versions.dumps()))
def test_local_empty(self): with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', 'this is some text')) origin_rev = git_utils.get_latest_commit('gh-pages') stage_dir('deploy_clone') check_call_silent(['git', 'clone', self.stage, '.']) git_config() assertPopen(['mike', 'deploy', '1.0']) self.assertEqual(git_utils.get_latest_commit('gh-pages^'), origin_rev)
def test_handle_exception(self): self._add_file('file.txt') try: with git_utils.Commit('master', 'add file') as commit: commit.add_file( git_utils.FileInfo('file2.txt', 'this is some text')) raise ValueError('bad') except ValueError: pass check_call_silent(['git', 'checkout', 'master']) assertDirectory('.', {'file.txt'})
def test_diverged_remote(self): with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo( 'file.txt', 'this is some text' )) stage_dir('deploy_clone') check_call_silent(['git', 'clone', self.stage, '.']) check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages']) git_config() with pushd(self.stage): with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo( 'file2-origin.txt', 'this is some text' )) origin_rev = git_utils.get_latest_commit('gh-pages') with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo( 'file2.txt', 'this is some text' )) clone_rev = git_utils.get_latest_commit('gh-pages') check_call_silent(['git', 'fetch', 'origin']) assertOutput(self, ['mike', 'deploy', '1.0'], output=( 'error: gh-pages has diverged from origin/gh-pages\n' + ' Pass --ignore to ignore this or --rebase to rebase onto ' + 'remote\n' ), returncode=1) self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev) assertPopen(['mike', 'deploy', '1.0', '--ignore']) self.assertEqual(git_utils.get_latest_commit('gh-pages^'), clone_rev) assertPopen(['mike', 'deploy', '1.0', '--rebase']) self.assertEqual(git_utils.get_latest_commit('gh-pages^'), origin_rev)
def test_overwrite_alias(self): with git_utils.Commit('gh-pages', 'add versions.json') as commit: commit.add_file( git_utils.FileInfo( 'versions.json', '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]', )) commit.add_file(git_utils.FileInfo('1.0/file.txt', '')) commit.add_file(git_utils.FileInfo('latest/file.txt', '')) with self.assertRaises(ValueError): commands.deploy(self.stage, '2.0', '2.0.0', ['latest']) check_call_silent(['git', 'checkout', 'gh-pages']) self._test_deploy('add versions.json', [versions.VersionInfo('1.0', '1.0', ['latest'])])
def test_overwrite_version(self): with git_utils.Commit('gh-pages', 'add versions.json') as commit: commit.add_file( git_utils.FileInfo( 'versions.json', '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]', )) commit.add_file(git_utils.FileInfo('1.0/old-file.txt', '')) commit.add_file(git_utils.FileInfo('latest/old-file.txt', '')) commands.deploy(self.stage, '1.0', '1.0.1', ['greatest']) check_call_silent(['git', 'checkout', 'gh-pages']) self._test_deploy(expected_versions=[ versions.VersionInfo('1.0', '1.0.1', ['latest', 'greatest']) ])
def test_ahead_remote(self): origin_rev = git_utils.get_latest_commit('gh-pages') stage_dir('serve_clone') check_call_silent(['git', 'clone', self.stage, '.']) check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages']) git_config() with git_utils.Commit('gh-pages', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', 'this is some text')) clone_rev = git_utils.get_latest_commit('gh-pages') self._check_serve() self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev) self.assertEqual(git_utils.get_latest_commit('gh-pages^'), origin_rev)
def setUp(self): self.stage = stage_dir('walk_files') os.chdir(self.stage) git_init() commit_files(['file.txt'], 'initial commit') with git_utils.Commit('branch', 'add file') as commit: commit.add_file(git_utils.FileInfo('file.txt', b'text')) commit.add_file( git_utils.FileInfo(os.path.join('dir/file.txt'), b'more text')) commit.add_file( git_utils.FileInfo(os.path.join('dir', 'file 2.txt'), b'more text')) commit.add_file( git_utils.FileInfo(os.path.join('dir', 'subdir', 'file 3.txt'), b'even more text'))
def test_update_aliases(self): with git_utils.Commit('gh-pages', 'add versions.json') as commit: commit.add_file( git_utils.FileInfo( 'versions.json', '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]', )) commit.add_file(git_utils.FileInfo('1.0/file.txt', '')) commit.add_file(git_utils.FileInfo('latest/file.txt', '')) commands.deploy(self.stage, '2.0', '2.0.0', ['latest'], True) check_call_silent(['git', 'checkout', 'gh-pages']) self._test_deploy('.*', [ versions.VersionInfo('2.0', '2.0.0', ['latest']), versions.VersionInfo('1.0', '1.0', []), ])
def setUp(self): self.stage = stage_dir('list') git_init() copytree(os.path.join(test_data_dir, 'basic_theme'), self.stage) check_call_silent(['git', 'add', 'mkdocs.yml', 'docs']) check_call_silent(['git', 'commit', '-m', 'initial commit']) all_versions = versions.Versions() all_versions.add('1.0') all_versions.add('2.0', '2.0.2') all_versions.add('3.0', '3.0.3', ['stable']) all_versions.add('4.0', aliases=['latest', 'dev']) with git_utils.Commit('gh-pages', 'commit message') as commit: commit.add_file( git_utils.FileInfo(os.path.join(self.prefix, 'versions.json'), all_versions.dumps()))
def setUp(self): self.stage = stage_dir('server') git_init() with git_utils.Commit('branch', 'add file') as commit: commit.add_file(git_utils.FileInfo('index.html', 'main page')) commit.add_file(git_utils.FileInfo('dir/index.html', 'sub page')) class Handler(server.GitBranchHTTPHandler): branch = 'branch' # Use a buffered response in Python 3.6+, since it's easier for # testing. if sys.version_info >= (3, 6): wbufsize = -1 def log_message(self, *args): pass self.server = MockServer(('0.0.0.0', 8888), Handler)
def test_invalid_username(self): check_call_silent(['git', 'config', 'user.name', '<>']) with self.assertRaises(git_utils.GitError): with git_utils.Commit('master', 'add file'): pass
def setUp(self): self.stage = stage_dir('serve') git_init() with git_utils.Commit('branch', 'add file') as commit: commit.add_file(git_utils.FileInfo('index.html', 'main page')) commit.add_file(git_utils.FileInfo('dir/index.html', 'sub page'))
def _add_file(self, name, branch='master'): with git_utils.Commit(branch, 'add file') as commit: commit.add_file(git_utils.FileInfo(name, 'this is some text'))