def get_remote_repo(self, repo_name: str) -> RemoteRepositoryResponse: """ Finds a remote repository in artifactory. Fill object if exist :param repo_name: Name of the repository to retrieve :return: RemoteRepositoryResponse object """ try: r = self._get(f"api/{self._uri}/{repo_name}") return RemoteRepositoryResponse(**r.json()) except requests.exceptions.HTTPError as e: if e.response.status_code == 404 or e.response.status_code == 400: logging.error(f"Repository {repo_name} does not exist") raise RepositoryNotFoundException( f" Repository {repo_name} does not exist") raise ArtifactoryException from e
def get_remote_repo(self, repo_name: str) -> RemoteRepositoryResponse: """ Finds a remote repository in artifactory. Fill object if exist :param repo_name: Name of the repository to retrieve :return: RemoteRepositoryResponse object """ warnings.warn( "`get_remote_repo()` is deprecated, use `get_repo` instead", DeprecationWarning, ) try: response = self._get(f"api/{self._uri}/{repo_name}") logger.debug("Repository %s found", repo_name) return RemoteRepositoryResponse(**response.json()) except requests.exceptions.HTTPError as error: if error.response.status_code in (404, 400): raise RepositoryNotFoundException( f" Repository {repo_name} does not exist") raise ArtifactoryException from error
SIMPLE_REPOSITORY = SimpleRepository(key="test_repository", type="local", url="some-url", packageType="docker") LOCAL_REPOSITORY = LocalRepository(key="test_local_repository") LOCAL_REPOSITORY_RESPONSE = LocalRepositoryResponse( key="test_local_repository") VIRTUAL_REPOSITORY = VirtualRepository(key="test_virtual_repository", rclass="virtual") VIRTUAL_REPOSITORY_RESPONSE = VirtualRepositoryResponse( key="test_virtual_repository", rclass="virtual") REMOTE_REPOSITORY = RemoteRepository(key="test_remote_repository", url="http://test-url.com", rclass="remote") REMOTE_REPOSITORY_RESPONSE = RemoteRepositoryResponse( key="test_remote_repository", url="http://test-url.com", rclass="remote") @responses.activate def test_create_local_repository_fail_if_user_already_exists(mocker): responses.add( responses.GET, f"{URL}/api/repositories/{LOCAL_REPOSITORY.key}", json=LOCAL_REPOSITORY_RESPONSE.dict(), status=200, ) artifactory_repo = ArtifactoryRepository(AuthModel(url=URL, auth=AUTH)) mocker.spy(artifactory_repo, "get_local_repo") with pytest.raises(RepositoryAlreadyExistsException): artifactory_repo.create_local_repo(LOCAL_REPOSITORY)
LOCAL_REPOSITORY_RESPONSE = LocalRepositoryResponse( key="test_local_repository") UPDATED_LOCAL_REPOSITORY = LocalRepository(key="test_local_repository", description="updated") UPDATED_LOCAL_REPOSITORY_RESPONSE = LocalRepositoryResponse( key="test_local_repository", description="updated") VIRTUAL_REPOSITORY = VirtualRepository(key="test_virtual_repository") VIRTUAL_REPOSITORY_RESPONSE = VirtualRepositoryResponse( key="test_virtual_repository") UPDATED_VIRTUAL_REPOSITORY = VirtualRepository(key="test_virtual_repository", description="updated") UPDATED_VIRTUAL_REPOSITORY_RESPONSE = VirtualRepositoryResponse( key="test_virtual_repository", description="updated") REMOTE_REPOSITORY = RemoteRepository(key="test_remote_repository", url="http://test-url.com") REMOTE_REPOSITORY_RESPONSE = RemoteRepositoryResponse( key="test_remote_repository", url="http://test-url.com") UPDATED_REMOTE_REPOSITORY = RemoteRepository( key="test_remote_repository", url="http://test-url.com", description="updated", ) UPDATED_REMOTE_REPOSITORY_RESPONSE = RemoteRepositoryResponse( key="test_remote_repository", url="http://test-url.com", description="updated", ) @responses.activate def test_create_local_repository_using_create_repo_fail_if_repository_already_exists( mocker, ):