Exemplo n.º 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))
Exemplo n.º 2
0
def test_set_user_cfg():
    SearchConfigs.set_user_cfg(1, 999, 'n')
    SearchConfigs.set_user_cfg(1, 99, 'm')

    assert SearchConfigs.get_user_show_first_n(1) == 999
    assert SearchConfigs.get_user_cfg(1).m == 99

    with pytest.raises(ValueError):
        SearchConfigs.set_user_cfg(1, 999, 'w')
Exemplo n.º 3
0
def run_before():
    SearchConfigs.DUMP_FOLDER = os.path.join(SRC_TEST_FOLDER, 'resources/usr_cfg_test')
    SearchConfigs.USERS_CFG_FILEPATH = os.path.join(SRC_TEST_FOLDER, 'resources/usr_cfg_test', 'users_cfg.json')
    SearchConfigs.set_user_cfg(1, 5, 'n')
    SearchConfigs.set_user_cfg(1, 1, 'm')
    SearchConfigs.set_user_cfg(2, 10, 'n')
    SearchConfigs.set_user_cfg(2, 30, 'm')
    SearchConfigs.set_user_cfg(3, 3, 'n')
    SearchConfigs.set_user_cfg(3, 90, 'm')

    yield
    SearchConfigs.reset_user_data()
    filelist = [f for f in os.listdir(SearchConfigs.DUMP_FOLDER)]
    for f in filelist:
        os.remove(os.path.join(SearchConfigs.DUMP_FOLDER, f))
Exemplo n.º 4
0
def test_dump_data():
    one_hashed = sha1(bytes(1)).hexdigest()
    two_hashed = sha1(bytes(2)).hexdigest()

    SearchConfigs.dump_data()

    SearchConfigs.set_user_cfg(1, 10, 'n')
    SearchConfigs.set_user_cfg(1, 20, 'm')
    SearchConfigs.set_user_cfg(2, 30, 'n')
    SearchConfigs.set_user_cfg(2, 40, 'm')

    SearchConfigs.dump_data()

    SearchConfigs.set_user_cfg(1, 999, 'n')
    SearchConfigs.set_user_cfg(1, 998, 'm')
    SearchConfigs.set_user_cfg(2, 111, 'n')
    SearchConfigs.set_user_cfg(2, 112, 'm')

    assert SearchConfigs.get_user_show_first_n(1) == 999
    assert SearchConfigs.get_user_show_min_threshold(1) == 998

    assert SearchConfigs.get_user_show_first_n(2) == 111
    assert SearchConfigs.get_user_show_min_threshold(2) == 112

    SearchConfigs.init_data()

    assert SearchConfigs.get_user_show_first_n(1) == 10
    assert SearchConfigs.get_user_show_min_threshold(1) == 20

    assert SearchConfigs.get_user_show_first_n(2) == 30
    assert SearchConfigs.get_user_show_min_threshold(2) == 40