Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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_deploy(self, expected_message=None,
expected_versions=[versions.VersionInfo('1.0')]):
rev = git_utils.get_latest_commit('master', short=True)
message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
universal_newlines=True).rstrip()
if expected_message:
self.assertEqual(message, expected_message)
else:
self.assertRegex(
message,
r'^Deployed {} to {} with MkDocs \S+ and mike \S+$'
.format(rev, expected_versions[0].version)
)
dirs = set()
for i in expected_versions:
dirs |= {str(i.version)} | i.aliases
contents = {'versions.json'} | set(chain.from_iterable(
message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
universal_newlines=True).rstrip()
if expected_message:
self.assertEqual(message, expected_message)
else:
self.assertRegex(message, r'^Copied \S+ to latest with mike \S+$')
assertDirectory('.', {
'versions.json',
'1.0/index.html',
'latest/index.html',
}, allow_extra=True)
with open('versions.json') as f:
self.assertEqual(list(versions.Versions.loads(f.read())), [
versions.VersionInfo('1.0', aliases=['latest']),
])
message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
universal_newlines=True).rstrip()
if expected_message:
self.assertEqual(message, expected_message)
else:
self.assertRegex(message,
r'^Set title of \S+ to 1\.0\.1 with mike \S+$')
assertDirectory('.', {
'versions.json',
'1.0/index.html',
}, allow_extra=True)
with open('versions.json') as f:
self.assertEqual(list(versions.Versions.loads(f.read())), [
versions.VersionInfo('1.0', '1.0.1'),
])
def _test_alias(self, expected_message=None):
message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
universal_newlines=True).rstrip()
if expected_message:
self.assertEqual(message, expected_message)
else:
self.assertRegex(message, r'^Copied \S+ to latest with mike \S+$')
assertDirectory('.', {
'versions.json',
'1.0/index.html',
'latest/index.html',
}, allow_extra=True)
with open('versions.json') as f:
self.assertEqual(list(versions.Versions.loads(f.read())), [
versions.VersionInfo('1.0', aliases=['latest']),
])
def _test_retitle(self, expected_message=None):
message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
universal_newlines=True).rstrip()
if expected_message:
self.assertEqual(message, expected_message)
else:
self.assertRegex(message,
r'^Set title of \S+ to 1\.0\.1 with mike \S+$')
assertDirectory('.', {
'versions.json',
'1.0',
'1.0/file.txt'
})
with open('versions.json') as f:
self.assertEqual(list(versions.Versions.loads(f.read())), [
versions.VersionInfo('1.0', '1.0.1'),
])
def _test_retitle(self, expected_message=None):
message = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'],
universal_newlines=True).rstrip()
if expected_message:
self.assertEqual(message, expected_message)
else:
self.assertRegex(message,
r'^Set title of \S+ to 1\.0\.1 with mike \S+$')
assertDirectory('.', {
'versions.json',
'1.0/index.html',
}, allow_extra=True)
with open('versions.json') as f:
self.assertEqual(list(versions.Versions.loads(f.read())), [
versions.VersionInfo('1.0', '1.0.1'),
])
self.assertRegex(
message,
r'^Deployed {} to {} with MkDocs \S+ and mike \S+$'
.format(rev, expected_versions[0].version)
)
dirs = set()
for i in expected_versions:
dirs |= {str(i.version)} | i.aliases
contents = {'versions.json'} | set(chain.from_iterable(
(d, d + '/index.html') for d in dirs
))
assertDirectory('.', contents, allow_extra=True)
with open('versions.json') as f:
self.assertEqual(list(versions.Versions.loads(f.read())),
expected_versions)
def _test_alias(self, expected_message=None, expected_src='1.0',
expected_aliases=['greatest']):
if not expected_message:
expected_message = r'^Copied {} to {} with mike \S+$'.format(
re.escape(expected_src),
re.escape(', '.join(expected_aliases))
)
self._test_state(expected_message, [
versions.VersionInfo('1.0', aliases=expected_aliases + ['latest'])
])
def test_update_aliases(self):
assertPopen(['mike', 'deploy', '1.0', 'latest'])
assertPopen(['mike', 'deploy', '-u', '2.0', 'latest'])
check_call_silent(['git', 'checkout', 'gh-pages'])
self._test_deploy(expected_versions=[
versions.VersionInfo('2.0', aliases=['latest']),
versions.VersionInfo('1.0'),
])