~didrocks/ubuntuone-client/dont-suffer-zg-crash

« back to all changes in this revision

Viewing changes to tests/status/test_aggregator.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes, Chris Coulson
  • Date: 2011-04-10 21:24:30 UTC
  • mfrom: (1.1.49 upstream)
  • Revision ID: james.westby@ubuntu.com-20110410212430-u9txrycw32fbt0x2
Tags: 1.6.0-0ubuntu1
* New upstream release.
  - Avoid conflict when same file already exists locally (LP: #711389)
  - Must move fils to trash on deletion (LP: #690673)
  - Support disconnection during initial connect attempt (LP: #711211)
  - Log version number on startup (LP: #715455)
  - Memory usage too high (LP: #721483)
  - Unsubscribed folders show as synced, if they exist (LP: #741835)
  - gnome-settings-daemon crash in g_str_hash (LP: #744383)
  - Should not re-queue uploads directly (LP: #744608)
  - No feedback when creating folder from symlink fails (LP: #747299)
  - [FFE] Use API to set urgency from background process (LP: #747677)
  - Open control panel to volumes when quota exceeded (LP: #702176)
  - Set the launcher to urgent when quota exceeded (LP: #702183)
  - nautilus crash in g_str_hash (LP: #724882)
  - Disable/enable file sync is buggy (LP: #744980)

[Chris Coulson]
* gnome-settings-daemon crash in g_return_fail_if_warning (LP: #744980)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from twisted.internet import defer
23
23
from twisted.internet.task import Clock
24
24
from twisted.trial.unittest import TestCase
 
25
from mocker import Mocker
25
26
 
26
27
from contrib.testing.testcase import BaseTwistedTestCase
27
28
from ubuntuone.devtools.handlers import MementoHandler
29
30
from ubuntuone.status.notification import AbstractNotification
30
31
from ubuntuone.status.messaging import AbstractMessaging
31
32
from ubuntuone.syncdaemon import status_listener
32
 
from ubuntuone.syncdaemon.volume_manager import Share, UDF
 
33
from ubuntuone.syncdaemon.volume_manager import Share, UDF, Root
33
34
 
34
35
FILENAME = 'example.txt'
35
36
FILENAME2 = 'another_example.mp3'
82
83
    def test_not_fired_if_reset_within_delay(self):
83
84
        """The timer is not fired if it is reset within the delay."""
84
85
        self.timer.reset()
85
 
        self.clock.advance(self.timer.delay/0.8)
 
86
        self.clock.advance(self.timer.delay / 0.8)
86
87
        self.timer.reset()
87
 
        self.clock.advance(self.timer.delay/0.8)
 
88
        self.clock.advance(self.timer.delay / 0.8)
88
89
        self.assertTrue(self.timer.called)
89
90
 
 
91
    def test_active(self):
 
92
        """The timer is active until the delay is reached."""
 
93
        self.timer.reset()
 
94
        self.assertTrue(self.timer.active)
 
95
        self.clock.advance(self.timer.delay + 1)
 
96
        self.assertFalse(self.timer.active)
 
97
 
90
98
 
91
99
class DeadlineTimerTestCase(TimerTestCase):
92
100
    """Test the DeadlineTimer class."""
327
335
        """The list of notifications shown."""
328
336
        return self.bubble.notification.notifications_shown
329
337
 
330
 
    def test_popup_shows_notification(self):
331
 
        """The popup callback shows notifications."""
332
 
        self.bubble.new_file_found()
333
 
        self.bubble._popup()
334
 
        message = self.aggregator.build_discovery_message()
335
 
        notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
336
 
        self.assertIn(notification, self.get_notifications_shown())
 
338
    def test_popup_shows_notification_when_connected(self):
 
339
        """The popup callback shows notifications."""
 
340
        self.bubble.connection_made()
 
341
        self.bubble.new_file_found()
 
342
        self.bubble._popup()
 
343
        message = self.aggregator.build_discovery_message()
 
344
        notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
 
345
        self.assertIn(notification, self.get_notifications_shown())
 
346
 
 
347
    def test_popup_shows_notification_after_connected(self):
 
348
        """The popup callback shows notifications."""
 
349
        self.bubble.new_file_found()
 
350
        self.bubble.connection_made()
 
351
        message = self.aggregator.build_discovery_message()
 
352
        notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
 
353
        self.assertIn(notification, self.get_notifications_shown())
 
354
 
 
355
    def test_popup_shows_no_notification_before_connection_made(self):
 
356
        """The popup callback shows notifications."""
 
357
        self.bubble.new_file_found()
 
358
        self.bubble._popup()
 
359
        message = self.aggregator.build_discovery_message()
 
360
        notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
 
361
        self.assertNotIn(notification, self.get_notifications_shown())
 
362
 
 
363
    def test_popup_shows_no_notification_after_connection_lost(self):
 
364
        """The popup callback shows notifications."""
 
365
        self.bubble.connection_made()
 
366
        self.bubble.connection_lost()
 
367
        self.bubble.new_file_found()
 
368
        self.bubble._popup()
 
369
        message = self.aggregator.build_discovery_message()
 
370
        notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
 
371
        self.assertNotIn(notification, self.get_notifications_shown())
337
372
 
338
373
    def test_notification_is_logged_in_debug(self):
339
374
        """The notification is printed in the debug log."""
 
375
        self.bubble.connection_made()
340
376
        self.bubble.new_file_found()
341
377
        self.bubble._popup()
342
378
        msg = "notification shown: %s" % self.get_notifications_shown()[0][1]
349
385
 
350
386
    def test_bubble_is_shown_after_delay(self):
351
387
        """The bubble is shown after a delay."""
 
388
        self.bubble.connection_made()
352
389
        self.bubble.new_file_found()
353
390
        self.clock.advance(self.initial_delay)
354
391
        self.assertEqual(1, len(self.get_notifications_shown()))
362
399
 
363
400
    def test_bubble_shown_if_timeout_exceeded(self):
364
401
        """The bubble is shown if the timeout is exceeded."""
 
402
        self.bubble.connection_made()
365
403
        self.bubble.new_file_found()
366
404
        count = int(self.initial_timeout / self.smaller_delay) + 1
367
405
        for n in range(count):
382
420
 
383
421
    def test_update_state(self):
384
422
        """When the gathering state finishes, the update state is started."""
 
423
        self.bubble.connection_made()
385
424
        self.bubble.new_file_found()
386
425
        self.clock.advance(self.initial_delay)
387
426
        self.assertEqual(type(self.bubble.state),
389
428
 
390
429
    def test_sleeping_state(self):
391
430
        """When the update state finishes, the sleeping state is started."""
 
431
        self.bubble.connection_made()
392
432
        self.bubble.new_file_found()
393
433
        self.clock.advance(self.initial_delay)
394
434
        self.clock.advance(self.updates_timeout)
397
437
 
398
438
    def test_back_to_initial_state(self):
399
439
        """When the last state finishes, we return to the idle state."""
 
440
        self.bubble.connection_made()
400
441
        self.bubble.new_file_found()
401
442
        self.clock.advance(self.initial_delay)
402
443
        self.clock.advance(self.updates_timeout)
406
447
 
407
448
    def test_new_files_found_while_updating_not_shown_immediately(self):
408
449
        """New files found in the updating state are not shown immediately."""
 
450
        self.bubble.connection_made()
409
451
        self.bubble.new_file_found()
410
452
        self.clock.advance(self.initial_delay)
411
453
        self.bubble.new_file_found()
413
455
 
414
456
    def test_new_files_found_while_updating_are_shown_after_a_delay(self):
415
457
        """New files found in the updating state are shown after a delay."""
 
458
        self.bubble.connection_made()
416
459
        self.bubble.new_file_found()
417
460
        self.clock.advance(self.initial_delay)
418
461
        self.bubble.new_file_found()
421
464
 
422
465
    def test_update_modifies_notification(self):
423
466
        """The update callback updates notifications."""
 
467
        self.bubble.connection_made()
424
468
        self.bubble.new_file_found()
425
469
        self.bubble._popup()
426
470
        self.bubble.new_file_found()
431
475
 
432
476
    def test_update_is_logged_in_debug(self):
433
477
        """The notification is logged when _update is called."""
 
478
        self.bubble.connection_made()
434
479
        self.bubble.new_file_found()
435
480
        self.bubble._popup()
436
481
        self.bubble.new_file_found()
466
511
 
467
512
    progress_visible = False
468
513
    progress = 0.0
469
 
    emblem_visible = False
470
 
    emblem = None
471
514
 
472
515
    def show_progressbar(self):
473
516
        """The progressbar is shown."""
481
524
        """The progressbar value is changed."""
482
525
        self.progress = value
483
526
 
484
 
    def show_warning_emblem(self):
485
 
        """Show a warning emblem."""
486
 
        self.emblem_visible = True
487
 
 
488
 
    def hide_emblem(self):
489
 
        """Hide the current emblem."""
490
 
        self.emblem_visible = False
491
 
 
492
527
 
493
528
class FakeInhibitor(object):
494
529
    """A fake session inhibitor."""
613
648
        inhibitor = yield d
614
649
        self.assertEqual(inhibitor.flags, 0)
615
650
 
616
 
    def test_show_warning_emblem(self):
617
 
        """The warning emblem is shown."""
618
 
        self.bar.hide_emblem()
619
 
        self.bar.show_warning_emblem()
620
 
        self.assertTrue(self.bar.emblem_visible)
621
 
        self.assertTrue(self.bar.launcher.emblem_visible)
622
 
 
623
 
    def test_hide_emblem(self):
624
 
        """The emblem is hidden."""
625
 
        self.bar.show_warning_emblem()
626
 
        self.bar.hide_emblem()
627
 
        self.assertFalse(self.bar.emblem_visible)
628
 
        self.assertFalse(self.bar.launcher.emblem_visible)
629
 
 
630
651
 
631
652
class FakeDelayedBuffer(object):
632
653
    """Appends all status pushed into a list."""
663
684
    def __init__(self):
664
685
        """Initialize this instance."""
665
686
        self.volumes = {}
 
687
        self.root = None
666
688
 
667
689
    def get_volume(self, volume_id):
668
690
        """Return a volume given its id."""
677
699
        self.queued_commands = set()
678
700
        self.notification_switch = aggregator.NotificationSwitch()
679
701
        self.connected = False
 
702
        self.clock = PatchedClock()
680
703
        self.files_uploading = []
681
704
        self.files_downloading = []
682
705
 
722
745
class StatusFrontendTestCase(BaseTwistedTestCase):
723
746
    """Test the status frontend."""
724
747
 
 
748
    def _fake_popunder(self):
 
749
        self.popunders += 1
 
750
 
725
751
    def setUp(self):
726
752
        """Initialize this test instance."""
727
753
        BaseTwistedTestCase.setUp(self)
830
856
        # msg did not receive a count argument
831
857
        self.assertEqual(None, msg[2])
832
858
 
 
859
    def test_already_subscribed_new_udf_available(self):
 
860
        """A new udf that was already subscribed."""
 
861
        udf = UDF()
 
862
        udf.subscribed = True
 
863
        self.listener.handle_VM_UDF_CREATED(udf)
 
864
        self.assertEqual(
 
865
            0, len(self.status_frontend.notification.notifications_shown))
 
866
        self.assertEqual(
 
867
            0, len(self.status_frontend.messaging.messages_shown))
 
868
        self.assertEqual(
 
869
            0, len(self.status_frontend.messaging.messages_updated))
 
870
 
833
871
    def test_new_udf_available(self):
834
872
        """A new udf is available for subscription."""
835
873
        udf = UDF()
851
889
        # msg did receive a count argument
852
890
        self.assertEqual(1, msg[2])
853
891
        # call callback
854
 
        print msg
855
892
        msg[0]('fake_indicator')
856
893
        self.assertEqual(1, len(self.status_frontend.messaging.callbacks))
857
894
 
908
945
        self.assertFalse(self.status_frontend.aggregator.
909
946
                         notification_switch.enabled)
910
947
 
 
948
    def test_udf_quota_exceeded(self):  # pylint: disable=R0201
 
949
        """Quota exceeded in udf."""
 
950
        mocker = Mocker()
 
951
        launcher = mocker.replace(
 
952
            "ubuntuone.platform.unity.UbuntuOneLauncher")
 
953
        launcher()
 
954
        mock_launcher = mocker.mock()
 
955
        mocker.result(mock_launcher)
 
956
        mock_launcher.set_urgent()
 
957
        mocker.replay()
 
958
        UDF_ID = 'fake udf id'
 
959
        udf = UDF(volume_id=UDF_ID)
 
960
        self.fakevm.volumes[UDF_ID] = udf
 
961
        self.listener.handle_SYS_QUOTA_EXCEEDED(
 
962
            volume_id=UDF_ID, free_bytes=0)
 
963
        self.assertEqual(
 
964
            0, len(self.status_frontend.notification.notifications_shown))
 
965
        mocker.restore()
 
966
        mocker.verify()
 
967
 
 
968
    def test_root_quota_exceeded(self):  # pylint: disable=R0201
 
969
        """Quota exceeded in root."""
 
970
        mocker = Mocker()
 
971
        launcher = mocker.replace(
 
972
            "ubuntuone.platform.unity.UbuntuOneLauncher")
 
973
        launcher()
 
974
        mock_launcher = mocker.mock()
 
975
        mocker.result(mock_launcher)
 
976
        mock_launcher.set_urgent()
 
977
        mocker.replay()
 
978
        ROOT_ID = 'fake root id'
 
979
        root = Root(volume_id=ROOT_ID)
 
980
        self.fakevm.volumes[ROOT_ID] = root
 
981
        self.fakevm.root = root
 
982
        self.listener.handle_SYS_QUOTA_EXCEEDED(
 
983
            volume_id=ROOT_ID, free_bytes=0)
 
984
        self.assertEqual(
 
985
            0, len(self.status_frontend.notification.notifications_shown))
 
986
        mocker.restore()
 
987
        mocker.verify()
 
988
 
 
989
    def test_share_quota_exceeded(self):
 
990
        """Quota exceeded in share."""
 
991
        mocker = Mocker()
 
992
        launcher = mocker.replace(
 
993
            "ubuntuone.platform.unity.UbuntuOneLauncher")
 
994
        launcher()
 
995
        mock_launcher = mocker.mock()
 
996
        mocker.result(mock_launcher)
 
997
        mock_launcher.set_urgent()
 
998
        launcher()
 
999
        mock_launcher = mocker.mock()
 
1000
        mocker.result(mock_launcher)
 
1001
        mock_launcher.set_urgent()
 
1002
        mocker.replay()
 
1003
        SHARE_ID = 'fake share id'
 
1004
        BYTES = 0
 
1005
        share = Share(volume_id=SHARE_ID)
 
1006
        self.fakevm.volumes[SHARE_ID] = share
 
1007
        self.listener.handle_SYS_QUOTA_EXCEEDED(SHARE_ID, BYTES)
 
1008
        self.assertEqual(
 
1009
            1, len(self.status_frontend.notification.notifications_shown))
 
1010
        self.listener.handle_SYS_QUOTA_EXCEEDED(SHARE_ID, BYTES)
 
1011
        self.listener.handle_SYS_QUOTA_EXCEEDED(SHARE_ID, BYTES)
 
1012
        self.assertEqual(
 
1013
            1, len(self.status_frontend.notification.notifications_shown))
 
1014
        self.status_frontend.aggregator.clock.advance(aggregator.ONE_DAY + 1)
 
1015
        self.listener.handle_SYS_QUOTA_EXCEEDED(SHARE_ID, BYTES)
 
1016
        self.assertEqual(
 
1017
            2, len(self.status_frontend.notification.notifications_shown))
 
1018
        mocker.restore()
 
1019
        mocker.verify()
 
1020
 
911
1021
 
912
1022
class StatusEventTestCase(TestCase):
913
1023
    """Test the status event class and children."""
1033
1143
    def cleanup(self):
1034
1144
        """Cleanup this instance."""
1035
1145
 
 
1146
    def connection_made(self):
 
1147
        """Connection made."""
 
1148
 
 
1149
    def connection_lost(self):
 
1150
        """Connection lost."""
 
1151
 
1036
1152
 
1037
1153
class FakeFinalBubble(object):
1038
1154
    """A fake FinalStatusBubble."""
1259
1375
        self.assertEqual(0.0, self.aggregator.progress_bar.progress)
1260
1376
        self.assertFalse(self.aggregator.progress_bar.visible)
1261
1377
 
1262
 
    def test_connection_lost(self):
1263
 
        """The connection to the server was lost."""
1264
 
        self.status_frontend.server_connection_lost()
1265
 
        self.assertTrue(self.aggregator.progress_bar.emblem_visible)
1266
 
 
1267
 
    def test_connection_made(self):
1268
 
        """The connection to the server was made."""
1269
 
        self.status_frontend.server_connection_made()
1270
 
        self.assertFalse(self.aggregator.progress_bar.emblem_visible)
1271
 
 
1272
1378
 
1273
1379
class StatusGrouperTestCase(TestCase):
1274
1380
    """Tests for the group_statuses function."""
1303
1409
        clock = PatchedClock()
1304
1410
        upload = FakeCommand(path='upload.foo')
1305
1411
        sf = aggregator.StatusFrontend(clock=clock)
 
1412
        sf.server_connection_made()
1306
1413
        sf.set_show_all_notifications(True)
1307
1414
 
1308
1415
        # the progress bar is not visible yet