def test_update(self): ydl = self.FakeYoutubeDL({ 'https://www.youtube.com/channel/yt_id0/videos': { 'entries': ({ 'id': 'yt_id8', 'title': 'title6' }, ) }, 'https://www.youtube.com/channel/yt_id1/videos': { 'entries': ({ 'id': 'yt_id9', 'title': 'title7' }, { 'id': 'yt_id10', 'title': 'title8' }) } }) self.subs.update((), client=subs.Client(0, ydl)) c = self.conn.cursor() ret = { y for x in c.execute('select distinct last_update from subs') for y in x } self.assertEqual(ret, {int(self.now.timestamp())}) c.execute('select sub, yt_id, title from videos where id > 6') self.assertEqual( set(c), {(1, 'yt_id8', 'title6'), (2, 'yt_id9', 'title7'), (2, 'yt_id10', 'title8')})
def test_cache(self): last_update = int(self.now.timestamp()) - 1 c = self.conn.cursor() c.execute('update subs set last_update = ?', (last_update, )) self.subs.update((), cache=1, client=subs.Client(24 * 60, self.FakeYoutubeDL())) ret = min(y for x in c.execute('select distinct last_update from subs') for y in x) self.assertEqual(ret, last_update)
def test_no_updates(self): ydl = self.FakeYoutubeDL({ 'https://www.youtube.com/channel/yt_id0/videos': { 'entries': () }, 'https://www.youtube.com/channel/yt_id1/videos': { 'entries': () } }) self.subs.update((), client=subs.Client(0, ydl)) ret = min(y for x in self.conn.cursor().execute( 'select distinct last_update from subs') for y in x) self.assertNotEqual(ret, 0)
def test_last_video(self): c = self.conn.cursor() c.execute('update subs set last_video = ? where id = ?', (int(self.now.timestamp()), 2)) resp = { 'https://www.youtube.com/channel/yt_id1/videos': { 'entries': ({ 'id': 'yt_id8', 'title': 'title6' }, ) } } self.subs.update((), last_video=0, client=subs.Client(0, self.FakeYoutubeDL(resp))) c.execute('select count(*) from videos where sub == 2') self.assertEqual(c.fetchone()[0], 3)
def test_set_last_video(self): c = self.conn.cursor() last_video = lambda: \ c.execute('select id, last_video from subs').fetchall() self.assertEqual(last_video(), [(1, 0), (2, 0)]) resp = { 'https://www.youtube.com/channel/yt_id0/videos': { 'entries': ({ 'id': 'yt_id8', 'title': 'title6' }, ) }, 'https://www.youtube.com/channel/yt_id1/videos': { 'entries': () } } self.subs.update((), client=subs.Client(0, self.FakeYoutubeDL(resp))) self.assertEqual(last_video(), [(1, int(self.now.timestamp())), (2, 0)])
def test_tags(self): c = self.conn.cursor() c.executemany('insert into tags (name) values (?)', (('tag0', ), ('tag1', ))) c.executemany('insert into subs_tags (sub, tag) values (?, ?)', ((1, 1), (1, 2))) resp = { 'https://www.youtube.com/channel/yt_id0/videos': { 'entries': ({ 'id': 'yt_id8', 'title': 'title6' }, { 'id': 'yt_id9', 'title': 'title7' }) }, 'https://www.youtube.com/channel/yt_id1/videos': { 'entries': () } } self.subs.update((), client=subs.Client(0, self.FakeYoutubeDL(resp))) c.execute('select video, tag from videos_tags') self.assertEqual(c.fetchall(), [(7, 1), (7, 2), (8, 1), (8, 2)])