示例#1
0
 def test_add_to_matter_calls_post_with_expected_url_and_params(
         self, mock_connection):
     service = LegalHoldService(mock_connection)
     service.add_to_matter("user", "legal")
     expected_data = {"legalHoldUid": "legal", "userUid": "user"}
     mock_connection.post.assert_called_once_with(
         "/api/LegalHoldMembership", json=expected_data)
示例#2
0
    def test_add_to_matter_when_post_raises_bad_request_error_indicating_user_already_added_raises_user_already_added(
        self, mocker, mock_connection
    ):
        mock_connection.post.side_effect = create_mock_error(
            Py42BadRequestError, mocker, "USER_ALREADY_IN_HOLD"
        )
        mock_connection.get.return_value = {"name": "NAME"}
        service = LegalHoldService(mock_connection)
        with pytest.raises(Py42UserAlreadyAddedError) as err:
            service.add_to_matter("user", "legal")

        expected = (
            "User with ID user is already on the legal hold matter id=legal, name=NAME."
        )
        assert str(err.value) == expected
示例#3
0
    def test_add_to_matter_when_post_raises_bad_request_error_indicating_user_already_added_raises_user_already_added(
            self, mocker, mock_connection):
        def side_effect(*args, **kwargs):
            base_err = mocker.MagicMock(spec=HTTPError)
            base_err.response = mocker.MagicMock(spec=Response)
            base_err.response.text = "USER_ALREADY_IN_HOLD"
            raise Py42BadRequestError(base_err)

        mock_connection.post.side_effect = side_effect
        mock_connection.get.return_value = {"name": "NAME"}
        service = LegalHoldService(mock_connection)
        with pytest.raises(Py42UserAlreadyAddedError) as err:
            service.add_to_matter("user", "legal")

        expected = (
            "User with ID user is already on the legal hold matter id=legal, name=NAME."
        )
        assert str(err.value) == expected