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) artifactory_user.get.assert_called_once_with(NEW_USER.name)
def test_create_user_success(mocker): responses.add(responses.GET, f"{URL}/api/security/users/{USER.name}", status=404) responses.add( responses.PUT, f"{URL}/api/security/users/{USER.name}", json=USER.dict(), status=201, ) 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") user = artifactory_user.create(NEW_USER) artifactory_user.get.assert_called_with(NEW_USER.name) assert artifactory_user.get.call_count == 2 assert user == USER.dict()