コード例 #1
0
ファイル: test_database.py プロジェクト: Alwnikrotikz/ardj
    def test_update(self):
        db.execute('DELETE FROM queue')
        row = db.execute('INSERT INTO queue (track_id, owner) VALUES (?, ?)', (1, 'ardj', ))
        self.assertEquals(row, 1)

        db.Open().update('queue', {'owner': 'test', 'id': row})
        tmp = db.fetchone('SELECT * FROM queue')
        self.assertEquals(tmp, (1, 1, 'test'))
コード例 #2
0
    def test_mark_recent(self):
        for idx in range(200):
            row = db.execute('INSERT INTO tracks (title) VALUES (?)', (str(idx), ))
            db.execute("INSERT INTO labels (track_id, label, email) VALUES (?, 'music', 'test')", (row, ))

        db.Open().mark_recent_music()

        new = db.fetchone("SELECT COUNT(*) FROM tracks WHERE id IN (SELECT track_id FROM labels WHERE label = 'recent')")[0]
        old = db.fetchone("SELECT COUNT(*) FROM tracks WHERE id NOT IN (SELECT track_id FROM labels WHERE label = 'recent')")[0]

        self.assertEquals(200, new + old)
        self.assertEquals(100, new)
コード例 #3
0
ファイル: test_database.py プロジェクト: Alwnikrotikz/ardj
    def test_mark_recent(self):
        for idx in range(200):
            row = db.execute('INSERT INTO tracks (title) VALUES (?)', (str(idx), ))
            db.execute("INSERT INTO labels (track_id, label, email) VALUES (?, 'music', 'test')", (row, ))

        db.Open().mark_recent_music()

        new = db.fetchone("SELECT COUNT(*) FROM tracks WHERE id IN (SELECT track_id FROM labels WHERE label = 'recent')")[0]
        old = db.fetchone("SELECT COUNT(*) FROM tracks WHERE id NOT IN (SELECT track_id FROM labels WHERE label = 'recent')")[0]

        self.assertEquals(200, new + old)
        self.assertEquals(100, new)
コード例 #4
0
    def test_mark_liked_by(self):
        db.execute("DELETE FROM tracks")
        db.execute("DELETE FROM votes")
        db.execute("DELETE FROM labels")

        jids = ["*****@*****.**", "*****@*****.**", "*****@*****.**"]

        for idx in range(len(jids)):
            track_id = idx + 1
            db.execute("INSERT INTO tracks (id) VALUES (?)", (track_id, ))
            for jid in range(idx, len(jids)):
                db.execute("INSERT INTO votes (track_id, email, vote) VALUES (?, ?, ?)", (track_id, jids[jid], 1, ))

        count = ardj.tracks.add_label_to_tracks_liked_by("tmp", jids[1:], "test")
        self.assertEquals(2, count)

        rows = db.fetchcol("SELECT track_id FROM labels WHERE label = ?", ("tmp", ))
        self.assertEquals([1, 2], rows)
コード例 #5
0
ファイル: test_database.py プロジェクト: Alwnikrotikz/ardj
    def test_mark_liked_by(self):
        db.execute("DELETE FROM tracks")
        db.execute("DELETE FROM votes")
        db.execute("DELETE FROM labels")

        jids = ["*****@*****.**", "*****@*****.**", "*****@*****.**"]

        for idx in range(len(jids)):
            track_id = idx + 1
            db.execute("INSERT INTO tracks (id) VALUES (?)", (track_id, ))
            for jid in range(idx, len(jids)):
                db.execute("INSERT INTO votes (track_id, email, vote) VALUES (?, ?, ?)", (track_id, jids[jid], 1, ))

        count = ardj.tracks.add_label_to_tracks_liked_by("tmp", jids[1:], "test")
        self.assertEquals(2, count)

        rows = db.fetchcol("SELECT track_id FROM labels WHERE label = ?", ("tmp", ))
        self.assertEquals([1, 2], rows)
コード例 #6
0
    def test_sticky_labels(self):
        genres = ["rock", "jazz", "calm"]
        for genre in genres:
            for idx in range(10):
                track_id = database.execute(
                    "INSERT INTO tracks (weight, artist, filename) VALUES (1, 'somebody', 'dummy.mp3')"
                )
                database.execute(
                    "INSERT INTO labels (track_id, label, email) VALUES (?, ?, ?)",
                    (
                        track_id,
                        "music",
                        "-",
                    ))
                database.execute(
                    "INSERT INTO labels (track_id, label, email) VALUES (?, ?, ?)",
                    (
                        track_id,
                        genre,
                        "-",
                    ))
                logging.debug("track %u genre: %s" % (track_id, genre))

        logging.debug(database.fetch("SELECT * FROM labels"))

        playlist = {
            "name": "sticky",
            "labels": ["music"],
            "sticky_labels": genres,
        }

        sticky_label, track = self._pick_track(playlist, genres)
        logging.debug("Picked first track %u with labels: %s, sticky=%s" %
                      (track["id"], track.get_labels(), sticky_label))

        # Make sure 100 tracks follow this rule.
        for idx in range(100):
            new_label, track = self._pick_track(playlist, genres)
            self.assertEquals(new_label, sticky_label)
