Exemplo n.º 1
0
 def list(self) -> List[SimpleUser]:
     """
     Lists all the users
     :return: UserList
     """
     response = self._get(f"api/{self._uri}")
     logger.debug("List all users successful")
     return [SimpleUser(**user) for user in response.json()]
import pytest
import responses

from pyartifactory import ArtifactoryUser
from pyartifactory.exception import UserAlreadyExistsException, UserNotFoundException
from pyartifactory.models import AuthModel, NewUser, UserResponse, SimpleUser

URL = "http://*****:*****@test.com")
NEW_USER = NewUser(name="test_user",
                   password="******",
                   email="*****@*****.**")


class TestUser:
    @staticmethod
    @responses.activate
    def test_create_user_fail_if_user_already_exists(mocker):
        responses.add(
            responses.GET,
            f"{URL}/api/security/users/{USER.name}",
            json=USER.dict(),
            status=200,
        )

        artifactory_user = ArtifactoryUser(AuthModel(url=URL, auth=AUTH))
        mocker.spy(artifactory_user, "get")
        with pytest.raises(UserAlreadyExistsException):
            artifactory_user.create(NEW_USER)