~nataliabidart/ubuntuone-control-panel/subscribe

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/tests/test_gui.py

  • Committer: Tarmac
  • Author(s): natalia.bidart at canonical
  • Date: 2010-10-22 23:41:24 UTC
  • mfrom: (9.1.3 add-more-account)
  • Revision ID: natalia.bidart@canonical.com-20101022234124-bolu6hk9rvm7gcxx
Added information in account tab when retrieved from backend layer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
# pylint: disable=W0212
39
39
 
40
40
 
 
41
FAKE_ACCOUNT_INFO = {'type': 'Payed', 'name': 'Test me',
 
42
    'email': 'test.com', 'quota_total': '12345', 'quota_used': '9999'}
 
43
 
 
44
 
41
45
class FakedBuilder(gui.gtk.Builder):
42
46
    """A faked builder."""
43
47
 
423
427
    ui_filename = 'page.ui'
424
428
 
425
429
    def test_is_a_greyable_bin(self):
426
 
        """Inherits from gtk.VBox."""
 
430
        """Inherits from GreyableBin."""
427
431
        self.assertIsInstance(self.ui, gui.GreyableBin)
428
432
 
429
433
    def test_inner_widget_is_packed(self):
430
 
        """The 'itself' vbos is packed into the widget."""
 
434
        """The 'itself' vbox is packed into the widget."""
431
435
        self.assertIn(self.ui.itself, self.ui.get_children())
432
436
 
433
437
    def test_startup_visibility(self):
452
456
    ui_filename = 'overview.ui'
453
457
 
454
458
    def test_is_a_greyable_bin(self):
455
 
        """Inherits from gtk.VBox."""
 
459
        """Inherits from GreyableBin."""
456
460
        self.assertIsInstance(self.ui, gui.GreyableBin)
457
461
 
458
462
    def test_inner_widget_is_packed(self):
459
 
        """The 'itself' vbos is packed into the widget."""
 
463
        """The 'itself' vbox is packed into the widget."""
460
464
        self.assertIn(self.ui.itself, self.ui.get_children())
461
465
 
 
466
    def test_join_now_is_default(self):
 
467
        """The 'join_now' button is the default widget."""
 
468
        self.assertTrue(self.ui.join_now_button.get_property('can-default'))
 
469
 
462
470
    def test_sso_backend(self):
463
471
        """Has a correct SSO backend."""
464
472
        self.assertIsInstance(self.ui.sso_backend, FakedSSOBackend)
723
731
    messages = ['<small>Test me</small>', 'A <b>little</b> bit more']
724
732
 
725
733
 
 
734
class AccountTestCase(ControlPanelMixinTestCase):
 
735
    """The test suite for the account panel."""
 
736
 
 
737
    klass = gui.AccountPanel
 
738
    ui_filename = 'account.ui'
 
739
 
 
740
    def assert_account_info_correct(self, info):
 
741
        """Check that the displayed account info matches 'info'."""
 
742
        self.assertEqual(self.ui.name_label.get_text(),
 
743
                         FAKE_ACCOUNT_INFO['name'])
 
744
        self.assertEqual(self.ui.type_label.get_text(),
 
745
                         FAKE_ACCOUNT_INFO['type'])
 
746
        self.assertEqual(self.ui.email_label.get_text(),
 
747
                         FAKE_ACCOUNT_INFO['email'])
 
748
 
 
749
    def test_is_a_vbox(self):
 
750
        """Inherits from gtk.VBox."""
 
751
        self.assertIsInstance(self.ui, gui.gtk.VBox)
 
752
 
 
753
    def test_inner_widget_is_packed(self):
 
754
        """The 'itself' vbox is packed into the widget."""
 
755
        self.assertIn(self.ui.itself, self.ui.get_children())
 
756
 
 
757
    def test_is_visible(self):
 
758
        """Is visible."""
 
759
        self.assertTrue(self.ui.get_visible())
 
760
 
 
761
    def test_type_label_is_loading(self):
 
762
        """Placeholder for type label is a Loading widget."""
 
763
        self.assertIsInstance(self.ui.type_label, gui.LabelLoading)
 
764
        self.assertIn(self.ui.type_label, self.ui.type_box.get_children())
 
765
 
 
766
    def test_email_label_is_loading(self):
 
767
        """Placeholder for email label is a Loading widget."""
 
768
        self.assertIsInstance(self.ui.email_label, gui.LabelLoading)
 
