def shipping(message): chatIDs.append(cd.cooldownTime(message.chat.id, message.date)) users = db.get_data() rnd = random.randint(0, db.get_count() - 1) left_dog_hand = users[rnd][1] rnd = random.randint(0, db.get_count() - 1) right_dog_hand = users[rnd][1] bot.send_message(message.chat.id, "Море волнуется раз") bot.send_message(message.chat.id, "Море волнуется два") bot.send_message(message.chat.id, "Море волнуется три") bot.send_message( message.chat.id, "И в любовной паре замирают " + left_dog_hand + " + " + right_dog_hand + " = ♥️") text.out_white( convertTime(message.date) + " | " + message.from_user.first_name + " " + message.from_user.last_name + ": " + left_dog_hand + " + " + right_dog_hand + " = <3")
def on_short_link_details(self, request, short_id): link_target = get_url(self.redis, short_id) if not link_target: NotFound() click_count = get_count(self.redis, short_id) return self.render_template( "short_link_details.html", link_target=link_target, short_id=short_id, click_count=click_count, )
def on_short_link_details(self, request, short_id): url = get_url(self.redis, short_id) if not url: return NotFound() click_count = get_count(self.redis, short_id) return self.render_template( "short_link_details.html", link_target=url.decode('utf-8'), short_id=short_id, click_count=click_count, )
def test_locking_increment_race(self): def erroring_locking_increment(): # Trying to get a lock when the other thread has it will cause a # CouldNotLock exception - catch it here or the test will fail with self.assertRaises(db.CouldNotLock): incrmnt.locking_increment() with before_after.after('incrmnt.db.get_count', erroring_locking_increment): incrmnt.locking_increment() count = db.get_count() self.assertEqual(count, 1)
def test_locking_increment_race(self): def erroring_locking_increment(): # Trying to get a lock when the other thread has it will cause a # CouldNotLock exception - catch it here or the test will fail with self.assertRaises(db.CouldNotLock): incrmnt.locking_increment() with before_after.after( 'incrmnt.db.get_count', erroring_locking_increment): incrmnt.locking_increment() count = db.get_count() self.assertEqual(count, 1)
def on_short_link_details(self, request, short_id): # TODO: Достать из базы запись о ссылке по ее ид (get_url) # если такого ид в базе нет то кинуть 404 (NotFount()) url = get_url(self.redis, short_id) if not url: return NotFound() click_count = get_count(self.redis, short_id) link_target = "/" return self.render_template( "short_link_details.html", link_target=link_target, short_id=short_id, click_count=click_count, )
def datatable(): if not request.is_json: abort(400, "Data not in JSON format!") return received = request.json try: draw = received['draw'] limit = received['length'] offset = received['start'] except KeyError: abort(400, description="Required parameters are missing!") return user_id = auth.get_session(request) data = db.get_all_records(g.dbhandle.cursor(), user_id, offset, limit) recordCount = db.get_count(g.dbhandle.cursor(),user_id) result = { 'draw': draw, 'recordsFiltered': recordCount, 'recordsTotal': recordCount, 'data': data } return jsonify(result)
def test_increment_race(self): with before_after.after('incrmnt.db.get_count', incrmnt.increment): incrmnt.increment() count = db.get_count() self.assertEqual(count, 1) # Should be 2
def test_sequential_increment(self): incrmnt.increment() incrmnt.increment() count = db.get_count() self.assertEqual(count, 2)
def test_increment(self): incrmnt.increment() count = db.get_count() self.assertEqual(count, 1)
session = db.get_session() while not STOP: try: username = QUEUE.get() get(username, session) QUEUE.task_done() except Exception as e: logger.error(str(e)) session.rollback() session.close() if __name__ == "__main__": count = 0 if db.get_count() == 0: while len(SEEDS): seed = SEEDS.pop() count += 1 QUEUE.put(seed) else: session = db.get_session() _add_seeds(session) for i in range(10): t = Thread(target=worker) t.daemon = True t.start() try: while True:
def test_count(): session = db.get_session(SESSION) assert_equal(0, db.get_count(session)) db.create_user(session, 'kevin') assert_equal(1, db.get_count(session))
def increment(): count = db.get_count() new_count = count + 1 db.set_count(new_count) return new_count