예제 #1
0
def test_has_no_work():
    scenario = Mock()
    user_id = "abc"
    backend = Mock()

    uc = commands.UserCommands(scenario, user_id, backend)

    backend.get_work.return_value = 0

    assert not uc.has_work()
예제 #2
0
def test_is_not_up():
    scenario = Mock()
    user_id = "abc"
    backend = Mock()

    event = Mock()

    event.payload = {"IDs": ["abc"]}

    uc = commands.UserCommands(scenario, user_id, backend)

    backend.get_user_events.return_value = [event]

    assert not uc.is_up()
예제 #3
0
def test_run_output():
    def test_fn():
        return 42

    scenario = Mock()
    user_id = "abc"
    backend = Mock()

    scenario.fn = test_fn

    uc = commands.UserCommands(scenario, user_id, backend)

    output, exception, logs = uc.run()

    assert output == 42
    assert exception is None
    assert logs == ""
예제 #4
0
def test_run_logs():
    def test_fn():
        print("foo")

    scenario = Mock()
    user_id = "abc"
    backend = Mock()

    scenario.fn = test_fn

    uc = commands.UserCommands(scenario, user_id, backend)

    output, exception, logs = uc.run()

    assert output is None
    assert exception is None
    assert logs == "foo\n"
예제 #5
0
def test_run_exception():
    def test_fn():
        raise ValueError("some error")

    scenario = Mock()
    user_id = "abc"
    backend = Mock()

    scenario.fn = test_fn

    uc = commands.UserCommands(scenario, user_id, backend)

    output, exception, logs = uc.run(log_traceback=False)

    assert output is None
    assert isinstance(exception, ValueError)
    assert str(exception) == "some error"
    assert logs == ""