769
        self.assertIn(self.ui.email_label, self.ui.email_box.get_children())
 
770
 
 
771
    def test_backend_signals(self):
 
772
        """The proper signals are connected to the backend."""
 
773
        self.assertEqual(self.ui.backend._signals['AccountInfoReady'],
 
774
                         [self.ui.on_account_info_ready])
 
775
        self.assertEqual(self.ui.backend._signals['AccountInfoError'],
 
776
                         [self.ui.on_account_info_error])
 
777
 
 
778
    def test_on_account_info_ready(self):
 
779
        """Account info is processed when ready."""
 
780
        self.ui.on_account_info_ready(FAKE_ACCOUNT_INFO)
 
781
        self.assert_account_info_correct(FAKE_ACCOUNT_INFO)
 
782
 
 
783
        for widget in (self.ui.name_label, self.ui.type_label,
 
784
                       self.ui.email_label):
 
785
            self.assertFalse(widget.active)
 
786
 
 
787
    def test_on_account_info_error(self):
 
788
        """Account info couldn't be retrieved."""
 
789
        self.ui.on_account_info_error()
 
790
        for widget in (self.ui.name_label, self.ui.type_label,
 
791
                       self.ui.email_label):
 
792
            self.assert_warning_correct(widget, self.ui.VALUE_ERROR)
 
793
            self.assertFalse(widget.active)
 
794
 
 
795
 
 
796
class ContactsTestCase(ControlPanelMixinTestCase):
 
797
    """The test suite for the contacts panel."""
 
798
 
 
799
    klass = gui.ContactsPanel
 
800
    ui_filename = 'contacts.ui'
 
801
 
 
802
    def test_is_a_vbox(self):
 
803
        """Inherits from gtk.VBox."""
 
804
        self.assertIsInstance(self.ui, gui.gtk.VBox)
 
805
 
 
806
    def test_inner_widget_is_packed(self):
 
807
        """The 'itself' vbox is packed into the widget."""
 
808
        self.assertIn(self.ui.itself, self.ui.get_children())
 
809
 
 
810
    def test_is_visible(self):
 
811
        """Is visible."""
 
812
        self.assertTrue(self.ui.get_visible())
 
813
 
 
814
 
 
815
class DevicesTestCase(ControlPanelMixinTestCase):
 
816
    """The test suite for the devices panel."""
 
817
 
 
818
    klass = gui.DevicesPanel
 
819
    ui_filename = 'devices.ui'
 
820
 
 
821
    def test_is_a_vbox(self):
 
822
        """Inherits from gtk.VBox."""
 
823
        self.assertIsInstance(self.ui, gui.gtk.VBox)
 
824
 
 
825
    def test_inner_widget_is_packed(self):
 
826
        """The 'itself' vbox is packed into the widget."""
 
827
        self.assertIn(self.ui.itself, self.ui.get_children())
 
828
 
 
829
    def test_is_visible(self):
 
830
        """Is visible."""
 
831
        self.assertTrue(self.ui.get_visible())
 
832
 
 
833
 
 
834
class ApplicationsTestCase(ControlPanelMixinTestCase):
 
835
    """The test suite for the applications panel."""
 
836
 
 
837
    klass = gui.ApplicationsPanel
 
838
    ui_filename = 'applications.ui'
 
839
 
 
840
    def test_is_a_vbox(self):
 
841
        """Inherits from gtk.VBox."""
 
842
        self.assertIsInstance(self.ui, gui.gtk.VBox)
 
843
 
 
844
    def test_inner_widget_is_packed(self):
 
845
        """The 'itself' vbox is packed into the widget."""
 
846
        self.assertIn(self.ui.itself, self.ui.get_children())
 
847
 
 
848
    def test_is_visible(self):
 
849
        """Is visible."""
 
850
        self.assertTrue(self.ui.get_visible())
 
851
 
 
852
 
726
853
class ManagementPanelTestCase(ControlPanelMixinTestCase):
727
854
    """The test suite for the management panel."""
728
855
 
729
856
    klass = gui.ManagementPanel
730
857
    ui_filename = 'management.ui'
731
 
    fake_account_info = {'type': 'Payed', 'name': 'Test me',
732
 
        'email': 'test.com', 'quota_total': '12345', 'quota_used': '9999'}
733
858
 
734
859
    def assert_account_info_correct(self, info):
