Beispiel #1
0
def test_get_user():
    bot = Minette(prepare_table=True)
    with bot.connection_provider.get_connection() as connection:
        # register user for test
        u = bot.user_store.get(
            channel="get_user_test", channel_user_id=user_id,
            connection=connection)
        u.name = "user channel"
        bot.user_store.save(u, connection)
        u_detail = bot.user_store.get(
            channel="get_user_test_detail", channel_user_id=user_id,
            connection=connection)
        u_detail.name = "user detail"
        bot.user_store.save(u_detail, connection)

        # without detail
        request = Message(
            text="hello", channel="get_user_test", channel_user_id=user_id)
        user = bot._get_user(request, connection)
        assert user.channel == "get_user_test"
        assert user.channel_user_id == user_id
        assert user.name == "user channel"

        # with detail
        bot.config.confg_parser.set("minette", "user_scope", "channel_detail")
        request = Message(
            text="hello", channel="get_user_test", channel_detail="detail",
            channel_user_id=user_id)
        user = bot._get_user(request, connection)
        assert user.channel == "get_user_test_detail"
        assert user.channel_user_id == user_id
        assert user.name == "user detail"
Beispiel #2
0
def test_save_user():
    bot = Minette(prepare_table=True)
    with bot.connection_provider.get_connection() as connection:
        # register user for test
        u = bot.user_store.get(
            channel="save_user_test", channel_user_id=user_id,
            connection=connection)
        u.name = "Tomori Nao"

        # save
        bot._save_user(u, connection)

        # check
        request = Message(
            text="hello", channel="save_user_test", channel_user_id=user_id)
        user = bot._get_user(request, connection)
        assert user.channel == "save_user_test"
        assert user.channel_user_id == user_id
        assert user.name == "Tomori Nao"