def setUp(self): super(RegisterWidgetTests, self).setUp() self.exc_infos = [] self.excs = [] self.backend = StubBackend() expected_facts = {'fact1': 'one', 'fact2': 'two', 'system': '', 'system.uuid': 'MOCKUUID'} self.facts = StubFacts(fact_dict=expected_facts) self.reg_info = RegisterInfo() self.rs = RegisterWidget(backend=self.backend, reg_info=self.reg_info) self.rs._screens[CHOOSE_SERVER_PAGE] = Mock() self.rs._screens[CHOOSE_SERVER_PAGE].index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].screens_index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].button_label = "Dummy" self.rs._screens[CHOOSE_SERVER_PAGE].apply.return_value = CREDENTIALS_PAGE
def setUp(self): super(RegisterWidgetTests, self).setUp() self.exc_infos = [] self.excs = [] self.backend = StubBackend() expected_facts = {'fact1': 'one', 'fact2': 'two', 'system': '', 'system.uuid': 'MOCKUUID'} self.facts = StubFacts(fact_dict=expected_facts) self.rs = RegisterWidget(self.backend, self.facts) self.rs._screens[CHOOSE_SERVER_PAGE] = Mock() self.rs._screens[CHOOSE_SERVER_PAGE].index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].button_label = "Dummy" self.rs._screens[CHOOSE_SERVER_PAGE].apply.return_value = \ CREDENTIALS_PAGE
class RegisterWidgetTests(SubManFixture): def setUp(self): super(RegisterWidgetTests, self).setUp() self.exc_infos = [] self.excs = [] self.backend = StubBackend() expected_facts = { 'fact1': 'one', 'fact2': 'two', 'system': '', 'system.uuid': 'MOCKUUID' } self.facts = StubFacts(fact_dict=expected_facts) self.reg_info = RegisterInfo() self.rs = RegisterWidget(backend=self.backend, reg_info=self.reg_info) self.rs._screens[CHOOSE_SERVER_PAGE] = Mock() self.rs._screens[CHOOSE_SERVER_PAGE].index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].screens_index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].button_label = "Dummy" self.rs._screens[ CHOOSE_SERVER_PAGE].apply.return_value = CREDENTIALS_PAGE def test_show(self): self.rs.initialize() def page_notify_handler(self, obj, param): page_after = obj.get_current_page() # NOTE: these exceptions are not in the nost test context, # so they don't actually fail nose try: self.assertEqual(page_after, 0) except Exception: self.exc_infos.append(sys.exc_info()) return self.correct_page = True self.gtk_quit() return False def error_handler(self, obj, msg, exc_info): page_after = self.rs.register_notebook.get_current_page() # NOTE: these exceptions are not in the nost test context, # so they don't actually fail nose try: self.assertEqual(page_after, 0) except Exception: self.exc_infos.append(sys.exc_info()) return self.correct_page = True self.gtk_quit() return False def emit_proceed(self): self.rs.emit('proceed') return False def emit_error(self): self.rs.emit('register-error', 'Some register error', None) return False # FIXME: unit tests for gtk is a weird universe def test_registration_error_returns_to_page(self): self.rs.initialize() self.correct_page = None self.rs.register_notebook.connect('notify::page', self.page_notify_handler) self.rs.connect('register-error', self.error_handler) ga_GObject.timeout_add(3000, self.gtk_quit_on_fail) ga_GObject.idle_add(self.emit_proceed) ga_GObject.idle_add(self.emit_error) # run till quit or timeout # if we get to the state we want we can call quit ga_Gtk.main() # If we saw any exceptions, raise them now so we fail nosetests for exc_info in self.exc_infos: six.reraise(*exc_info) self.assertTrue(self.correct_page) # if we got the right answer, go ahead and end gtk.main() def gtk_quit(self): ga_Gtk.main_quit() # End the main loop, but first add an exception to sys.exc_info so # the end of the tests can fail on it. def gtk_quit_on_fail(self): try: self.fail("registergui didn't get a signal before the timeout.") except Exception: self.exc_infos.append(sys.exc_info()) ga_Gtk.main_quit() def test_screen_history_empty(self): self.rs.initialize() self.assertTrue(self.rs.applied_screen_history.is_empty()) self.rs.apply_current_screen() self.assertFalse(self.rs.applied_screen_history.is_empty()) self.rs._pop_last_screen() self.assertTrue(self.rs.applied_screen_history.is_empty())
class RegisterWidgetTests(SubManFixture): def setUp(self): super(RegisterWidgetTests, self).setUp() self.exc_infos = [] self.excs = [] self.backend = StubBackend() expected_facts = {'fact1': 'one', 'fact2': 'two', 'system': '', 'system.uuid': 'MOCKUUID'} self.facts = StubFacts(fact_dict=expected_facts) self.reg_info = RegisterInfo() self.rs = RegisterWidget(backend=self.backend, reg_info=self.reg_info) self.rs._screens[CHOOSE_SERVER_PAGE] = Mock() self.rs._screens[CHOOSE_SERVER_PAGE].index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].screens_index = 0 self.rs._screens[CHOOSE_SERVER_PAGE].button_label = "Dummy" self.rs._screens[CHOOSE_SERVER_PAGE].apply.return_value = CREDENTIALS_PAGE def test_show(self): self.rs.initialize() def page_notify_handler(self, obj, param): page_after = obj.get_current_page() # NOTE: these exceptions are not in the nost test context, # so they don't actually fail nose try: self.assertEqual(page_after, 0) except Exception: self.exc_infos.append(sys.exc_info()) return self.correct_page = True self.gtk_quit() return False def error_handler(self, obj, msg, exc_info): page_after = self.rs.register_notebook.get_current_page() # NOTE: these exceptions are not in the nost test context, # so they don't actually fail nose try: self.assertEqual(page_after, 0) except Exception: self.exc_infos.append(sys.exc_info()) return self.correct_page = True self.gtk_quit() return False def emit_proceed(self): self.rs.emit('proceed') return False def emit_error(self): self.rs.emit('register-error', 'Some register error', None) return False # FIXME: unit tests for gtk is a weird universe def test_registration_error_returns_to_page(self): self.rs.initialize() self.correct_page = None self.rs.register_notebook.connect('notify::page', self.page_notify_handler) self.rs.connect('register-error', self.error_handler) ga_GObject.timeout_add(3000, self.gtk_quit_on_fail) ga_GObject.idle_add(self.emit_proceed) ga_GObject.idle_add(self.emit_error) # run till quit or timeout # if we get to the state we want we can call quit ga_Gtk.main() # If we saw any exceptions, raise them now so we fail nosetests for exc_info in self.exc_infos: six.reraise(*exc_info) self.assertTrue(self.correct_page) # if we got the right answer, go ahead and end gtk.main() def gtk_quit(self): ga_Gtk.main_quit() # End the main loop, but first add an exception to sys.exc_info so # the end of the tests can fail on it. def gtk_quit_on_fail(self): try: self.fail("registergui didn't get a signal before the timeout.") except Exception: self.exc_infos.append(sys.exc_info()) ga_Gtk.main_quit() def test_screen_history_empty(self): self.rs.initialize() self.assertTrue(self.rs.applied_screen_history.is_empty()) self.rs.apply_current_screen() self.assertFalse(self.rs.applied_screen_history.is_empty()) self.rs._pop_last_screen() self.assertTrue(self.rs.applied_screen_history.is_empty())