735
860
        """Check that the displayed account info matches 'info'."""
742
867
                         self.ui.QUOTA_LABEL % expected)
743
868
 
744
869
    def test_is_a_vbox(self):
745
 
        """Inherits from gtk.Notebook."""
 
870
        """Inherits from gtk.VBox."""
746
871
        self.assertIsInstance(self.ui, gui.gtk.VBox)
747
872
 
748
873
    def test_startup_visibility(self):
751
876
                        'must be visible at startup.')
752
877
 
753
878
    def test_inner_widget_is_packed(self):
754
 
        """The 'itself' vbos is packed into the widget."""
 
879
        """The 'itself' vbox is packed into the widget."""
755
880
        self.assertIn(self.ui.itself, self.ui.get_children())
756
881
 
757
882
    def test_tabs_are_not_shown(self):
762
887
        """The default page is Account."""
763
888
        self.assertEqual(self.ui.notebook.get_current_page(),
764
889
                         self.ui.ACCOUNT_PAGE)
 
890
        self.assertTrue(self.ui.account_button.get_active())
765
891
 
766
892
    def test_buttons_set_notebook_pages(self):
767
893
        """The notebook pages are set when clicking buttons."""
774
900
            self.assertEqual(actual, expected,
775
901
                             msg % (expected, button, actual))
776
902
 
 
903
    def test_buttons_indicates_current_page(self):
 
904
        """Only one button is activated at a time."""
 
905
        msg = 'Only button %s should be active (%s was active as well).'
 
906
        for tab in self.ui.tabs:
 
907
            button = '%s_button' % tab
 
908
            getattr(self.ui, button).clicked()
 
909
            for other in self.ui.tabs:
 
910
                if other is tab:
 
911
                    continue
 
912
                active = getattr(self.ui, '%s_button' % other).get_active()
 
913
                self.assertFalse(active, msg % (button, other))
 
914
 
777
915
 
778
916
class ManagementPanelAccountTestCase(ManagementPanelTestCase):
779
917
    """The test suite for the management panel (account tab)."""
789
927
        """Account info is requested to the backend."""
790
928
        self.assert_backend_called('account_info', ())
791
929
 
 
930
    def test_account_panel_is_packed(self):
 
931
        """The account panel is packed."""
 
932
        self.assertIsInstance(self.ui.account, gui.AccountPanel)
 
933
        actual = self.ui.notebook.get_nth_page(self.ui.ACCOUNT_PAGE)
 
934
        self.assertTrue(self.ui.account is actual)
 
935
 
 
936
    def test_contacts_panel_is_packed(self):
 
937
        """The contacts panel is packed."""
 
938
        self.assertIsInstance(self.ui.contacts, gui.ContactsPanel)
 
939
        actual = self.ui.notebook.get_nth_page(self.ui.CONTACTS_PAGE)
 
940
        self.assertTrue(self.ui.contacts is actual)
 
941
 
 
942
    def test_devices_panel_is_packed(self):
 
943
        """The devices panel is packed."""
 
944
        self.assertIsInstance(self.ui.devices, gui.DevicesPanel)
 
945
        actual = self.ui.notebook.get_nth_page(self.ui.DEVICES_PAGE)
 
946
        self.assertTrue(self.ui.devices is actual)
 
947
 
 
948
    def test_applications_panel_is_packed(self):
 
949
        """The applications panel is packed."""
 
950
        self.assertIsInstance(self.ui.applications, gui.ApplicationsPanel)
 
951
        actual = self.ui.notebook.get_nth_page(self.ui.APPLICATIONS_PAGE)
 
952
        self.assertTrue(self.ui.applications is actual)
 
953
 
792
954
    def test_placeholders_are_loading(self):
793
955
        """Placeholders for labels are a Loading widget."""
794
956
        widgets = (self.ui.quota_label, self.ui.status_label)
798
960
 
799
961
    def test_on_account_info_ready(self):
800
962
        """Account info is processed when ready."""
801
 
        self.ui.on_account_info_ready(self.fake_account_info)
802
 
        self.assert_account_info_correct(self.fake_account_info)
 
963
        self.ui.on_account_info_ready(FAKE_ACCOUNT_INFO)
 
964
        self.assert_account_info_correct(FAKE_ACCOUNT_INFO)
803
965
 
804
966
        for widget in (self.ui.quota_label,):
805
967
            self.assertFalse(widget.active)