Пример #1
0
def test_post_success(EnqueueMessageUseCaseMock, BCInboxRepoMock, client):

    execute = EnqueueMessageUseCaseMock.return_value.execute
    execute.return_value = True

    msg_data = generate_message()
    msg_data['sender_ref'] = uuid.uuid4()
    msg_data['status'] = 'received'
    m = Message.from_dict(msg_data)

    http_response = client.post(POST_URL,
                                data=encode_message(m),
                                content_type='application/json')
    assert http_response.mimetype == VALID_RESPONSE_MIMETYPE
    assert not m.spurious_attrs_errors()
    assert int(http_response.status_code
               ) == HTTPStatus.CREATED, http_response.get_json()
    # the payload is re-case into a domain object
    execute.assert_called_with(m)
Пример #2
0
    error_response_json_template
)
from intergov.apis.common.utils.routing import (
    UnsupportedMediaTypeError
)
from intergov.domain.wire_protocols.generic_discrete import Message
from tests.unit.domain.wire_protocols.test_generic_message import (
    _generate_msg_dict as generate_message,
    _remove_message_params as remove_message_params
)

MESSAGE_CLASS = 'intergov.apis.message_rx.message.Message'
BC_INBOX_REPO_CLASS = 'intergov.apis.message_rx.message.BCInboxRepo'
ENQUEUE_MESSAGE_USE_CASE_CLASS = 'intergov.apis.message_rx.message.EnqueueMessageUseCase'

VALID_MESSAGE_DATA_DICT = generate_message()
VALID_MESSAGE_DATA_DICT['sender_ref'] = '00000000-1111-2222-3333-4445555666ff'

POST_URL = '/messages'

VALID_REQUEST_MIMETYPE = 'application/json'
VALID_RESPONSE_MIMETYPE = VALID_REQUEST_MIMETYPE

INVALID_REQUEST_MIMETYPE = 'application/x-www-form-urlencoded'


def _test_post_message_missing_required_attr(client, valid_data, url=POST_URL):
    for key in Message.required_attrs:

        data = remove_message_params(valid_data, keys=[key])
        resp = client.post(url, json=data)