Exemplo n.º 1
0
 def directory_contents(self, path, **kw):
     try:
         return self._contents[path]
     except KeyError:
         raise NotFoundError(
             DummyResponse("Accessed unexpected directory: {}".format(path),
                           404))
 def next(self):
     if self._prs == []:
         raise NotFoundError(Thing())
     elif self.counter < len(prs):
         self.counter += 1
         return self._prs[self.counter - 1]
     else:
         raise StopIteration
Exemplo n.º 3
0
 def test_create_branches_on_github__missing(self, user_factory,
                                             epic_factory):
     user = user_factory()
     with ExitStack() as stack:
         try_to_make_branch = stack.enter_context(
             patch(f"{PATCH_ROOT}.try_to_make_branch"))
         get_repo_info = stack.enter_context(
             patch(f"{PATCH_ROOT}.get_repo_info"))
         get_repo_info.return_value = MagicMock(
             **{"branch.side_effect": NotFoundError(MagicMock())})
         epic = epic_factory(branch_name="placeholder")
         create_gh_branch_for_new_epic(epic, user=user)
         assert try_to_make_branch.called
Exemplo n.º 4
0
 def test_clean__repo_missing(self, user_factory):
     form = ProjectForm({"name": "Test", "repo_owner": "test", "repo_name": "test"})
     # This is how the user gets there in real circumstances, just
     # jammed on:
     form.user = user_factory()
     with patch("metecho.api.admin.gh.get_repo_info") as get_repo_info:
         get_repo_info.side_effect = NotFoundError(MagicMock())
         assert not form.is_valid()
         assert form.errors == {
             "__all__": [
                 "Could not access test/test using GitHub app. "
                 "Does the Metecho app need to be installed for this repository?"
             ],
         }
Exemplo n.º 5
0
    def retrieve_asset_contents(self, release_tag: str, asset_label: str):
        ci.util.not_none(release_tag)
        ci.util.not_none(asset_label)

        release = self.repository.release_from_tag(release_tag)
        for asset in release.assets():
            if asset.label == asset_label or asset.name == asset_label:
                break
        else:
            response = requests.Response()
            response.status_code = 404
            response.json = lambda: {'message':'no asset with label {} found'.format(asset_label)}
            raise NotFoundError(resp=response)

        buffer = io.BytesIO()
        asset.download(buffer)
        return buffer.getvalue().decode()
Exemplo n.º 6
0
    def test_cumulusci_yml_error(self, mocker):
        user = MagicMock()
        repo_id = 123
        mocker.patch(f"{PATCH_ROOT}.zipfile")
        mocker.patch(f"{PATCH_ROOT}.os")
        gh_given_user = mocker.patch(f"{PATCH_ROOT}.gh_given_user")
        mocker.patch(f"{PATCH_ROOT}.shutil")
        glob = mocker.patch(f"{PATCH_ROOT}.glob")
        repository = MagicMock(default_branch="main")
        repository.file_contents.side_effect = NotFoundError(MagicMock())
        gh = MagicMock()
        gh.repository_with_id.return_value = repository
        gh_given_user.return_value = gh
        glob.return_value = ["owner-repo_name-"]

        with pytest.raises(Exception):
            with local_github_checkout(user, repo_id):
                pass  # pragma: nocover
Exemplo n.º 7
0
def test_main_create_release(github3_repo_mock, retry_client_mock,
                             valid_release_mock,
                             valid_release_with_assets_mock,
                             scriptworker_config):
    github3_repo_mock.release_from_tag.side_effect = [
        NotFoundError(MagicMock()),
        valid_release_mock,
        valid_release_with_assets_mock,
    ]

    main(config_path=scriptworker_config)
    github3_repo_mock.create_release.assert_called_once_with(
        tag_name="v5.2.0",
        name="Firefox 5.2",
        draft=False,
        prerelease=False,
        target_commitish="b94cfdf06be2be4b5a3c83ab4095eb2ecde7ba71")
    assert github3_repo_mock.edit.call_count == 0
    assert valid_release_mock.upload_asset.call_count == 2
Exemplo n.º 8
0
    def test_safe(self):
        user = MagicMock()
        repo = 123
        with ExitStack() as stack:
            stack.enter_context(patch(f"{PATCH_ROOT}.zipfile"))
            os = stack.enter_context(patch(f"{PATCH_ROOT}.os"))
            gh_given_user = stack.enter_context(
                patch(f"{PATCH_ROOT}.gh_given_user"))
            shutil = stack.enter_context(patch(f"{PATCH_ROOT}.shutil"))
            glob = stack.enter_context(patch(f"{PATCH_ROOT}.glob"))
            repository = MagicMock(default_branch="main")
            repository.file_contents.side_effect = NotFoundError(MagicMock())
            gh = MagicMock()
            gh.repository_with_id.return_value = repository
            gh_given_user.return_value = gh
            glob.return_value = ["owner-repo_name-"]

            with local_github_checkout(user, repo):
                assert shutil.rmtree.called
                assert os.remove.called
Exemplo n.º 9
0
 def release_from_tag(self, tag_name):
     for release in self._releases:
         if release.tag_name == tag_name:
             return release
     raise NotFoundError(DummyResponse("", 404))
Exemplo n.º 10
0
 def latest_release(self):
     for release in self._releases:
         if release.tag_name.startswith("release/"):
             return release
     raise NotFoundError(DummyResponse("", 404))
Exemplo n.º 11
0
 def branch(self, name):
     if name != self.default_branch:
         raise NotFoundError(MagicMock())
     return MagicMock(**{"latest_sha.return_value": "abc123"})
Exemplo n.º 12
0
 async def _mock_get_release(*args):
     if release_exists or next(get_release_call_counter) >= 1:
         return _DummyRelease()
     raise NotFoundError(MagicMock())