def test_does_not_update_unknown_branch_remotely(self, rebase, checkout, branches, fetch, is_working_copy): branches.return_value = ["1", "2", "5", "master"] is_working_copy.return_value = True r = repo.RallyRepository( remote_url="[email protected]/rally-resources", root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False) self.assertTrue(r.remote) with self.assertRaises(exceptions.SystemSetupError) as ctx: r.update(distribution_version="4.0.0") self.assertEqual("Cannot find unittest-resources for distribution version 4.0.0", ctx.exception.args[0]) calls = [ # first try to find it remotely... mock.call("/rally-resources/unit-test", remote=True), # ... then fallback to local mock.call("/rally-resources/unit-test", remote=False), ] branches.assert_has_calls(calls) self.assertEqual(0, checkout.call_count) self.assertEqual(0, rebase.call_count)
def test_does_nothing_if_working_copy_present(self, is_working_copy): is_working_copy.return_value = True r = repo.RallyRepository(remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=True) self.assertFalse(r.remote)
def test_checkout_revision(self, checkout, fetch, is_working_copy): is_working_copy.return_value = True r = repo.RallyRepository(remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False) r.checkout("abcdef123") checkout.assert_called_with("/rally-resources/unit-test", "abcdef123")
def test_fails_in_offline_mode_if_not_existing(self, is_working_copy, exists): is_working_copy.return_value = False exists.return_value = False with self.assertRaises(exceptions.SystemSetupError) as ctx: repo.RallyRepository(remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=True) self.assertEqual( "Expected a git repository at [/rally-resources/unit-test] but the directory does not exist.", ctx.exception.args[0])
def test_updates_from_remote(self, rebase, checkout, branches, fetch, is_working_copy): branches.return_value = ["1", "2", "5", "master"] is_working_copy.return_value = True r = repo.RallyRepository( remote_url="[email protected]/rally-resources", root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False) r.update(distribution_version="1.7.3") branches.assert_called_with("/rally-resources/unit-test", remote=True) rebase.assert_called_with("/rally-resources/unit-test", branch="1") checkout.assert_called_with("/rally-resources/unit-test", branch="1")
def test_updates_locally(self, rebase, checkout, branches, fetch, is_working_copy): branches.return_value = ["1", "2", "5", "master"] is_working_copy.return_value = True r = repo.RallyRepository( remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False) r.update(distribution_version="6.0.0") branches.assert_called_with("/rally-resources/unit-test", remote=False) self.assertEqual(0, rebase.call_count) checkout.assert_called_with("/rally-resources/unit-test", branch="master")
def test_fails_in_offline_mode_if_not_a_git_repo(self, is_working_copy, exists): is_working_copy.return_value = False exists.return_value = True with pytest.raises(exceptions.SystemSetupError) as exc: repo.RallyRepository( remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=True, ) assert exc.value.args[0] == ( "[/rally-resources/unit-test] must be a git repository.\n\nPlease run:\ngit -C /rally-resources/unit-test init" )
def test_fallback_to_tags(self, curr_branch, rebase, checkout, branches, tags, fetch, is_working_copy): curr_branch.return_value = "master" branches.return_value = ["5", "master"] tags.return_value = ["v1", "v1.7", "v2"] is_working_copy.return_value = True r = repo.RallyRepository(remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False) r.update(distribution_version="1.7.4") branches.assert_called_with("/rally-resources/unit-test", remote=False) self.assertEqual(0, rebase.call_count) tags.assert_called_with("/rally-resources/unit-test") checkout.assert_called_with("/rally-resources/unit-test", branch="v1.7")
def test_updates_locally(self, curr_branch, rebase, checkout, branches, fetch, is_working_copy, head_revision): curr_branch.return_value = "5" branches.return_value = ["1", "2", "5", "master"] is_working_copy.return_value = True head_revision.return_value = "123a" r = repo.RallyRepository( remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False, ) r.update(distribution_version="6.0.0") branches.assert_called_with("/rally-resources/unit-test", remote=False) assert rebase.call_count == 0 checkout.assert_called_with("/rally-resources/unit-test", branch="master")
def test_does_not_update_unknown_branch_locally(self, rebase, checkout, branches, tags, fetch, is_working_copy): branches.return_value = ["1", "2", "5", "master"] tags.return_value = [] is_working_copy.return_value = True r = repo.RallyRepository( remote_url=None, root_dir="/rally-resources", repo_name="unit-test", resource_name="unittest-resources", offline=False, ) with pytest.raises(exceptions.SystemSetupError) as exc: r.update(distribution_version="4.0.0") assert exc.value.args[ 0] == "Cannot find unittest-resources for distribution version 4.0.0" branches.assert_called_with("/rally-resources/unit-test", remote=False) assert checkout.call_count == 0 assert rebase.call_count == 0