Example #1
0
def test_get_conversation_bad_deserialize(get_mock):
    # type: (Mock) -> None
    get_mock.side_effect = [
        Response(True, '[' + conversation_contents + ']', 200),
        Response(True, '', 200)
    ]

    request = Fulfillment(id='PR-0000-0000-0000')
    conversation = request.get_conversation()

    assert get_mock.call_count == 2
    get_mock.assert_has_calls([
        call(headers={
            'Content-Type': 'application/json',
            'Authorization': 'ApiKey XXXX:YYYYY'
        },
             params={'instance_id': request.id},
             url='http://localhost:8080/api/public/v1/conversations/'),
        call(
            headers={
                'Content-Type': 'application/json',
                'Authorization': 'ApiKey XXXX:YYYYY'
            },
            url=
            'http://localhost:8080/api/public/v1/conversations/CO-750-033-356')
    ])

    assert conversation is None
Example #2
0
def test_get_conversation_ok(get_mock):
    # type: (Mock) -> None
    get_mock.side_effect = [
        Response(True, '[' + conversation_contents + ']', 200),
        Response(True, conversation_contents, 200)
    ]

    request = Fulfillment(id='PR-0000-0000-0000')
    conversation = request.get_conversation()

    assert get_mock.call_count == 2
    get_mock.assert_has_calls([
        call(headers={
            'Content-Type': 'application/json',
            'Authorization': 'ApiKey XXXX:YYYYY'
        },
             params={'instance_id': request.id},
             timeout=300,
             url='http://localhost:8080/api/public/v1/conversations'),
        call(headers={
            'Content-Type': 'application/json',
            'Authorization': 'ApiKey XXXX:YYYYY'
        },
             timeout=300,
             url='http://localhost:8080/api/public/v1/conversations/' +
             conversation.id)
    ])

    assert isinstance(conversation, Conversation)
Example #3
0
def test_get_conversation_empty(get_mock):
    # type: (Mock) -> None
    get_mock.return_value = Response(True, '[]', 200)

    request = Fulfillment(id='PR-0000-0000-0000')
    conversation = request.get_conversation()

    assert get_mock.call_count == 1
    get_mock.assert_has_calls([
        call(headers={
            'Content-Type': 'application/json',
            'Authorization': 'ApiKey XXXX:YYYYY'
        },
             params={'instance_id': request.id},
             url='http://localhost:8080/api/public/v1/conversations/')
    ])

    assert conversation is None