diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index 971242e5..0aafb1c2 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -595,86 +595,6 @@ class DeployTest(unittest.TestCase): name, fdroidserver.deploy.REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url) ) - def test_update_servergitmirrors(self): - # setup parameters for this test run - fdroidserver.common.options = mock.Mock() - fdroidserver.common.options.identity_file = None - fdroidserver.common.options.no_keep_git_mirror_archive = False - fdroidserver.common.options.verbose = False - fdroidserver.common.options.quiet = True - fdroidserver.common.options.index_only = False - - config = {} - fdroidserver.common.fill_config_defaults(config) - fdroidserver.deploy.config = config - fdroidserver.deploy.config["servergitmirrors"] = [] - - repo_section = 'repo' - - # setup function for asserting subprocess.call invocations - update_servergitmirrors_call_iteration = 0 - remote_push_call_iteration = 0 - - os.chdir(self.testdir) - repo = Path('repo') - repo.mkdir(parents=True) - fake_apk = repo / 'Sym.apk' - with fake_apk.open('w') as fp: - fp.write('not an APK, but has the right filename') - fake_index = repo / fdroidserver.deploy.INDEX_FILES[0] - with fake_index.open('w') as fp: - fp.write('not an index, but has the right filename') - - def update_servergitmirrors_call(cmd): - nonlocal update_servergitmirrors_call_iteration - if update_servergitmirrors_call_iteration == 0: - self.assertListEqual( - cmd, - [ - 'rsync', - '--recursive', - '--safe-links', - '--times', - '--perms', - '--one-file-system', - '--delete', - '--chmod=Da+rx,Fa-x,a+r,u+w', - '--quiet', - 'repo/', - "git-mirror/fdroid/repo/", - ], - ) - else: - self.fail('unexpected subprocess.call invocation') - update_servergitmirrors_call_iteration += 1 - return 0 - - def remote_push_call(ref, force=False, set_upstream=False, **_args): - nonlocal remote_push_call_iteration - if remote_push_call_iteration == 0: - self.assertEqual([ref, force, set_upstream], ['master', True, True]) - else: - self.fail('unexpected git.Remote.push invocation') - remote_push_call_iteration += 1 - return [] - - with mock.patch('subprocess.call', side_effect=update_servergitmirrors_call): - with mock.patch( - 'git.Remote.push', side_effect=remote_push_call - ) as mock_remote_push: - mock_remote_push.return_value = [] - fdroidserver.deploy.update_servergitmirrors( - [{'url': 'https://github.com/user/repo'}], repo_section - ) - self.assertEqual( - update_servergitmirrors_call_iteration, - 1, - 'expected 1 invocations of subprocess.call', - ) - self.assertEqual( - remote_push_call_iteration, 1, 'expected 1 invocations of git.Remote.push' - ) - def test_update_awsbucket_s3cmd(self): # setup parameters for this test run fdroidserver.deploy.options = mock.Mock() @@ -891,7 +811,6 @@ class DeployTest(unittest.TestCase): self.assertEqual(call_iteration, 2, 'expected 2 invocations of subprocess.call') def test_update_awsbucket_libcloud(self): - from libcloud.storage.drivers.s3 import S3StorageDriver from libcloud.storage.base import Container # setup parameters for this test run @@ -1019,8 +938,6 @@ class DeployTest(unittest.TestCase): assert mock_driver.upload_object_via_stream.call_count == 1 def test_update_servergitmirrors(self): - from libcloud.storage.drivers.s3 import S3StorageDriver - from libcloud.storage.base import Container # setup parameters for this test run fdroidserver.deploy.options.identity_file = None @@ -1049,40 +966,37 @@ class DeployTest(unittest.TestCase): with fake_index.open('w') as fp: fp.write('not an index, but has the right filename') - with tempfile.TemporaryDirectory() as local_copy_dir: + def update_servergitmirrors_call(cmd): + nonlocal call_iteration + if call_iteration == 0: + self.assertListEqual( + cmd, + [ + 'rsync', + '--recursive', + '--safe-links', + '--times', + '--perms', + '--one-file-system', + '--delete', + '--chmod=Da+rx,Fa-x,a+r,u+w', + '--quiet', + 'repo/', + "git-mirror/fdroid/repo/", + ], + ) + else: + self.fail('unexpected subprocess.call invocation') + call_iteration += 1 + return 0 - def update_servergitmirrors_call(cmd): - nonlocal call_iteration - if call_iteration == 0: - self.assertListEqual( - cmd, - [ - 'rsync', - '--recursive', - '--safe-links', - '--times', - '--perms', - '--one-file-system', - '--delete', - '--chmod=Da+rx,Fa-x,a+r,u+w', - '--quiet', - 'repo/', - "git-mirror/fdroid/repo/", - ], - ) - else: - self.fail('unexpected subprocess.call invocation') - call_iteration += 1 - return 0 - - with mock.patch( - 'subprocess.call', side_effect=update_servergitmirrors_call - ): - fdroidserver.deploy.update_servergitmirrors([], repo_section) + with mock.patch( + 'subprocess.call', side_effect=update_servergitmirrors_call + ): + fdroidserver.deploy.update_servergitmirrors([], repo_section) self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call') def test_update_servergitmirrors_in_index_only_mode(self): - from libcloud.storage.base import Container # setup parameters for this test run fdroidserver.deploy.options.identity_file = None @@ -1111,45 +1025,44 @@ class DeployTest(unittest.TestCase): with fake_index.open('w') as fp: fp.write('not an index, but has the right filename') - with tempfile.TemporaryDirectory() as local_copy_dir: - def update_servergitmirrors_call(cmd): - nonlocal call_iteration - if call_iteration == 0: - self.assertListEqual( - cmd, - [ - 'rsync', - '--recursive', - '--safe-links', - '--times', - '--perms', - '--one-file-system', - '--delete', - '--chmod=Da+rx,Fa-x,a+r,u+w', - '--quiet', - 'repo/entry.jar', - 'repo/entry.json', - 'repo/entry.json.asc', - 'repo/index-v1.jar', - 'repo/index-v1.json', - 'repo/index-v1.json.asc', - 'repo/index-v2.json', - 'repo/index-v2.json.asc', - 'repo/index.jar', - 'repo/index.xml', - "git-mirror/fdroid/repo/", - ], - ) - else: - self.fail('unexpected subprocess.call invocation') - call_iteration += 1 - return 0 + def update_servergitmirrors_call(cmd): + nonlocal call_iteration + if call_iteration == 0: + self.assertListEqual( + cmd, + [ + 'rsync', + '--recursive', + '--safe-links', + '--times', + '--perms', + '--one-file-system', + '--delete', + '--chmod=Da+rx,Fa-x,a+r,u+w', + '--quiet', + 'repo/entry.jar', + 'repo/entry.json', + 'repo/entry.json.asc', + 'repo/index-v1.jar', + 'repo/index-v1.json', + 'repo/index-v1.json.asc', + 'repo/index-v2.json', + 'repo/index-v2.json.asc', + 'repo/index.jar', + 'repo/index.xml', + "git-mirror/fdroid/repo/", + ], + ) + else: + self.fail('unexpected subprocess.call invocation') + call_iteration += 1 + return 0 - with mock.patch( - 'subprocess.call', side_effect=update_servergitmirrors_call - ): - fdroidserver.deploy.update_servergitmirrors([], repo_section) + with mock.patch( + 'subprocess.call', side_effect=update_servergitmirrors_call + ): + fdroidserver.deploy.update_servergitmirrors([], repo_section) self.assertEqual(call_iteration, 1, 'expected 1 invocations of subprocess.call')