Beispiel #1
0
def test_replace_exception(get_db_mock, logger_mock):
    get_db_mock.side_effect = KeyError('problem')

    assert mossbot.MOSS.serve({
        'content': {
            'msgtype': 'm.text',
            'body': 's/Foo Bar/Zick Zack'
        },
        'sender': '@bar:foo.tld'
    }) == mossbot.MSG_RETURN('skip', None)

    assert logger_mock.exception.called is True
Beispiel #2
0
def test_weather_exception(requests_mock, logger_mock, config):
    requests_mock.get.side_effect = Exception('foo bar')

    event = {
        'content': {
            'msgtype': 'm.text',
            'body': '!weather wolfsburg'
        },
        'sender': '@bar:foo.tld'
    }

    event['config'] = config

    assert mossbot.MOSS.serve(event) == mossbot.MSG_RETURN(
        'notice', 'problem with getting weather')

    assert logger_mock.exception.called is True
Beispiel #3
0
def test_on_message_notice(moss_mock, store_msg_mock, matrix_handler, room):
    event = {
        'content': {
            'msgtype': 'm.text',
            'body': 'Foo Bar'
        },
        'sender': {'@bar:foo.tld'},
    }

    msg = mossbot.MSG_RETURN('notice', 'Foo Bar')

    moss_mock.serve.return_value = msg

    matrix_handler.on_message(room, event)

    room.send_notice.assert_called_with('Foo Bar')

    store_msg_mock.assert_called_with(event)
Beispiel #4
0
def test_on_message_reaction(moss_mock, write_media_mock, store_msg_mock,
                             matrix_handler, room):
    event = {
        'content': {
            'msgtype': 'm.text',
            'body': '!reaction foo bar'
        },
        'sender': '@bar:foo.tld'
    }

    msg = mossbot.MSG_RETURN('image', 'https://foo.tld/bar.gif')

    moss_mock.serve.return_value = msg

    matrix_handler.on_message(room, event)

    write_media_mock.assert_called_with('image', room,
                                        'https://foo.tld/bar.gif')

    store_msg_mock.assert_called_with(event)
Beispiel #5
0
def test_on_message_html(moss_mock, store_msg_mock, matrix_handler):
    event = {
        'content': {
            'msgtype': 'm.text',
            'body': 'Foo Bar'
        },
        'sender': {'@bar:foo.tld'},
    }

    msg = mossbot.MSG_RETURN('html', 'Foo Bar')

    moss_mock.serve.return_value = msg

    room_mock = mock.Mock()
    room_mock.room_id = '!foobar:foo.tld'
    room_mock.client.api.get_html_content.return_value = 'HTML'

    matrix_handler.on_message(room_mock, event)

    room_mock.send_html.assert_called_with('Foo Bar')

    store_msg_mock.assert_called_with(event)
Beispiel #6
0
def test_on_message_skip(moss_mock, store_msg_mock, write_media_mock,
                         logger_mock, matrix_handler, room):
    event = {
        'content': {
            'msgtype': 'm.text',
            'body': 'Foo Bar'
        },
        'sender': {'@bar:foo.tld'},
    }

    msg = mossbot.MSG_RETURN('skip', None)

    moss_mock.serve.return_value = msg

    matrix_handler.on_message(room, event)

    room.assert_not_called()

    write_media_mock.assert_not_called()

    store_msg_mock.assert_called_with(event)

    # logger_mock.info.assert_called_with('skipping msg...')
    print(logger_mock.info.call_args_list)
Beispiel #7
0
      ('image', 'https://mediarg/thumb/d/d4/Pav_23.jpg/80ieu_Louvre_3.jpg'))])
def test_image(route, expected):
    assert mossbot.MOSS.serve({'content': {'body': route}}) == expected


@pytest.mark.parametrize(
    'event,gif_url,expected',
    [({
        'content': {
            'body': '!reaction foo bar'
        },
        'config': {
            'giphy_api_key': 'abc123',
        }
    }, 'http://foo.bar/zonk.gif',
      mossbot.MSG_RETURN('image', 'http://foo.bar/zonk.gif')),
     ({
         'content': {
             'body': '!reaction foo bar'
         },
         'config': {
             'giphy_api_key': 'abc123',
         }
     }, None, mossbot.MSG_RETURN('skip', None))])
@mock.patch('mossbot.logger')
@mock.patch('mossbot.get_giphy_reaction_url')
def test_reaction(get_giphy_reaction_url_mock, logger_mock, event, gif_url,
                  expected):
    get_giphy_reaction_url_mock.return_value = gif_url

    assert mossbot.MOSS.serve(event) == expected