Beispiel #1
0
 def test_create_when_fails_with_unknown_error_raises_custom_exception(
         self, mock_connection, mock_unknown_error):
     cases_service = CasesService(mock_connection)
     mock_connection.post.side_effect = Py42BadRequestError(
         mock_unknown_error)
     with pytest.raises(Py42BadRequestError) as e:
         cases_service.create("Case")
     assert e.value.response.status_code == 400
Beispiel #2
0
 def test_create_when_fails_with_unknown_error_raises_exception(
     self, mocker, mock_connection
 ):
     cases_service = CasesService(mock_connection)
     mock_connection.post.side_effect = create_mock_error(
         Py42BadRequestError, mocker, UNKNOWN_ERROR_MSG
     )
     with pytest.raises(Py42BadRequestError):
         cases_service.create("Case")
Beispiel #3
0
    def test_create_when_fails_with_description_too_long_error_raises_custom_exception(
            self, mock_connection, mock_description_too_long_response):
        cases_service = CasesService(mock_connection)
        mock_connection.post.side_effect = Py42BadRequestError(
            mock_description_too_long_response)
        with pytest.raises(Py42DescriptionLimitExceededError) as e:
            cases_service.create("test", description=u"supposedly too long")

        assert (e.value.args[0] ==
                u"Description limit exceeded, max 250 characters allowed.")
Beispiel #4
0
    def test_create_when_fails_with_invalid_assignee_raises_custom_exception(
        self, mocker, mock_connection
    ):
        cases_service = CasesService(mock_connection)
        mock_connection.post.side_effect = create_mock_error(
            Py42BadRequestError, mocker, _get_invalid_user_text("assignee")
        )
        with pytest.raises(Py42InvalidCaseUserError) as err:
            cases_service.create("test", assignee="Not a person")

        assert err.value.args[0] == "The provided assignee is not a valid user."
Beispiel #5
0
    def test_create_when_fails_with_name_exists_error_raises_custom_exception(
            self, mock_connection, mock_name_exists_response):
        cases_service = CasesService(mock_connection)
        mock_connection.post.side_effect = Py42BadRequestError(
            mock_name_exists_response)
        with pytest.raises(Py42CaseNameExistsError) as e:
            cases_service.create("Duplicate")

        assert (
            e.value.args[0] ==
            u"Case name 'Duplicate' already exists, please set another name")
Beispiel #6
0
 def test_create_called_with_expected_url_and_params(self, mock_connection):
     cases_service = CasesService(mock_connection)
     cases_service.create("name", "subject", "user uid", "description", "findings")
     assert mock_connection.post.call_args[0][0] == "/api/v1/case"
     data = {
         "name": "name",
         "subject": "subject",
         "assignee": "user uid",
         "description": "description",
         "findings": "findings",
     }
     mock_connection.post.assert_called_once_with(_BASE_URI, json=data)
Beispiel #7
0
    def test_create_when_fails_with_description_too_long_error_raises_custom_exception(
        self, mocker, mock_connection
    ):
        cases_service = CasesService(mock_connection)
        mock_connection.post.side_effect = create_mock_error(
            Py42BadRequestError, mocker, DESCRIPTION_TOO_LONG_ERROR_MSG
        )
        with pytest.raises(Py42DescriptionLimitExceededError) as err:
            cases_service.create("test", description="supposedly too long")

        assert (
            err.value.args[0]
            == "Description limit exceeded, max 250 characters allowed."
        )
Beispiel #8
0
    def test_create_when_fails_with_name_exists_error_raises_custom_exception(
        self, mocker, mock_connection
    ):
        cases_service = CasesService(mock_connection)
        mock_connection.post.side_effect = create_mock_error(
            Py42BadRequestError, mocker, NAME_EXISTS_ERROR_MSG
        )
        with pytest.raises(Py42CaseNameExistsError) as err:
            cases_service.create("Duplicate")

        assert (
            err.value.args[0]
            == "Case name 'Duplicate' already exists, please set another name."
        )