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
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."""
85
self.clock.advance(self.timer.delay/0.8)
86
self.clock.advance(self.timer.delay / 0.8)
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)
91
def test_active(self):
92
"""The timer is active until the delay is reached."""
94
self.assertTrue(self.timer.active)
95
self.clock.advance(self.timer.delay + 1)
96
self.assertFalse(self.timer.active)
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
330
def test_popup_shows_notification(self):
331
"""The popup callback shows notifications."""
332
self.bubble.new_file_found()
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()
343
message = self.aggregator.build_discovery_message()
344
notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
345
self.assertIn(notification, self.get_notifications_shown())
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())
355
def test_popup_shows_no_notification_before_connection_made(self):
356
"""The popup callback shows notifications."""
357
self.bubble.new_file_found()
359
message = self.aggregator.build_discovery_message()
360
notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
361
self.assertNotIn(notification, self.get_notifications_shown())
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()
369
message = self.aggregator.build_discovery_message()
370
notification = (aggregator.UBUNTUONE_TITLE, message, None, False)
371
self.assertNotIn(notification, self.get_notifications_shown())
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]
481
524
"""The progressbar value is changed."""
482
525
self.progress = value
484
def show_warning_emblem(self):
485
"""Show a warning emblem."""
486
self.emblem_visible = True
488
def hide_emblem(self):
489
"""Hide the current emblem."""
490
self.emblem_visible = False
493
528
class FakeInhibitor(object):
494
529
"""A fake session inhibitor."""
613
648
inhibitor = yield d
614
649
self.assertEqual(inhibitor.flags, 0)
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)
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)
631
652
class FakeDelayedBuffer(object):
632
653
"""Appends all status pushed into a list."""
830
856
# msg did not receive a count argument
831
857
self.assertEqual(None, msg[2])
859
def test_already_subscribed_new_udf_available(self):
860
"""A new udf that was already subscribed."""
862
udf.subscribed = True
863
self.listener.handle_VM_UDF_CREATED(udf)
865
0, len(self.status_frontend.notification.notifications_shown))
867
0, len(self.status_frontend.messaging.messages_shown))
869
0, len(self.status_frontend.messaging.messages_updated))
833
871
def test_new_udf_available(self):
834
872
"""A new udf is available for subscription."""
908
945
self.assertFalse(self.status_frontend.aggregator.
909
946
notification_switch.enabled)
948
def test_udf_quota_exceeded(self): # pylint: disable=R0201
949
"""Quota exceeded in udf."""
951
launcher = mocker.replace(
952
"ubuntuone.platform.unity.UbuntuOneLauncher")
954
mock_launcher = mocker.mock()
955
mocker.result(mock_launcher)
956
mock_launcher.set_urgent()
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)
964
0, len(self.status_frontend.notification.notifications_shown))
968
def test_root_quota_exceeded(self): # pylint: disable=R0201
969
"""Quota exceeded in root."""
971
launcher = mocker.replace(
972
"ubuntuone.platform.unity.UbuntuOneLauncher")
974
mock_launcher = mocker.mock()
975
mocker.result(mock_launcher)
976
mock_launcher.set_urgent()
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)
985
0, len(self.status_frontend.notification.notifications_shown))
989
def test_share_quota_exceeded(self):
990
"""Quota exceeded in share."""
992
launcher = mocker.replace(
993
"ubuntuone.platform.unity.UbuntuOneLauncher")
995
mock_launcher = mocker.mock()
996
mocker.result(mock_launcher)
997
mock_launcher.set_urgent()
999
mock_launcher = mocker.mock()
1000
mocker.result(mock_launcher)
1001
mock_launcher.set_urgent()
1003
SHARE_ID = 'fake share id'
1005
share = Share(volume_id=SHARE_ID)
1006
self.fakevm.volumes[SHARE_ID] = share
1007
self.listener.handle_SYS_QUOTA_EXCEEDED(SHARE_ID, BYTES)
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)
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)
1017
2, len(self.status_frontend.notification.notifications_shown))
912
1022
class StatusEventTestCase(TestCase):
913
1023
"""Test the status event class and children."""
1259
1375
self.assertEqual(0.0, self.aggregator.progress_bar.progress)
1260
1376
self.assertFalse(self.aggregator.progress_bar.visible)
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)
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)
1273
1379
class StatusGrouperTestCase(TestCase):
1274
1380
"""Tests for the group_statuses function."""