Ejemplo n.º 1
0
    def test_save_outside_transaction(self):
        self._db.begin()
        self._db.set_value('four', 'five')
        self._db.commit()

        new_db = Database('test_db.csv')
        self.assertEqual('five', new_db.get_value('four'))
Ejemplo n.º 2
0
    def test_save_inside_transaction(self):
        self._db.begin()
        self._db.set_value('four', 'five')
        self._db.save()

        new_db = Database('test_db.csv')
        self.assertIsNone(new_db.get_value('five'))
 def setUp(self):
     application = Flask(__name__)
     application.config['TESTING'] = True
     application.secret_key = 'you will not guess'
     application.permanent_session_lifetime = timedelta(seconds=1)
     self.application = application
     # Use an in memory database
     self.database = Database("sqlite://", 1, 0)
     self.session_manager = SessionStorage(self.database)
Ejemplo n.º 4
0
def main():
    db.drop_all()
    db.create_all()

    for row in clean_data:
        new_row = Database(rank=row[0],
                           company=row[1],
                           country=row[2],
                           percentage=row[3],
                           link=row[4])
        db.session.add(new_row)
        db.session.commit()
Ejemplo n.º 5
0
	def __init__(self, **kwargs):
		super().__init__(**kwargs)
		self.INTERFACE = Builder.load_file('main.kv')
		self.database = Database()

		menu_items = [{"text":f"item {i}"} for i in range(50)]
		self.menu = MDDropdownMenu(
            caller=self.INTERFACE.ids.refCommande,
            items=menu_items,
            position="center",
            width_mult=8,
        )
		self.menu.bind(on_release=self.set_item)
Ejemplo n.º 6
0
 def setUp(self):
     data = [
         ['foo', 'bar'],
         ['biz', 'baz'],
         ['spam', 'eggs'],
         ['bar', 'foo'],
         ['bat', 'foo'],
     ]
     f = open('test_db.csv', 'w')
     f.write('\n'.join(f'{key},{value}' for key, value in data))
     f.close()
     self._db = Database('test_db.csv')
     super().setUp()
Ejemplo n.º 7
0
def handle_preferenced(message, markup):
    with Database() as db:
        pref = db.get_preferenced_directors(message.chat.id)
    if len(pref) < 1:
        bot.send_message(message.chat.id,
                         'Не знаю, что посоветовать(',
                         reply_markup=markup)
    else:
        films_list = []
        for dir in pref:
            films_list += parser.get_film_list_by_director_id(dir)
        random.shuffle(films_list)
        obtain_films_list(message, films_list)
Ejemplo n.º 8
0
def buttons_callback(call):
    with Database() as db:
        cur_pos = db.get_cur_search_pos(call.message.chat.id)
        search_data = db.get_search_data(call.message.chat.id)
    new_pos = cur_pos
    grade = 0
    if call.data == 'back':
        if cur_pos >= 1:
            new_pos -= 1
    elif call.data == 'fwd':
        if cur_pos < len(search_data) - 1:
            new_pos += 1
    elif call.data == 'like':
        grade = 1
    elif call.data == 'dis':
        grade = -1
    if new_pos != cur_pos:
        with Database() as db:
            db.change_cur_search_pos(call.message.chat.id, new_pos)
        keyboard = telebot.types.InlineKeyboardMarkup(4)
        key_back = telebot.types.InlineKeyboardButton('⬅',
                                                      callback_data='back')
        key_fwd = telebot.types.InlineKeyboardButton('➡', callback_data='fwd')
        key_like = telebot.types.InlineKeyboardButton('👍',
                                                      callback_data='like')
        key_dis = telebot.types.InlineKeyboardButton('👎', callback_data='dis')
        keyboard.add(key_back, key_fwd, key_like, key_dis)
        msg = 'Фильм: {}\nРейтинг: {}/10'.\
            format(search_data[new_pos][0], search_data[new_pos][1])
        bot.edit_message_text(msg,
                              call.message.chat.id,
                              call.message.message_id,
                              reply_markup=keyboard)
    elif grade != 0:
        title, rating, dir_id = search_data[cur_pos]
        with Database() as db:
            db.set_grade(call.message.chat.id, title, dir_id, grade)
Ejemplo n.º 9
0
def obtain_films_list(message, films_list):
    if not films_list:
        bot.send_message(
            message.chat.id, 'Что-то пошло не так. '
            'Попробуй позже (можно попробовать '
            'поменять VPN)')
        return
    with Database() as db:
        db.clear_search_data(message.chat.id)
        db.insert_search_data(message.chat.id, films_list)
    keyboard = telebot.types.InlineKeyboardMarkup(4)
    key_back = telebot.types.InlineKeyboardButton('⬅', callback_data='back')
    key_fwd = telebot.types.InlineKeyboardButton('➡', callback_data='fwd')
    key_like = telebot.types.InlineKeyboardButton('👍', callback_data='like')
    key_dis = telebot.types.InlineKeyboardButton('👎', callback_data='dis')
    keyboard.add(key_back, key_fwd, key_like, key_dis)
    msg = 'Фильм: {}\nРейтинг: {}/10'. \
        format(films_list[0][0], films_list[0][1])
    bot.send_message(message.chat.id, text=msg, reply_markup=keyboard)
Ejemplo n.º 10
0
 def setUp(self):
     self.database = Database("sqlite://", 1, 0)
     self.storage = EncryptedQuestionnaireStorage(self.database, "user_id", "user_ik", "pepper")
Ejemplo n.º 11
0
 def setUp(self):
     super().setUp()
     self.database = MagicMock(Database("sqlite://", 1, 0))
     self.jti_claim_storage = JtiClaimStorage(self.database)
Ejemplo n.º 12
0
    def test_save(self):
        self._db.set_value('four', 'five')
        self._db.save()

        new_db = Database('test_db.csv')
        self.assertEqual('five', new_db.get_value('four'))
Ejemplo n.º 13
0
 def setUp(self) -> None:
     self.db = Database()
Ejemplo n.º 14
0
def get_name(message):
    with Database() as db:
        db.add_user(message.chat.id, message.text)
    bot.send_message(message.chat.id, 'Привет, ' + message.text + '!')