487
487
yield self.action_queue.get_webclient(self.fake_iri)
488
488
self.assertEqual(calls[1]["context_factory"], fake_context)
490
def test_queue_music_delivery_results(self):
491
"""The music delivery results are queued."""
492
albums = ["fake", "list", "of", "albums"]
493
self.action_queue.music_delivery_results(albums)
494
expected = ('AQ_MUSIC_DELIVERY_RESULTS', {'purchased_albums': albums})
495
self.assertEqual([expected], self.action_queue.event_queue.events)
498
class MusicDeliveryLifeCycleTestCase(BasicTestCase):
499
"""Tests to check the lifecycle of the music delivery checks."""
501
def test_delivery_checker_initialization(self):
502
"""Check the initialization of the checker."""
503
self.assertEqual(self.action_queue.delivery_checker.action_queue,
506
def test_delivery_checker_started(self):
507
"""Check that the delivery checker is started on connection."""
509
self.patch(self.action_queue, "_lookup_srv", lambda: defer.Deferred())
510
self.patch(self.action_queue.delivery_checker, "start",
511
lambda: called.append(True))
512
self.action_queue.connect()
513
self.assertEqual(len(called), 1)
515
def test_delivery_checker_stopped(self):
516
"""Check that the delivery checker is stopped on disconnection."""
518
self.patch(self.action_queue.delivery_checker, "stop",
519
lambda: called.append(True))
520
self.action_queue._cleanup_connection_state()
521
self.assertEqual(len(called), 1)
524
FAKE_DELIVERY_RESPONSE = """{
525
"server_timestamp": 1234,
526
"purchased_albums": [{
527
"album_name": "7digital Essential: 50s Rock",
528
"cloud_delivery_status": "COMPLETED",
529
"timestamp_purchased": 1230,
530
"open_url": "http://one.ubuntu.com/......",
531
"tracks_udf_paths": [
532
"Bill Haley/7digital Essential: 50s Rock/Rock Around the Clock.mp3",
533
"Bo Diddley/7digital Essential: 50s Rock/I'm a Man.mp3",
534
"Buddy Holly/7digital Essential: 50s Rock/Little Baby.mp3",
535
"Chuck Berry/7digital Essential: 50s Rock/Johnny Be Good.mp3",
536
"Chuck Berry/7digital Essential: 50s Rock/Roll Over Beethoven.mp3",
537
"Chuck Berry/7digital Essential: 50s Rock/Sweet Little Rock&Roll.mp3",
538
"Eddie Cochran/7digital Essential: 50s Rock/Let's Get Together.mp3",
539
"Eddie Cochran/7digital Essential: 50s Rock/My Way.mp3",
540
"Elvis Presley/7digital Essential: 50s Rock/Blue Suede Shoes.mp3",
541
"Elvis Presley/7digital Essential: 50s Rock/Don't Be Cruel.mp3",
542
"Elvis Presley/7digital Essential: 50s Rock/Shake, Rattle and Roll.mp3"
548
class FakeAQ(object):
549
"""A fake action queue."""
551
def __init__(self, result=FAKE_DELIVERY_RESPONSE):
554
self.delivery_results = None
556
def webcall(self, *args, **kwargs):
557
"""A fake web call."""
558
self.called.append((args, kwargs))
559
response = action_queue.txweb.Response(self.result)
560
return defer.succeed(response)
562
def music_delivery_results(self, albums):
563
"""The music results are sent to the event queue."""
564
self.delivery_results = albums
567
class MusicDeliveryCheckerTestCase(TwistedTestCase):
568
"""Tests for the MusicDeliveryChecker."""
570
@defer.inlineCallbacks
571
def test_webservice_called_with_timestamp(self):
572
"""The webservice is called with the last server timestamp."""
574
checker = action_queue.MusicDeliveryChecker(fakeaq)
575
expected = ((action_queue.MusicDeliveryChecker.ALBUM_DELIVERY_IRI %
576
checker.last_server_timestamp,), {'method': 'GET'})
577
yield checker.check_api()
578
self.assertEqual(fakeaq.called, [expected])
580
@defer.inlineCallbacks
581
def test_new_server_timestamp_is_stored(self):
582
"""The webservice response is json parsed and the timestamp stored."""
584
checker = action_queue.MusicDeliveryChecker(fakeaq)
585
yield checker.check_api()
586
self.assertEqual(checker.last_server_timestamp, 1234)
588
@defer.inlineCallbacks
589
def test_event_queue_is_pushed(self):
590
"""The webservice response is pushed into the event queue."""
592
checker = action_queue.MusicDeliveryChecker(fakeaq)
593
yield checker.check_api()
594
self.assertEqual(len(fakeaq.delivery_results), 1)
491
597
class TestLoggingStorageClient(TwistedTestCase):
492
598
"""Tests for ensuring magic hash dont show in logs."""