示例#1
0
def test_settings_read_attribute_as_int():
    clear_expectations()

    fake_config = Fake("config")
    fake_config.expects("get").with_args("name", "setting").returns("10")

    ss = SettingsSection(None, "name", fake_config)
    assert ss.as_int("setting") == 10
示例#2
0
def test_task_will_invoke_provided_class():
    def foo(): pass
    fake = Fake()
    fake.expects("__init__").with_args(foo)
    fudge.clear_calls()
    fudge.clear_expectations()

    foo = decorators.task(foo, task_class=fake)

    fudge.verify()
示例#3
0
def test_settings_read_attribute_with_no_section_returns_none():
    clear_expectations()

    fake_config = Fake("config")
    fake_config.expects("get").with_args("name", "setting_true_1").raises(NoSectionError("name"))
    fake_config.next_call("get").with_args("name", "setting_true_2").raises(NoOptionError("name", "setting_true_2"))

    ss = SettingsSection(None, "name", fake_config)
    assert not ss.as_bool("setting_true_1")
    assert not ss.as_bool("setting_true_2")
示例#4
0
def test_task_passes_args_to_the_task_class():
    random_vars = ("some text", random.randint(100, 200))
    def foo(): pass

    fake = Fake()
    fake.expects("__init__").with_args(foo, *random_vars)
    fudge.clear_calls()
    fudge.clear_expectations()

    foo = decorators.task(foo, task_class=fake, *random_vars)
    fudge.verify()
示例#5
0
def test_settings_read_attribute_as_bool():
    clear_expectations()

    fake_config = Fake("config")
    fake_config.expects("get").with_args("name", "setting_true_1").returns("True")
    fake_config.next_call("get").with_args("name", "setting_true_2").returns("true")
    fake_config.next_call("get").with_args("name", "setting_false_1").returns("False")
    fake_config.next_call("get").with_args("name", "setting_false_2").returns("false")

    ss = SettingsSection(None, "name", fake_config)
    assert ss.as_bool("setting_true_1")
    assert ss.as_bool("setting_true_2")
    assert not ss.as_bool("setting_false_1")
    assert not ss.as_bool("setting_false_2")
示例#6
0
def test_healthcheck_action_returns_working_if_no_text_in_config():
    clear_expectations()
    clear()

    settings_health_check.Ion = Fake('Ion')
    settings_health_check.Ion.healthcheck_text = None

    fake_server_health_check = Fake('server')
    fake_server_health_check.expects('test_connection').returns(True)

    controller = Controller()
    controller.server = fake_server_health_check

    assert controller.healthcheck() == "WORKING"
示例#7
0
def test_healthcheck_action():
    clear_expectations()
    clear()

    settings_health_check.Ion = Fake('Ion')
    settings_health_check.Ion.healthcheck_text = "CUSTOMTEXT"

    fake_server_health_check = Fake('server')
    fake_server_health_check.expects('test_connection').returns(True)

    controller = Controller()
    controller.server = fake_server_health_check

    assert controller.healthcheck() == "CUSTOMTEXT"
示例#8
0
    def test_chained_fakes_honor_order(self):
        Thing = Fake("thing").remember_order().expects("__init__")
        holder = Thing.expects("get_holder").returns_fake()
        holder = holder.expects("init")

        thing = Thing()
        holder = thing.get_holder()
        # missing thing.init()
        fudge.verify()
示例#9
0
    def test_chained_fakes_honor_order(self):
        Thing = Fake("thing").remember_order().expects("__init__")
        holder = Thing.expects("get_holder").returns_fake()
        holder = holder.expects("init")

        thing = Thing()
        holder = thing.get_holder()
        # missing thing.init()
        fudge.verify()
示例#10
0
def test_healthcheck_action_fails_if_database_not_found():
    clear_expectations()
    clear()

    settings_health_check.Ion = Fake('Ion')
    settings_health_check.Ion.healthcheck_text = None

    fake_server_health_check = Fake('server')
    controller = Controller()
    controller.server = fake_server_health_check

    fake_server_health_check.expects('test_connection').returns(False)
    fake_server_health_check.test_connection_error = ValueError('Fake error')

    try:
        controller.healthcheck()
    except RuntimeError, err:
        assert str(err) == "The connection to the database failed with error: Fake error"
        return
示例#11
0
def test_route_decorator_registers_route_with_custom_name():
    clear_expectations()
    clear()
    class TestController(Controller):
        @route("/something", name="named_route")
        def SomeAction(self):
            pass

    assert TestController.__routes__

    assert TestController.__routes__[0][0] == 'named_route'
    assert TestController.__routes__[0][1]['route'] == '/something'
    assert TestController.__routes__[0][1]['method'] == 'SomeAction'

dispatcher = Fake("dispatcher")
dispatcher.expects("connect").with_args("test_SomeAction", "/something", controller=arg.any_value(), action="SomeAction")
@with_fakes
def test_register_routes():
    clear_expectations()
    clear()

    class TestController(Controller):
        @route("/something")
        def SomeAction(self):
            pass

    ctrl = TestController()

    ctrl.register_routes(dispatcher)

template_context = Fake('context').has_attr(settings=Fake('settings'))
示例#12
0
文件: test_db.py 项目: heynemann/ion
@with_patched_object(Db, "connstr", fake_conn_str)
def test_disconnecting_from_not_connected_raises():
    clear_expectations()

    db = Db(connection_context)

    try:
        db.disconnect()
    except RuntimeError, err:
        assert str(err) == "You have to connect before disconnecting"
        return

    assert False, "Should not have gotten this far"

closable_session = Fake('closable_session')
closable_session.expects('close')

@with_fakes
@with_patched_object(db, "create_engine", fake_create_engine)
@with_patched_object(db, "session", closable_session)
@with_patched_object(Db, "connstr", fake_conn_str)
def test_disconnection_calls_close():
    clear_expectations()

    db = Db(connection_context)

    db.connect()
    db.disconnect()
    assert not db.is_connected

@with_fakes