Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@db_session
def test_create(self):
"""Test create episode"""
series = Series(name='test')
episode = Episode(
series=series,
season=1,
number=2,
name='test',
)
commit()
Episode.get().should.be.equal(episode)
@db_session
def test_delete_item(self):
item = Item[self.item.id]
assert_in(item, Item.select()[:])
res = self.client.delete("/api/v1/items/{0}".format(self.item.id))
assert_not_in(self.item, Item.select())
def setUp(self):
db.create_tables()
# create some items
with db_session:
self.person = Person(firstname="Steve", lastname="Loria")
self.person2 = Person(firstname="Monty", lastname="Python")
self.item = Item(name="Foo", person=self.person)
self.item2 = Item(name="Bar")
@db_session
def test_canonicalize_tracker_state(self):
ts = self.mds.TrackerState(url='http://tracker.tribler.org:80/announce/')
self.assertEqual(self.mds.TrackerState.get(url='http://tracker.tribler.org/announce'), ts)
@orm.db_session
def _get_asset(file_path):
""" Get the database record for an asset file """
record = model.Image.get(file_path=file_path)
fingerprint = ','.join((utils.file_fingerprint(file_path),
str(RENDITION_VERSION)))
if not record or record.fingerprint != fingerprint:
# Reindex the file
LOGGER.info("Updating image %s -> %s", file_path, fingerprint)
# compute the md5sum; from https://stackoverflow.com/a/3431838/318857
md5 = hashlib.md5()
md5.update(bytes(RENDITION_VERSION))
with open(file_path, 'rb') as file:
for chunk in iter(lambda: file.read(16384), b""):
md5.update(chunk)
@orm.db_session
@tornado.web.authenticated
def post(self):
action = self.get_argument('action', None)
if action != "read":
return
user_id = force_int(self.get_argument('user_id', 0), 0)
current_user = self.current_user
user = User.get(id=user_id)
if not user:
return self.send_error(404)
message_box = current_user.get_message_box(user=user)
if not message_box:
return self.send_error(404)
message_box.status = 1
return self.send_success_result(msg="已读")
return
if len(leaves) > 1 and not fail_fast:
# Merge required
questioner = InteractiveMigrationQuestioner()
if questioner.ask_merge(leaves):
# not tested?
merge(graph=graph, leaves=leaves)
show_migrations(fail_fast=True)
return
return
leaf = leaves[0]
migrations = leaf.forwards_list()
names = [m.name for m in migrations]
try:
with orm.db_session:
orm.exists(m for m in db.Migration)
except orm.core.DatabaseError as ex:
print('No Migration table. Please apply the initial migration.')
return
saved = orm.select((m.name, m.applied) for m in db.Migration if m.name in names).order_by(2)[:]
if saved:
saved, _ = zip(*saved)
for name in saved:
print('+ {}'.format(name))
for name in names:
if name in saved:
continue
print(' {}'.format(name))
@classmethod
@orm.db_session
def send_notification(cls, user_id):
logging.info("Notification send")
if user_id not in cls.users:
return
user = User[user_id]
if not user:
return
data = {
"count": user.unread_notification_count,
}
wss = cls.users[user_id]
for ws in wss:
try:
ws.send('notification', **data)
except Exception, e:
logging.error(e)
@db_session
def highscores(year=None, month=None, day=None, week=None):
mode = "all_time"
title = "All Time"
subtitle = None
dt, f = None, None
today = datetime.datetime.utcnow().date()
r = today # dummy for filter lambdas
# daily highscores
if year and month and day:
mode = "day"
dt = datetime.date(year, month, day)
f = lambda: r.start_time.date() == dt
title = dt.strftime("%B %d, %Y")
@db_session
def user(self):
return User[self.user_id]