コード例 #7
0
ファイル: test_tracks.py プロジェクト: Alwnikrotikz/ardj
    def test_sticky_labels(self):
        genres = ["rock", "jazz", "calm"]
        for genre in genres:
            for idx in range(10):
                track_id = database.execute(
                    "INSERT INTO tracks (weight, artist, filename) VALUES (1, 'somebody', 'dummy.mp3')"
                )
                database.execute(
                    "INSERT INTO labels (track_id, label, email) VALUES (?, ?, ?)",
                    (
                        track_id,
                        "music",
                        "-",
                    ))
                database.execute(
                    "INSERT INTO labels (track_id, label, email) VALUES (?, ?, ?)",
                    (
                        track_id,
                        genre,
                        "-",
                    ))
                logging.debug("track %u genre: %s" % (track_id, genre))

        logging.debug(database.fetch("SELECT * FROM labels"))

        playlist = {
            "name": "sticky",
            "labels": ["music"],
            "sticky_labels": genres,
        }

        sticky_label, track = self._pick_track(playlist, genres)
        logging.debug("Picked first track %u with labels: %s, sticky=%s" %
                      (track["id"], track.get_labels(), sticky_label))

        # Make sure 100 tracks follow this rule.
        for idx in range(100):
            new_label, track = self._pick_track(playlist, genres)
            self.assertEquals(new_label, sticky_label)
コード例 #8
0
    def test_mark_orphans(self):
        t1 = db.execute('INSERT INTO tracks (title, weight) VALUES (NULL, 1)')
        db.execute('INSERT INTO labels (track_id, label, email) VALUES (?, \'music\', \'nobody\')', (t1, ))
        t2 = db.execute('INSERT INTO tracks (title, weight) VALUES (NULL, 1)')
        db.execute('INSERT INTO labels (track_id, label, email) VALUES (?, \'foobar\', \'nobody\')', (t2, ))

        if not db.Open().mark_orphans(quiet=True):
            self.fail('database.mark_orphans() failed to find tracks.')

        rows = db.fetch('SELECT track_id FROM labels WHERE label = \'orphan\'')
        self.assertEquals(1, len(rows), 'one track must have been labelled orphan, not %u' % len(rows))
        self.assertEquals(t2, rows[0][0], 'wrong track labelled orphan')
コード例 #9
0
ファイル: test_database.py プロジェクト: Alwnikrotikz/ardj
    def test_mark_orphans(self):
        t1 = db.execute('INSERT INTO tracks (title, weight) VALUES (NULL, 1)')
        db.execute('INSERT INTO labels (track_id, label, email) VALUES (?, \'music\', \'nobody\')', (t1, ))
        t2 = db.execute('INSERT INTO tracks (title, weight) VALUES (NULL, 1)')
        db.execute('INSERT INTO labels (track_id, label, email) VALUES (?, \'foobar\', \'nobody\')', (t2, ))

        if not db.Open().mark_orphans(quiet=True):
            self.fail('database.mark_orphans() failed to find tracks.')

        rows = db.fetch('SELECT track_id FROM labels WHERE label = \'orphan\'')
        self.assertEquals(1, len(rows), 'one track must have been labelled orphan, not %u' % len(rows))
        self.assertEquals(t2, rows[0][0], 'wrong track labelled orphan')
コード例 #10
0
 def tearDown(self):
     database.execute("DELETE FROM tracks")
     database.execute("DELETE FROM labels")
コード例 #11
0
 def test_queue(self):
     db.execute('INSERT INTO queue (track_id, owner) VALUES (?, ?)', (0, 'test', ))
     self.assertEquals(1, db.fetchone('SELECT COUNT(*) FROM queue')[0], 'Failed to insert a record into queue.')
コード例 #12
0
ファイル: test_tracks.py プロジェクト: Alwnikrotikz/ardj
 def tearDown(self):
     database.execute("DELETE FROM tracks")
     database.execute("DELETE FROM labels")
コード例 #13
0
ファイル: test_database.py プロジェクト: Alwnikrotikz/ardj
 def test_queue(self):
     db.execute('INSERT INTO queue (track_id, owner) VALUES (?, ?)', (0, 'test', ))
     self.assertEquals(1, db.fetchone('SELECT COUNT(*) FROM queue')[0], 'Failed to insert a record into queue.')
コード例 #14
0
ファイル: users.py プロジェクト: umonkey/ardj
def merge_aliased_votes():
    """Moves votes from aliases to real jids."""
    for k, v in get_aliases().items():
        for alias in v:
            database.execute("UPDATE votes SET email = ? WHERE email = ?", (k, alias, ))
    database.commit()