def test_should_persist_new_changes(self): cb = ComicMetadata(self.usr.user_id, 'foo/bar/baz.cbz') db.session.add(cb) db.session.commit() cb.last_page = 37 db.session.add(cb) db.session.commit() new_books = comic_query().filter_by(user_id=self.usr.user_id, book_relpath='foo/bar/baz.cbz').all() self.assertEquals(len(new_books), 1) self.assertEquals(new_books[0].last_page, 37)
def test_should_allow_one_record_per_user_per_book(self): cb1 = ComicMetadata(self.usr.user_id, 'foo/bar/baz.cbz') db.session.add(cb1) db.session.commit() cb2 = ComicMetadata(self.usr.user_id, 'foo/bar/baz.cbz') db.session.add(cb2) try: db.session.commit() self.assertTrue(False) except: db.session.rollback() self.assertTrue(True)
def update_page(): uid = current_user.user_id path = request.form.get('relpath') page = request.form.get('page') finished = request.form.get('finished') == 'true' fit_mode = request.form.get('fitmode') or "full" rtol = request.form.get('rtl') == 'true' dual = request.form.get('dual') == 'true' if path and uid and page: data = get_metadata(uid, path) if data is None: data = ComicMetadata(uid, path) data.last_access = datetime.now() data.last_page = page data.fit_mode = fit_mode data.right_to_left = rtol data.dual_page = dual if finished: data.finished_book = True try: save_object(data) return jsonify({'success': True}) except Exception as err: return jsonify({'success': False, 'error': str(err)}) return jsonify({'success': False, 'error': 'Missing data'})
def test_should_escape_relpath(self): c = ComicMetadata() c.book_relpath = os.path.join('foo', 'bar', 'baz.cbz') self.assertEquals('foo--bar--baz.cbz', c.disp_relpath() )
def test_should_get_base_path_as_name(self): c = ComicMetadata() c.book_relpath = 'foo/bar/baz.cbz' self.assertEquals('baz', c.book_name())
def test_should_get_nicer_date_format(self): c = ComicMetadata() c.last_access = datetime.datetime(2001, 2, 3, 4, 5, 6, 7) self.assertEquals(c.last_access_date(), '2001-02-03 04:05:06')
def test_should_set_relpath_on_create(self): cb = ComicMetadata(self.usr.user_id, 'foo/bar/baz.cbz') self.assertEquals(cb.book_relpath, 'foo/bar/baz.cbz')
def test_should_set_userid_on_create(self): cb = ComicMetadata(self.usr.user_id) self.assertEquals(cb.user_id, self.usr.user_id)