예제 #1
0
def update(request,channel_id):
    clock = Clock(logger=logger)
    clock.start()
    if request.GET.get('mode'):
        mode = request.GET['mode']
    else:
        mode = 'full'
    queue = QueueManager(channel = channel_id)
    backgrounds,backgrounds_directory = __get_backgrounds()
    now_playing_data = __get_playing(channel_id)

    if mode == 'full':        
        update = {
                    "queue":queue.getQueue(),
                    "current_background":get_current_background(channel = channel_id),
                    "backgrounds":backgrounds,
                    "now_playing":now_playing_data
                }
    elif mode == 'player':   
        update = {
                    "queue":queue.getQueue(),
                    "current_background":get_current_background(channel = channel_id),
                    "backgrounds":backgrounds,
                    "now_playing":now_playing_data
                }


    logger.info("Update %s returned in %f seconds" % (mode,clock.stop()))
    return HttpResponse(json.dumps(update))
예제 #2
0
class TestSequenceFunctions(TestCase):
    def setUp(self):
        user = User.objects.create(username='******')
        user.save()

        channel = Channel(creator=user)
        channel.save()

        self.queue = QueueManager(channel=channel.id)

    def test_db_connection(self):
        print "Test 1"
        self.assertIsNotNone(self.queue.get_db())

    def test_check_initial_emptiness(self):
        print "Test 2"
        self.assertEqual(len(self.queue.getQueue()), 0)

    def test_add_item(self):
        print "Test 2"

        self.queue.add(url="tGiEsjtfJdg", creator="127.0.0.1")
        self.assertEqual(len(self.queue.getQueue()), 1)

    def test_rm_item(self):
        print "Test 3"

        self.queue.rm(url="tGiEsjtfJdg")
        self.assertEqual(len(self.queue.getQueue()), 0)

    def test_uniqueness(self):
        print "Test 4"

        self.queue.add(url="tGiEsjtfJdg", creator="127.0.0.1")
        self.queue.add(url="tGiEsjtfJdg", creator="127.0.0.1")
        self.queue.add(url="tGiEsjtfJdg", creator="127.0.0.2")
        self.assertEqual(len(self.queue.getQueue()), 1)

    def test_next_video(self):
        print "Test 5"

        self.queue.add(url="tGiEsjtfJdg", creator="127.0.0.1")
        self.queue.add(url="XFwVfrAURDg", creator="127.0.0.1")
        self.queue.add(url="EfuVcRdamCY", creator="127.0.0.1")
        self.queue.add(url="4pRPAbCwgSs", creator="127.0.0.1")
        count = 0
        added = []

        self.assertEqual(len(self.queue.getQueue()), 4)
        self.assertEqual(self.queue.next(), "tGiEsjtfJdg")
        self.assertEqual(len(self.queue.getQueue()), 3)
        self.assertEqual(self.queue.next(), "XFwVfrAURDg")
        self.assertEqual(len(self.queue.getQueue()), 2)
        self.assertEqual(self.queue.next(), "EfuVcRdamCY")
        self.assertEqual(len(self.queue.getQueue()), 1)
        self.assertEqual(self.queue.next(), "4pRPAbCwgSs")
        self.assertEqual(len(self.queue.getQueue()), 0)
        self.assertIsNone(self.queue.next())

    def test_votes(self):
        print "Test 6"
        added = []

        # Asserts that it cant register a vote to something that isn't there
        self.assertFalse(
            self.queue.register_vote(url="dummy",
                                     positive=1,
                                     negative=0,
                                     creator="127.0.0.1"))

        # Asserts votes for queues of a single item
        self.assertEqual(self.queue.add(url="tGiEsjtfJdg",
                                        creator="127.0.0.1"),
                         (True, True))  #1,0
        self.assertEqual(self.queue.add(url="tGiEsjtfJdg",
                                        creator="127.0.0.1"),
                         (True, False))  #1,0
        elements = self.queue.getQueue()
        for element in elements:
            self.assertIsNotNone(element)
            self.assertEqual(element.get("positive"), 1)
            self.assertEqual(element.get("negative"), 0)

        self.assertTrue(
            self.queue.register_vote(
                url="tGiEsjtfJdg",  #2,0
                positive=1,
                negative=0,
                creator="127.0.0.2"))
        self.assertFalse(
            self.queue.register_vote(
                url="tGiEsjtfJdg",  #2,0
                positive=1,
                negative=0,
                creator="127.0.0.2"))

        elements = self.queue.getQueue()
        self.assertEqual(len(elements), 1)

        element = [x for x in elements if x.get("url") == "tGiEsjtfJdg"][0]
        self.assertIsNotNone(element)
        self.assertEqual(element.get("positive"), 2)
        self.assertEqual(element.get("negative"), 0)

        # Asserts votes for bigger queues
        self.queue.add(url="XFwVfrAURDg", creator="127.0.0.1")
        self.queue.add(url="EfuVcRdamCY", creator="127.0.0.1")
        self.queue.add(url="4pRPAbCwgSs", creator="127.0.0.1")

        self.assertIsNotNone(
            self.queue.register_vote(url="tGiEsjtfJdg",
                                     positive=0,
                                     negative=1,
                                     creator="127.0.0.2"))
        self.assertIsNotNone(
            self.queue.register_vote(url="XFwVfrAURDg",
                                     positive=1,
                                     negative=0,
                                     creator="127.0.0.2"))
        self.assertIsNotNone(
            self.queue.register_vote(url="EfuVcRdamCY",
                                     positive=1,
                                     negative=0,
                                     creator="127.0.0.2"))
        self.assertIsNotNone(
            self.queue.register_vote(url="4pRPAbCwgSs",
                                     positive=1,
                                     negative=0,
                                     creator="127.0.0.2"))

        elements = self.queue.getQueue()
        self.assertEqual(len(elements), 4)

        for element in elements:
            if element.get("url") == "tGiEsjtfJdg":
                self.assertEqual(element.get("positive"), 1)
                self.assertEqual(element.get("negative"), 1)
            elif element.get("url") == "XFwVfrAURDg":
                self.assertEqual(element.get("positive"), 2)
                self.assertEqual(element.get("negative"), 0)
            elif element.get("url") == "4pRPAbCwgSs":
                self.assertEqual(element.get("positive"), 2)
                self.assertEqual(element.get("negative"), 0)