Пример #1
0
def test_database_login_factory(monkeypatch):
    service_obj = pretend.stub()
    service_cls = pretend.call_recorder(
        lambda session, ratelimiters: service_obj)
    monkeypatch.setattr(services, "DatabaseUserService", service_cls)

    global_ratelimiter = pretend.stub()
    user_ratelimiter = pretend.stub()

    def find_service(iface, name, context):
        assert iface is IRateLimiter
        assert context is None
        assert name in {"global.login", "user.login"}

        return ({
            "global.login": global_ratelimiter,
            "user.login": user_ratelimiter
        }).get(name)

    context = pretend.stub()
    request = pretend.stub(db=pretend.stub(), find_service=find_service)

    assert services.database_login_factory(context, request) is service_obj
    assert service_cls.calls == [
        pretend.call(
            request.db,
            ratelimiters={
                "global": global_ratelimiter,
                "user": user_ratelimiter
            },
        )
    ]
Пример #2
0
def test_database_login_factory(monkeypatch, pyramid_services, metrics):
    service_obj = pretend.stub()
    service_cls = pretend.call_recorder(
        lambda session, ratelimiters, metrics: service_obj
    )
    monkeypatch.setattr(services, "DatabaseUserService", service_cls)

    global_ratelimiter = pretend.stub()
    user_ratelimiter = pretend.stub()

    def find_service(iface, name=None, context=None):
        if iface != IRateLimiter and name is None:
            return pyramid_services.find_service(iface, context=context)

        assert iface is IRateLimiter
        assert context is None
        assert name in {"global.login", "user.login"}

        return (
            {"global.login": global_ratelimiter, "user.login": user_ratelimiter}
        ).get(name)

    context = pretend.stub()
    request = pretend.stub(db=pretend.stub(), find_service=find_service)

    assert services.database_login_factory(context, request) is service_obj
    assert service_cls.calls == [
        pretend.call(
            request.db,
            metrics=metrics,
            ratelimiters={"global": global_ratelimiter, "user": user_ratelimiter},
        )
    ]
Пример #3
0
def test_database_login_factory(monkeypatch):
    service_obj = pretend.stub()
    service_cls = pretend.call_recorder(lambda session: service_obj)
    monkeypatch.setattr(services, "DatabaseUserService", service_cls)

    context = pretend.stub()
    request = pretend.stub(db=pretend.stub())

    assert services.database_login_factory(context, request) is service_obj
    assert service_cls.calls == [pretend.call(request.db)]
Пример #4
0
def test_database_login_factory(monkeypatch):
    service_obj = pretend.stub()
    service_cls = pretend.call_recorder(lambda session: service_obj)
    monkeypatch.setattr(services, "DatabaseLoginService", service_cls)

    context = pretend.stub()
    request = pretend.stub(db=pretend.stub())

    assert services.database_login_factory(context, request) is service_obj
    assert service_cls.calls == [pretend.call(request.db)]
Пример #5
0
def test_database_login_factory(monkeypatch, pyramid_services, metrics):
    service_obj = pretend.stub()
    service_cls = pretend.call_recorder(
        lambda session, ratelimiters, metrics: service_obj
    )
    monkeypatch.setattr(services, "DatabaseUserService", service_cls)

    global_login_ratelimiter = pretend.stub()
    user_login_ratelimiter = pretend.stub()
    ip_login_ratelimiter = pretend.stub()
    email_add_ratelimiter = pretend.stub()
    password_reset_ratelimiter = pretend.stub()

    def find_service(iface, name=None, context=None):
        if iface != IRateLimiter and name is None:
            return pyramid_services.find_service(iface, context=context)

        assert iface is IRateLimiter
        assert context is None
        assert name in {
            "global.login",
            "user.login",
            "ip.login",
            "email.add",
            "password.reset",
        }

        return (
            {
                "global.login": global_login_ratelimiter,
                "user.login": user_login_ratelimiter,
                "ip.login": ip_login_ratelimiter,
                "email.add": email_add_ratelimiter,
                "password.reset": password_reset_ratelimiter,
            }
        ).get(name)

    context = pretend.stub()
    request = pretend.stub(db=pretend.stub(), find_service=find_service)

    assert services.database_login_factory(context, request) is service_obj
    assert service_cls.calls == [
        pretend.call(
            request.db,
            metrics=metrics,
            ratelimiters={
                "global.login": global_login_ratelimiter,
                "user.login": user_login_ratelimiter,
                "ip.login": ip_login_ratelimiter,
                "email.add": email_add_ratelimiter,
                "password.reset": password_reset_ratelimiter,
            },
        )
    ]