How to use the werobot.testing function in WeRoBot

To help you get started, we’ve selected a few WeRoBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github offu / WeRoBot / tests / test_types.py View on Github external
def test_types():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    for type in robot.message_types:
        assert hasattr(robot, type)

    @robot.text
    def second(message):
        return "Hi"

    @robot.image
    def third(message):
        return 'nice pic'

    tester = werobot.testing.WeTest(robot)
    xml = """
    
    
    
    1348831860
    
    <content></content>
    1234567890123456
    
    """
    assert tester.send_xml(xml) == 'Hi'
    xml = """
    
    
    
    1348831860
github offu / WeRoBot / tests / test_robot.py View on Github external
def test_add_filter():
    import werobot.testing
    import re

    robot = WeRoBot()

    def test_register():
        return "test"

    robot.add_filter(test_register, ["test", re.compile(u".*?啦.*?")])

    tester = werobot.testing.WeTest(robot)

    assert tester.send_xml(_make_xml("test"))._args["content"] == "test"
    assert tester.send_xml(_make_xml(u"我要测试啦"))._args["content"] == "test"
    assert tester.send_xml(_make_xml(u"我要测试")) is None

    with pytest.raises(ValueError) as e:
        robot.add_filter("test", ["test"])
    assert e.value.args[0] == "test is not callable"

    with pytest.raises(ValueError) as e:
        robot.add_filter(test_register, "test")
    assert e.value.args[0] == "test is not list"

    with pytest.raises(TypeError) as e:
        robot.add_filter(test_register, [["bazinga"]])
    assert e.value.args[0] == "[\'bazinga\'] is not a valid rule"
github offu / WeRoBot / tests / test_imagemessage.py View on Github external
def test_echo():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    @robot.handler
    def echo(message):
        return message.img

    tester = werobot.testing.WeTest(robot)
    xml = """
    
    
    
    1348831860
    
    
    
    1234567890123456
    
    """
    assert tester.send_xml(xml) == "this is a url"
github offu / WeRoBot / tests / test_session.py View on Github external
robot = werobot.WeRoBot(
        token=werobot.utils.generate_token(), enable_session=True
    )

    @robot.text
    def first(message, session):
        if 'last' in session:
            return
        session['last'] = message.content
        return message.content

    @robot.text
    def second(_, session):
        return session['last']

    tester = werobot.testing.WeTest(robot)
    xml_1 = """
        
        
        
        1348831860
        
        <content></content>
        1234567890123456
        
    """
    xml_2 = """
        
        
        
        1348831860
github offu / WeRoBot / tests / test_handlers.py View on Github external
def test_one():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    @robot.handler
    def first(message):
        return

    def second(message):
        assert message.time == 1348831860
        return "Hi"

    robot.add_handler(second)

    tester = werobot.testing.WeTest(robot)
    xml = """
    
    
    
    1348831860
    
    <content></content>
    1234567890123456
    
    """
    assert tester.send_xml(xml) == 'Hi'
github offu / WeRoBot / tests / test_events.py View on Github external
def test_events():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())
    t = [False, '', 'NOTCHANGED']

    @robot.subscribe
    def first(message):
        return 'Hi'

    tester = werobot.testing.WeTest(robot)

    xml = """
    
        
        
        123456789
        
        
    
    """
    assert tester.send_xml(xml) == 'Hi', tester.send_xml(xml)

    @robot.unsubscribe
    def second(message):
        t[0] = True
github offu / WeRoBot / tests / test_locationmessage.py View on Github external
def test_echo():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    @robot.location
    def report(message):
        x, y = message.location
        return 'You are at ({x}, {y})'.format(
            x=x,
            y=y
        )

    tester = werobot.testing.WeTest(robot)
    xml = """
    
    
    
    1351776360
    
    20.00000
    30.00000
    40
    <label></label>
    1234567890123456
    
    """
    assert tester.send_xml(xml) == 'You are at (20.0, 30.0)'
github offu / WeRoBot / tests / test_link.py View on Github external
def test_link():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    @robot.link
    def first(message):
        assert message.title == 'title'
        assert message.description == 'description'
        assert message.url == 'url'

    tester = werobot.testing.WeTest(robot)

    xml = """
    
        
        
        123456789
        
        <title>&lt;![CDATA[title]]&gt;</title>
        
        
    
    """
    tester.send_xml(xml)
github offu / WeRoBot / tests / test_handlers.py View on Github external
def test_two():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    @robot.handler
    def first(message):
        if 'hi' in message.content:
            return 'Hello'

    @robot.handler
    def second(message):
        return "Hi"

    tester = werobot.testing.WeTest(robot)
    xml = """
    
    
    
    1348831860
    
    <content></content>
    1234567890123456
    
    """
    assert tester.send_xml(xml) == 'Hello'
    xml = """
    
    
    
    1348831860
github offu / WeRoBot / tests / test_textmessage.py View on Github external
def test_echo():
    robot = werobot.WeRoBot(token=werobot.utils.generate_token())

    @robot.handler
    def echo(message):
        return message.content

    tester = werobot.testing.WeTest(robot)
    xml = """
    
    
    
    1348831860
    
    <content></content>
    1234567890123456
    
    """
    assert tester.send_xml(xml) == 'this is a test'