Skip to content

Commit

Permalink
update exists
Browse files Browse the repository at this point in the history
  • Loading branch information
joelee2012 committed Oct 21, 2023
1 parent 3d2e2a9 commit 198d4ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api4jenkins/__init__.py
Expand Up @@ -229,7 +229,7 @@ def exists(self):
:returns: True or False
'''
try:
self.handle_req('GET', '')
self._request('HEAD', self.url)
return True
except Exception as e:
return isinstance(e, (AuthenticationError, PermissionError))
Expand Down Expand Up @@ -389,7 +389,7 @@ def _resolve_name(self, full_name):

async def exists(self):
try:
await self.handle_req('GET', '')
await self._request('HEAD', self.url)
return True
except Exception as e:
return isinstance(e, (AuthenticationError, PermissionError))
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_jenkins.py
@@ -1,10 +1,11 @@
import weakref

import pytest

from api4jenkins import Jenkins
from api4jenkins.exceptions import BadRequestError, ItemNotFoundError
from api4jenkins.item import new_item, snake
from api4jenkins.job import AsyncFolder, AsyncWorkflowJob, WorkflowJob, Folder
from api4jenkins.job import AsyncFolder, AsyncWorkflowJob, Folder, WorkflowJob


class TestJenkins:
Expand Down Expand Up @@ -128,7 +129,7 @@ def test__name2url(self, jenkins, name, url_entry):
@pytest.mark.parametrize('status, exist', [(403, True), (200, True),
(404, False), (500, False)])
def test_exists(self, jenkins, respx_mock, status, exist):
respx_mock.get(jenkins.url).respond(status)
respx_mock.head(jenkins.url).respond(status)
assert jenkins.exists() == exist

def test_iter_jobs(self, jenkins):
Expand Down Expand Up @@ -288,7 +289,7 @@ async def test__name2url(self, async_jenkins, name, url_entry):
@pytest.mark.parametrize('status, exist', [(403, True), (200, True),
(404, False), (500, False)])
async def test_exists(self, async_jenkins, respx_mock, status, exist):
respx_mock.get(async_jenkins.url).respond(status)
respx_mock.head(async_jenkins.url).respond(status)
assert await async_jenkins.exists() == exist

async def test_iter_jobs(self, async_jenkins):
Expand Down

0 comments on commit 198d4ac

Please sign in to comment.