def test_selfheal(self): """ SelfHeal service will replace deleted server """ sh_interval = float(os.environ["AS_SELFHEAL_INTERVAL"]) group, _ = self.helper.create_group(min_entities=1) yield group.start(self.rcs, self) yield group.wait_for_state(self.rcs, ContainsDict({"activeCapacity": Equals(1)})) # delete server OOB server_id = yield only_server_id(self.rcs, group) yield NovaServer(id=server_id, pool=self.helper.pool).delete(self.rcs) # Wait for new server to come back up by self heal service. It can # take 2 * selfheal interval because the new group may get scheduled # to be triggered after last scheduling is already setup yield group.wait_for_state( self.rcs, ContainsDict({ "active": MatchesListwise([ContainsDict({"id": NotEquals(server_id)})]) }), timeout=(sh_interval + convergence_exec_time) * 2) # Delete new server again and see if it comes back. It should be # back within selfheal interval server_id = yield only_server_id(self.rcs, group) yield NovaServer(id=server_id, pool=self.helper.pool).delete(self.rcs) yield group.wait_for_state( self.rcs, ContainsDict({ "active": MatchesListwise([ContainsDict({"id": NotEquals(server_id)})]) }), timeout=sh_interval + convergence_exec_time)
def test_quicklist_action_uses_startup_notification(self): """Tests that quicklist uses startup notification protocol.""" self.register_nautilus() self.addCleanup(self.close_all_windows, "Nautilus") self.process_manager.start_app_window("Calculator") self.process_manager.start_app(self.app_name) nautilus_icon = self.unity.launcher.model.get_icon( desktop_id="org.gnome.Nautilus.desktop") ql = self.open_quicklist_for_icon(nautilus_icon) de = self.get_desktop_entry("Nautilus") new_window_action_name = de.get("Name", group="Desktop Action Window", locale=True) self.assertThat(new_window_action_name, NotEquals(None)) new_win_ql_item_fn = lambda: ql.get_quicklist_item_by_text( new_window_action_name) self.assertThat(new_win_ql_item_fn, Eventually(NotEquals(None))) new_win_ql_item = new_win_ql_item_fn() ql.click_item(new_win_ql_item) nautilus_windows_fn = lambda: self.process_manager.get_open_windows_by_application( "Nautilus") self.assertThat(lambda: len(nautilus_windows_fn()), Eventually(Equals(1))) [nautilus_window] = nautilus_windows_fn() self.assertThat(new_win_ql_item.wait_until_destroyed, Not(Raises()))
def test_slider_buffers_activations(self): slider = self.indicator_page.get_slider() original_value = slider.value slider.slide_left() # will buffer change until it receives the change from server slider.slide_right() final_value = slider.value # backend will respond to first slider. Since it's a live slider # it'll probably be a random value along the slide. slider_menu = self.indicator_page.get_slider_menu() self.assertThat(slider_menu.serverValue, Eventually(NotEquals(original_value), timeout=20)) # It wont yet have reached the final value due to the buffering # Second activate should have gone out by now self.assertThat(slider_menu.serverValue, NotEquals(final_value)) # front-end should not change as a result of server update # while it is buffered self.assertThat(slider.value, Equals(final_value)) # server will respond to the second activate self.assertThat(slider_menu.serverValue, Eventually(Equals(final_value), timeout=20)) # make sure we've got the server value set. self.assertThat(slider.value, Equals(slider_menu.serverValue))
def test_hint_after_first_picture(self): hint = self.main_window.get_photo_roll_hint() photo_button = self.main_window.get_exposure_button() # Wait for the camera to be ready to take a picture self.assertThat(photo_button.enabled, Eventually(Equals(True))) self.assertThat(photo_button.width, Eventually(NotEquals(0))) self.assertThat(photo_button.height, Eventually(NotEquals(0))) # Check that the photo roll hint is hidden self.assertEquals(hint.visible, False) # Take a picture self.pointing_device.move_to_object(photo_button) self.pointing_device.click() # Check that the photo roll hint is displayed # self.assertEquals(hint.visible, True) self.assertThat(hint.visible, Eventually(Equals(True))) # Swipe to photo roll self.main_window.swipe_to_gallery(self) self.main_window.swipe_to_viewfinder(self) # Check that the photo roll hint is hidden self.assertEquals(hint.visible, False)
def test_change_searchengine(self): settings = self.open_settings() searchengine = settings.get_searchengine_entry() old_engine = searchengine.currentSearchEngineDisplayName self.assertThat(old_engine, NotEquals("")) self.pointing_device.click_object(searchengine) searchengine_page = settings.get_searchengine_page() self.assertThat( lambda: len( searchengine_page.select_many(objectName="searchEngineDelegate" )), Eventually(GreaterThan(1))) delegates = searchengine_page.select_many( objectName="searchEngineDelegate") delegates.sort(key=lambda delegate: delegate.objectName) new_index = -1 for (i, delegate) in enumerate(delegates): checkbox = delegate.select_single(uitk.CheckBox) if (new_index == -1) and not checkbox.checked: new_index = i self.assertThat(checkbox.checked, Equals(delegate.displayName == old_engine)) new_engine = delegates[new_index].displayName self.assertThat(new_engine, NotEquals(old_engine)) self.pointing_device.click_object(delegates[new_index].select_single( uitk.CheckBox)) searchengine_page.wait_until_destroyed() self.assertThat(searchengine.currentSearchEngineDisplayName, Eventually(Equals(new_engine)))
def keyboard_layout_page_tests(self, ): self._update_current_step('stepKeyboardConf') self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=True, skip_button=False) self._update_page_titles() logger.debug("run_keyboard_layout_page_tests()") logger.debug("Selecting the stepKeyboardCOnf page object") keyboard_page = self.main_window.select_single( GtkAlignment, BuilderName='stepKeyboardConf') treeviews = keyboard_page.select_many(GtkTreeView) # lets check all the keyboard tree items for the selected language # TODO: we should probably test at some point try changing the keyboard # layout to a different language/locale/layout and see if # ubiquity breaks for treeview in treeviews: items = treeview.get_all_items() for item in items: self.expectIsInstance( item.accessible_name, str, "[Page:'%r'] Expected %r item to be " "unicode but it wasn't" % (self.current_step, item.accessible_name)) self.expectThat( item.accessible_name, NotEquals(u''), "[Page:'{0}'] Tree view item found which " "didn't contain text, but it should!!") # now lets test typing with the keyboard layout entry = keyboard_page.select_single('GtkEntry') while True: text = u'Testing keyboard layout' with self.keyboard.focused_type(entry) as kb: kb.type(text) # check entry value is same length as text if len(entry.text) == len(text): # only test the entry value if we are using english install if self.english_install: self.expectThat(entry.text, Equals(text)) self.expectThat( entry.text, NotEquals(u''), "[Page:'{0}'] Expected Entry to contain text " "after typing but it didn't".format(self.current_step)) self.expectIsInstance( entry.text, str, "[Page:'{0}'] Expected Entry text to be " "unicode but it wasnt".format(self.current_step)) break # delete the entered text before trying again kb.press_and_release('Ctrl+a') kb.press_and_release('Delete') # TODO: Test detecting keyboard layout self._check_page_titles() self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=True, skip_button=False)
def test_start_app(self): """Ensure we can start an Application.""" app = self.process_manager.start_app('Calculator') self.assertThat(app, NotEquals(None)) # locale='C' does not work here as this goes through bamf, so we can't # assert the precise name self.assertThat(app.name, NotEquals('')) self.assertThat(app.desktop_file, Equals('gcalctool.desktop'))
class TestNotEqualsInterface(TestCase, TestMatchersInterface): matches_matcher = NotEquals(1) matches_matches = [2] matches_mismatches = [1] str_examples = [("NotEquals(1)", NotEquals(1)), ("NotEquals('1')", NotEquals('1'))] describe_examples = [("1 == 1", 1, NotEquals(1))]
def switch_recording_mode(self): record_control = self.get_record_control() # Wait for the camera overlay to be loaded record_control.enabled.wait_for(True) record_control.width.wait_for(NotEquals(0)) record_control.height.wait_for(NotEquals(0)) self.app.pointing_device.move_to_object(record_control) self.app.pointing_device.click()
def test_record_video(self): """Test clicking on the record control. Check if the recording time appears. """ # Get all the elements stop_watch = self.main_window.get_stop_watch() exposure_button = self.main_window.get_exposure_button() # Click the record button to toggle photo/video mode self.main_window.switch_recording_mode() # Before recording the stop watch should read zero recording time # and not be visible anyway. self.assertThat(stop_watch.opacity, Equals(0.0)) self.assertEquals(stop_watch.label, "00:00") # Click the exposure button to start recording self.pointing_device.move_to_object(exposure_button) self.assertThat(exposure_button.enabled, Eventually(Equals(True))) self.assertThat(exposure_button.width, Eventually(NotEquals(0))) self.assertThat(exposure_button.height, Eventually(NotEquals(0))) self.pointing_device.click() # Record video for 2 seconds and check if the stop watch actually # runs and is visible. # Since the timer is not precise we don't check the actual time, # just that it is not counting zero anymore. self.assertThat(stop_watch.opacity, Eventually(Equals(1.0))) self.assertThat(stop_watch.label, Eventually(NotEquals("00:00"))) # Now stop the video and check if everything resets itself to # previous states. self.pointing_device.click() self.assertThat(stop_watch.opacity, Eventually(Equals(0.0))) # Now start recording a second video and check if everything # still works self.pointing_device.click() # Is the stop watch visible and set to 00:00? self.assertEquals(stop_watch.label, "00:00") self.assertThat(stop_watch.opacity, Eventually(Equals(1.0))) # Record video for 2 seconds and check if the stop watch actually works self.assertThat(stop_watch.label, Eventually(NotEquals("00:00"))) # Now stop the video and go back to picture mode and check if # everything resets itself to previous states self.pointing_device.click() self.main_window.switch_recording_mode() self.assertThat(stop_watch.opacity, Eventually(Equals(0.0)))
class TestMatchesAllDictInterface(TestCase, TestMatchersInterface): matches_matcher = MatchesAllDict({'a': NotEquals(1), 'b': NotEquals(2)}) matches_matches = [3, 4] matches_mismatches = [1, 2] str_examples = [("MatchesAllDict({'a': NotEquals(1), 'b': NotEquals(2)})", matches_matcher)] describe_examples = [ ("""a: 1 == 1""", 1, matches_matcher), ]
def take_picture(self): exposure_button = self.main_window.get_exposure_button() # Wait for the camera to have finished focusing # (the exposure button gets enabled when ready) self.assertThat(exposure_button.enabled, Eventually(Equals(True))) self.assertThat(exposure_button.width, Eventually(NotEquals(0))) self.assertThat(exposure_button.height, Eventually(NotEquals(0))) # Press the shoot a picture button self.pointing_device.move_to_object(exposure_button) self.pointing_device.click()
def assert_space_item(self, object_name, text): """ Checks whether an space item exists and returns a value """ item = self.main_view.storage_page.wait_select_single( objectName=object_name) self.assertThat(item, NotEquals(None)) label = item.label # Label self.assertThat(label, Equals(text)) # Get item's label size_label = item.select_single(objectName='sizeLabel') self.assertThat(size_label, NotEquals(None)) values = size_label.text.split(' ') # Format: "00.0 (bytes|MB|GB)" self.assertThat(len(values), GreaterThan(1))
def test_equality_operator(self): fake_bus = object() addr1 = backends.DBusAddress(fake_bus, "conn", "path") self.assertThat(addr1, Equals(backends.DBusAddress(fake_bus, "conn", "path"))) self.assertThat( addr1, NotEquals(backends.DBusAddress(fake_bus, "conn", "new_path"))) self.assertThat( addr1, NotEquals(backends.DBusAddress(fake_bus, "conn2", "path"))) self.assertThat( addr1, NotEquals(backends.DBusAddress(object(), "conn", "path")))
def test_available_providers(self): """ Checks whether all the expected providers are available """ add_account_btn = self.app.select_single('GtkTextCellAccessible', accessible_name=u'Add account…') self.assertThat(add_account_btn, NotEquals(None)) self.mouse.move_to_object(add_account_btn) self.mouse.click() required_providers = [ 'FakeOAuth', ] for provider in required_providers: provider_item = self.app.select_single('GtkTextCellAccessible', accessible_name=provider) self.assertThat(add_account_btn, NotEquals(None))
def open_quicklist_with_keyboard(self): """Opens a quicklist using the keyboard.""" move_mouse_to_screen(0) self.ql_launcher.key_nav_start() self.addCleanup(self.ql_launcher.key_nav_cancel) self.ql_launcher.keyboard_select_icon(self.launcher_position, tooltip_text=self.ql_app.name) self.keybinding(keys[self.launcher_position + "/launcher/keynav/open-quicklist"]) self.addCleanup(self.keybinding, "launcher/keynav/close-quicklist") self.assertThat(self.ql_launcher_icon.get_quicklist, Eventually(NotEquals(None))) self.quicklist = self.ql_launcher_icon.get_quicklist() self.assertThat(lambda: self.quicklist.selected_item, Eventually(NotEquals(None)))
def _rebuild_and_check(self, content, broken_chunks_info, full_rebuild_pos, allow_frozen_container=False): rebuild_pos, rebuild_idx = full_rebuild_pos rebuild_chunk_info = broken_chunks_info[rebuild_pos][rebuild_idx] content.rebuild_chunk(rebuild_chunk_info["id"], allow_frozen_container=allow_frozen_container) # get the new structure of the content rebuilt_content = self.content_factory.get(self.container_id, content.content_id) # find the rebuilt chunk for c in rebuilt_content.chunks.filter(pos=rebuild_pos): if len(content.chunks.filter(id=c.id)) > 0: # not the rebuilt chunk # if this chunk is broken, it must not have been rebuilt for b_c_i in broken_chunks_info[rebuild_pos].values(): if c.id == b_c_i["id"]: with ExpectedException(NotFound): _, _ = self.blob_client.chunk_get(c.url) continue meta, stream = self.blob_client.chunk_get(c.url) self.assertEqual(meta["chunk_id"], c.id) self.assertEqual(md5_stream(stream), rebuild_chunk_info["dl_hash"]) self.assertEqual(c.checksum, rebuild_chunk_info["hash"]) self.assertThat(c.url, NotEquals(rebuild_chunk_info["url"])) del meta["chunk_id"] del rebuild_chunk_info["dl_meta"]["chunk_id"] self.assertEqual(meta, rebuild_chunk_info["dl_meta"])
def _test_rebuild(self, stgpol, data_size, broken_pos_list, full_rebuild_pos): data = random_data(data_size) content, broken_chunks_info = self._new_content( stgpol, data, broken_pos_list) rebuild_pos, rebuild_idx = full_rebuild_pos rebuild_chunk_info = broken_chunks_info[rebuild_pos][rebuild_idx] content.rebuild_chunk(rebuild_chunk_info["id"]) # get the new structure of the content rebuilt_content = self.content_factory.get(self.container_id, content.content_id) self.assertEqual(type(rebuilt_content), DupContent) # find the rebuilt chunk for c in rebuilt_content.chunks.filter(pos=rebuild_pos): if len(content.chunks.filter(id=c.id)) > 0: # not the rebuilt chunk # if this chunk is broken, it must not have been rebuilt for b_c_i in broken_chunks_info[rebuild_pos].values(): if c.id == b_c_i["id"]: with ExpectedException(NotFound): _, _ = self.blob_client.chunk_get(c.url) continue meta, stream = self.blob_client.chunk_get(c.url) self.assertEqual(meta["chunk_id"], c.id) self.assertEqual(md5_stream(stream), rebuild_chunk_info["dl_hash"]) self.assertEqual(c.hash, rebuild_chunk_info["hash"]) self.assertThat(c.url, NotEquals(rebuild_chunk_info["url"])) del meta["chunk_id"] del rebuild_chunk_info["dl_meta"]["chunk_id"] self.assertEqual(meta, rebuild_chunk_info["dl_meta"])
def test_record_flag_works(self): """Must be able to record videos when the -r flag is present.""" video_dir = mktemp() ap_dir = '/tmp/autopilot' video_session_pattern = '/tmp/rMD-session*' self.addCleanup(remove_if_exists, video_dir) self.addCleanup(remove_if_exists, '%s/Dummy_Description.ogv' % (ap_dir)) self.addCleanup(remove_if_exists, ap_dir) mock_test_case = Mock() mock_test_case.shortDescription.return_value = 'Dummy_Description' orig_sessions = glob.glob(video_session_pattern) video_logger = RMDVideoLogFixture(video_dir, mock_test_case) video_logger.setUp() video_logger._test_passed = False # We use Eventually() to avoid the case where recordmydesktop does not # create a file because it gets stopped before it's even started # capturing anything. self.assertThat(lambda: glob.glob(video_session_pattern), Eventually(NotEquals(orig_sessions))) video_logger._stop_video_capture(mock_test_case) self.assertTrue(os.path.exists(video_dir)) self.assertTrue( os.path.exists('%s/Dummy_Description.ogv' % (video_dir))) self.assertFalse(os.path.exists('%s/Dummy_Description.ogv' % (ap_dir)))
def test_bin_echo(self): # Try parsing a file without the pyelftools logic mocked out elf_file = elf.ElfFile(path=sys.executable) self.assertThat(elf_file.path, Equals(sys.executable)) # The arch attribute will be a tuple of three strings self.assertTrue(isinstance(elf_file.arch, tuple)) self.assertThat(len(elf_file.arch), Equals(3)) self.assertThat(elf_file.arch[0], StartsWith('ELFCLASS')) self.assertThat(elf_file.arch[1], StartsWith('ELFDATA')) self.assertThat(elf_file.arch[2], StartsWith('EM_')) # We expect Python to be a dynamic linked executable with an # ELF interpreter. self.assertTrue(isinstance(elf_file.interp, str)) self.assertThat(elf_file.interp, NotEquals('')) # Python is not a shared library, so has no soname self.assertThat(elf_file.soname, Equals('')) # We expect that Python will be linked to libc for lib in elf_file.needed.values(): if lib.name.startswith('libc.so'): break else: self.fail("Expected to find libc in needed library list") self.assertTrue(isinstance(lib.name, str)) for version in lib.versions: self.assertTrue(isinstance(version, str), "expected {!r} to be a string".format(version))
def _get_file_by_index(self, index): folder_list_page = self.app.main_view.get_folder_list_page() fileDelegate = lambda: folder_list_page.get_file_by_index(index) self.assertThat( fileDelegate, Eventually(NotEquals(None))) return folder_list_page.get_file_by_index(index)
def _check_object(self, obj_name, obj_visible=True): logger.debug("Checking {0} object.......".format(obj_name)) #select current page object page = self.main_window.select_single(BuilderName=self.current_step) #select object page_object = page.select_single(BuilderName=obj_name) if obj_visible: visible_message = "[Page:'{0}'] Expected {1} object to be " \ "visible but it wasn't".format(self.current_step, page_object.name) else: visible_message = "[Page:'{0}'] Expected {1} object to not be " \ "visible but it was!".format(self.current_step, page_object.name) self.expectThat(page_object.visible, Equals(obj_visible), visible_message) self.expectThat(page_object.label, NotEquals(u''), "[Page:'{0}'] Expected {1} objects label value to " "contain text but it didn't" .format(self.current_step, page_object.name)) self.expectIsInstance(page_object.label, str, "[Page:'{0}'] Expected {1} objects label " "value to be unicode but it wasn't" .format(self.current_step, page_object.name)) #we only want to test visible english values, hidden ones don't matter if (self.current_step in self.english_config) and obj_visible: if self.english_install and ( obj_name in self.english_config[self.current_step]): logger.debug( "Checking {0} object's english label value....".format( obj_name)) #if english install check english values self.expectThat(page_object.label, Equals( self.english_config[self.current_step][obj_name]))
def go_to_next_page(self, wait=False): """ Goes to the next page of Ubiquity installer Will timeout after 2 mins waiting for next page to appear. Params: wait: If set to true will wait for the buttons sensitive property to be true. Will timeout after 20mins. NOTE: this should only be used when clicking 'Install Now' the default 2 mins is sufficient for every other page switch """ logger.debug('go_to_next_page(wait={0})'.format(wait)) nxt_button = self.main_window.select_single('GtkButton', name='next') nxt_button.click() if wait: # This sleep just bridges a weird error when the next button, # sometimes flickers its sensitive property back to 1 once clicked # and then goes back to 0 time.sleep(2) # now take back over from the sleep and wait for sensitive to # become 1 logger.debug("Waiting for 'next' Button to become sensitive " "again.....") self.assertThat(nxt_button.sensitive, Eventually(Equals(True), timeout=1200)) page_title = self.main_window.select_single( 'GtkLabel', name='page_title') self.assertThat(page_title.label, Eventually(NotEquals(self.current_page_title), timeout=120))
def test_removing_location_via_list_item_action(self): """ tests removing a location via the list item action """ # Get the list item of the first location list_item = self.locations_page.get_location(0) # Check that the first location is London self.assertThat(list_item.get_name(), Equals("London")) # Remove the location via the list item action list_item.click_remove_action() # Check that the location was removed self.assertThat(self.home_page.get_location_count, Eventually(Equals(self.start_count - 1))) # Get the list item of the first location list_item = self.locations_page.get_location(0) # Check that the first location is not London self.assertThat(list_item.get_name(), NotEquals("London")) # Go back to the homepage self.locations_page.click_back() # Check homepage is now visible self.assertThat(self.home_page.visible, Eventually(Equals(True)))
def test_network_category(self): """ Checks whether the Network category is available """ category = self.main_view.select_single( objectName='categoryGrid-network') self.assertThat(category, NotEquals(None)) self.assertThat(category.categoryName, Eventually(Equals(_('Network'))))
def test_photo_editor_rotate(self): """Makes sure that the photo editor inside the photo viewer works using the rotate function""" opened_photo = self.photo_viewer.get_opened_photo() item_height = opened_photo.height def is_landscape(): return opened_photo.paintedWidth > opened_photo.paintedHeight self.assertThat(is_landscape(), Equals(True)) self.photo_viewer.click_rotate_button() self.media_view.ensure_spinner_not_running() self.main_view.get_header().click_custom_back_button() self.assertThat(opened_photo.paintedHeight, Eventually(Equals(item_height))) self.assertThat(lambda: is_landscape(), Eventually(Equals(False))) self.click_edit_button() self.photo_viewer.click_rotate_button() self.media_view.ensure_spinner_not_running() self.main_view.get_header().click_custom_back_button() self.click_edit_button() self.photo_viewer.click_revert_button() self.photo_viewer.click_confirm_revert_button() self.main_view.get_header().click_custom_back_button() self.assertThat(opened_photo.paintedHeight, Eventually(NotEquals(item_height))) is_landscape = opened_photo.paintedWidth > opened_photo.paintedHeight self.assertThat(is_landscape, Equals(True))
def drag_bottom_edge_upwards(self, fraction): self.assertThat(model(), NotEquals('Desktop')) handleRect = self.main_window.get_bottom_edge_handle().globalRect x = handleRect.x + handleRect.width // 2 y0 = handleRect.y + handleRect.height // 2 y1 = y0 - int(self.main_window.height * fraction) self.pointing_device.drag(x, y0, x, y1)
def test_personal_category(self): """ Checks whether the Personal category is available """ category = self.main_view.select_single( objectName='categoryGrid-personal') self.assertThat(category, NotEquals(None)) self.assertThat(category.categoryName, Eventually(Equals(_('Personal'))))
def key_nav_prev(self): """Moves the launcher keynav focus to the previous launcher icon""" logger.debug("Selecting previous item in keyboard navigation mode.") old_selection = self._get_controller().key_nav_selection self._perform_key_nav_binding("launcher/keynav/prev") self._get_controller().key_nav_selection.wait_for( NotEquals(old_selection))
def test_wait_select_single_succeeds_quickly(self): app = self.start_fully_featured_app() start_time = default_timer() main_window = app.wait_select_single('QMainWindow') end_time = default_timer() self.assertThat(main_window, NotEquals(None)) self.assertThat(abs(end_time - start_time), LessThan(1))