示例#1
0
    def set_top_results(self, update: Update,
                        context: CallbackContext) -> None:
        assert update.effective_message is not None  # for mypy, real check is in decorator

        chat_id = update.effective_message.chat_id
        value = self.sanitize_digit(context.args, 3, 10)

        if value != -1:
            is_same = SearchConfigs.check_if_same_value(chat_id, value, "n")
            if is_same:
                update.effective_message.reply_text(
                    TextRepo.MSG_SAME_VALUE.format(value))
                return
            SearchConfigs.set_user_cfg(chat_id, value, "n")
            update.effective_message.reply_text(
                TextRepo.MSG_SET_FIRST_N.format(value))
示例#2
0
def test_chek_if_same_value():
    assert SearchConfigs.check_if_same_value(1, 5, 'n')
    assert SearchConfigs.check_if_same_value(1, 1, 'm')
    assert not SearchConfigs.check_if_same_value(1, 999, 'n')
    assert not SearchConfigs.check_if_same_value(1, 999, 'm')

    assert SearchConfigs.check_if_same_value(2, 10, 'n')
    assert SearchConfigs.check_if_same_value(2, 30, 'm')
    assert not SearchConfigs.check_if_same_value(2, 999, 'n')
    assert not SearchConfigs.check_if_same_value(2, 999, 'm')

    assert SearchConfigs.check_if_same_value(3, 3, 'n')
    assert SearchConfigs.check_if_same_value(3, 90, 'm')
    assert not SearchConfigs.check_if_same_value(3, 999, 'n')
    assert not SearchConfigs.check_if_same_value(3, 999, 'm')

    with pytest.raises(ValueError):
        SearchConfigs.check_if_same_value(1, 5, 'w')