How to use get_mode method in autotest

Best Python code snippet using autotest_python

test_gui_share.py

Source:test_gui_share.py Github

copy

Full Screen

...7class TestShare(GuiBaseTest):8 # Shared test methods9 def removing_all_files_hides_remove_button(self, tab):10 """Test that clicking on the file item shows the remove button. Test that removing the only item in the list hides the remove button"""11 rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(12 tab.get_mode().server_status.file_selection.file_list.item(0)13 )14 QtTest.QTest.mouseClick(15 tab.get_mode().server_status.file_selection.file_list.viewport(),16 QtCore.Qt.LeftButton,17 pos=rect.center(),18 )19 # Remove button should be visible20 self.assertTrue(21 tab.get_mode().server_status.file_selection.remove_button.isVisible()22 )23 # Click remove, remove button should still be visible since we have one more file24 tab.get_mode().server_status.file_selection.remove_button.click()25 rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(26 tab.get_mode().server_status.file_selection.file_list.item(0)27 )28 QtTest.QTest.mouseClick(29 tab.get_mode().server_status.file_selection.file_list.viewport(),30 QtCore.Qt.LeftButton,31 pos=rect.center(),32 )33 self.assertTrue(34 tab.get_mode().server_status.file_selection.remove_button.isVisible()35 )36 tab.get_mode().server_status.file_selection.remove_button.click()37 # No more files, the remove button should be hidden38 self.assertFalse(39 tab.get_mode().server_status.file_selection.remove_button.isVisible()40 )41 def add_a_file_and_remove_using_its_remove_widget(self, tab):42 """Test that we can also remove a file by clicking on its [X] widget"""43 num_files = tab.get_mode().server_status.file_selection.get_num_files()44 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])45 tab.get_mode().server_status.file_selection.file_list.item(46 047 ).item_button.click()48 self.file_selection_widget_has_files(tab, num_files)49 def add_a_file_and_remove_using_remove_all_widget(self, tab):50 """Test that we can also remove all files by clicking on the Remove All widget"""51 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])52 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])53 tab.get_mode().remove_all_button.click()54 # Should be no files after clearing all55 self.file_selection_widget_has_files(tab, 0)56 def file_selection_widget_read_files(self, tab):57 """Re-add some files to the list so we can share"""58 num_files = tab.get_mode().server_status.file_selection.get_num_files()59 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])60 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])61 self.file_selection_widget_has_files(tab, num_files + 2)62 def download_share(self, tab):63 """Test that we can download the share"""64 url = f"http://127.0.0.1:{tab.app.port}/download"65 if tab.settings.get("general", "public"):66 r = requests.get(url)67 else:68 r = requests.get(69 url,70 auth=requests.auth.HTTPBasicAuth(71 "onionshare", tab.get_mode().server_status.web.password72 ),73 )74 tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)75 tmp_file.write(r.content)76 tmp_file.close()77 z = zipfile.ZipFile(tmp_file.name)78 QtTest.QTest.qWait(5, self.gui.qtapp)79 self.assertEqual("onionshare", z.read("test.txt").decode("utf-8"))80 QtTest.QTest.qWait(500, self.gui.qtapp)81 def individual_file_is_viewable_or_not(self, tab):82 """83 Test that an individual file is viewable (when in autostop_sharing is false) or that it84 isn't (when not in autostop_sharing is true)85 """86 url = f"http://127.0.0.1:{tab.app.port}"87 download_file_url = f"http://127.0.0.1:{tab.app.port}/test.txt"88 if tab.settings.get("general", "public"):89 r = requests.get(url)90 else:91 r = requests.get(92 url,93 auth=requests.auth.HTTPBasicAuth(94 "onionshare", tab.get_mode().server_status.web.password95 ),96 )97 if tab.settings.get("share", "autostop_sharing"):98 self.assertFalse('a href="/test.txt"' in r.text)99 if tab.settings.get("general", "public"):100 r = requests.get(download_file_url)101 else:102 r = requests.get(103 download_file_url,104 auth=requests.auth.HTTPBasicAuth(105 "onionshare", tab.get_mode().server_status.web.password106 ),107 )108 self.assertEqual(r.status_code, 404)109 self.download_share(tab)110 else:111 self.assertTrue('a href="test.txt"' in r.text)112 if tab.settings.get("general", "public"):113 r = requests.get(download_file_url)114 else:115 r = requests.get(116 download_file_url,117 auth=requests.auth.HTTPBasicAuth(118 "onionshare", tab.get_mode().server_status.web.password119 ),120 )121 tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)122 tmp_file.write(r.content)123 tmp_file.close()124 with open(tmp_file.name, "r") as f:125 self.assertEqual("onionshare", f.read())126 os.remove(tmp_file.name)127 QtTest.QTest.qWait(500, self.gui.qtapp)128 def hit_401(self, tab):129 """Test that the server stops after too many 401s, or doesn't when in public mode"""130 # In non-public mode, get ready to accept the dialog131 if not tab.settings.get("general", "public"):132 def accept_dialog():133 window = tab.common.gui.qtapp.activeWindow()134 if window:135 window.close()136 QtCore.QTimer.singleShot(1000, accept_dialog)137 # Make 20 requests with guessed passwords138 url = f"http://127.0.0.1:{tab.app.port}/"139 for _ in range(20):140 password_guess = self.gui.common.build_password()141 requests.get(142 url, auth=requests.auth.HTTPBasicAuth("onionshare", password_guess)143 )144 # In public mode, we should still be running (no rate-limiting)145 if tab.settings.get("general", "public"):146 self.web_server_is_running(tab)147 # In non-public mode, we should be shut down (rate-limiting)148 else:149 self.web_server_is_stopped(tab)150 def set_autostart_timer(self, tab, timer):151 """Test that the timer can be set"""152 schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)153 tab.get_mode().mode_settings_widget.autostart_timer_widget.setDateTime(schedule)154 self.assertTrue(155 tab.get_mode().mode_settings_widget.autostart_timer_widget.dateTime(),156 schedule,157 )158 def autostart_timer_widget_hidden(self, tab):159 """Test that the auto-start timer widget is hidden when share has started"""160 self.assertFalse(161 tab.get_mode().mode_settings_widget.autostart_timer_widget.isVisible()162 )163 def scheduled_service_started(self, tab, wait):164 """Test that the server has timed out after the timer ran out"""165 QtTest.QTest.qWait(wait, self.gui.qtapp)166 # We should have started now167 self.assertEqual(tab.get_mode().server_status.status, 2)168 def cancel_the_share(self, tab):169 """Test that we can cancel a share before it's started up """170 self.server_working_on_start_button_pressed(tab)171 self.server_status_indicator_says_scheduled(tab)172 self.add_remove_buttons_hidden(tab)173 self.mode_settings_widget_is_hidden(tab)174 self.set_autostart_timer(tab, 10)175 QtTest.QTest.qWait(500, self.gui.qtapp)176 QtTest.QTest.mousePress(177 tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton178 )179 QtTest.QTest.qWait(100, self.gui.qtapp)180 QtTest.QTest.mouseRelease(181 tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton182 )183 QtTest.QTest.qWait(500, self.gui.qtapp)184 self.assertEqual(185 tab.get_mode().server_status.status,186 tab.get_mode().server_status.STATUS_STOPPED,187 )188 self.server_is_stopped(tab)189 self.web_server_is_stopped(tab)190 # Grouped tests follow from here191 def run_all_share_mode_setup_tests(self, tab):192 """Tests in share mode prior to starting a share"""193 tab.get_mode().server_status.file_selection.file_list.add_file(194 self.tmpfile_test195 )196 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])197 tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])198 self.file_selection_widget_has_files(tab, 3)199 self.history_is_not_visible(tab)200 self.click_toggle_history(tab)201 self.history_is_visible(tab)202 self.removing_all_files_hides_remove_button(tab)203 self.add_a_file_and_remove_using_its_remove_widget(tab)204 self.file_selection_widget_read_files(tab)205 def run_all_share_mode_started_tests(self, tab, startup_time=2000):206 """Tests in share mode after starting a share"""207 self.server_working_on_start_button_pressed(tab)208 self.server_status_indicator_says_starting(tab)209 self.add_remove_buttons_hidden(tab)210 self.mode_settings_widget_is_hidden(tab)211 self.server_is_started(tab, startup_time)212 self.web_server_is_running(tab)213 self.have_a_password(tab)214 self.url_description_shown(tab)215 self.have_copy_url_button(tab)216 self.have_show_qr_code_button(tab)217 self.server_status_indicator_says_started(tab)218 def run_all_share_mode_download_tests(self, tab):219 """Tests in share mode after downloading a share"""220 tab.get_mode().server_status.file_selection.file_list.add_file(221 self.tmpfile_test222 )223 self.web_page(tab, "Total size")224 self.download_share(tab)225 self.history_widgets_present(tab)226 self.server_is_stopped(tab)227 self.web_server_is_stopped(tab)228 self.server_status_indicator_says_closed(tab)229 self.add_button_visible(tab)230 self.server_working_on_start_button_pressed(tab)231 self.toggle_indicator_is_reset(tab)232 self.server_is_started(tab)233 self.history_indicator(tab)234 def run_all_share_mode_individual_file_download_tests(self, tab):235 """Tests in share mode after downloading a share"""236 self.web_page(tab, "Total size")237 self.individual_file_is_viewable_or_not(tab)238 self.history_widgets_present(tab)239 self.server_is_stopped(tab)240 self.web_server_is_stopped(tab)241 self.server_status_indicator_says_closed(tab)242 self.add_button_visible(tab)243 self.server_working_on_start_button_pressed(tab)244 self.server_is_started(tab)245 self.history_indicator(tab)246 def run_all_share_mode_tests(self, tab):247 """End-to-end share tests"""248 self.run_all_share_mode_setup_tests(tab)249 self.run_all_share_mode_started_tests(tab)250 self.run_all_share_mode_download_tests(tab)251 def run_all_clear_all_history_button_tests(self, tab):252 """Test the Clear All history button"""253 self.run_all_share_mode_setup_tests(tab)254 self.run_all_share_mode_started_tests(tab)255 self.individual_file_is_viewable_or_not(tab)256 self.history_widgets_present(tab)257 self.clear_all_history_items(tab, 0)258 self.individual_file_is_viewable_or_not(tab)259 self.clear_all_history_items(tab, 2)260 def run_all_remove_all_file_selection_button_tests(self, tab):261 """Test the Remove All File Selection button"""262 self.run_all_share_mode_setup_tests(tab)263 self.add_a_file_and_remove_using_remove_all_widget(tab)264 def run_all_share_mode_individual_file_tests(self, tab):265 """Tests in share mode when viewing an individual file"""266 self.run_all_share_mode_setup_tests(tab)267 self.run_all_share_mode_started_tests(tab)268 self.run_all_share_mode_individual_file_download_tests(tab)269 # Tests270 def test_autostart_and_autostop_timer_mismatch(self):271 """272 If autostart timer is after autostop timer, a warning should be thrown273 """274 tab = self.new_share_tab()275 tab.get_mode().mode_settings_widget.toggle_advanced_button.click()276 tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()277 tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()278 def accept_dialog():279 window = tab.common.gui.qtapp.activeWindow()280 if window:281 window.close()282 self.run_all_common_setup_tests()283 self.run_all_share_mode_setup_tests(tab)284 self.set_autostart_timer(tab, 15)285 self.set_timeout(tab, 5)286 QtCore.QTimer.singleShot(200, accept_dialog)287 tab.get_mode().server_status.server_button.click()288 self.server_is_stopped(tab)289 self.close_all_tabs()290 def test_autostart_timer(self):291 """292 Autostart timer should automatically start293 """294 tab = self.new_share_tab()295 tab.get_mode().mode_settings_widget.toggle_advanced_button.click()296 tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()297 self.run_all_common_setup_tests()298 self.run_all_share_mode_setup_tests(tab)299 self.set_autostart_timer(tab, 2)300 self.server_working_on_start_button_pressed(tab)301 self.autostart_timer_widget_hidden(tab)302 self.server_status_indicator_says_scheduled(tab)303 self.web_server_is_stopped(tab)304 self.scheduled_service_started(tab, 2200)305 self.web_server_is_running(tab)306 self.close_all_tabs()307 def test_autostart_timer_too_short(self):308 """309 Autostart timer should throw a warning if the scheduled time is too soon310 """311 tab = self.new_share_tab()312 tab.get_mode().mode_settings_widget.toggle_advanced_button.click()313 tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()314 def accept_dialog():315 window = tab.common.gui.qtapp.activeWindow()316 if window:317 window.close()318 self.run_all_common_setup_tests()319 self.run_all_share_mode_setup_tests(tab)320 # Set a low timeout321 self.set_autostart_timer(tab, 2)322 QtTest.QTest.qWait(2200, self.gui.qtapp)323 QtCore.QTimer.singleShot(200, accept_dialog)324 tab.get_mode().server_status.server_button.click()325 self.assertEqual(tab.get_mode().server_status.status, 0)326 self.close_all_tabs()327 def test_autostart_timer_cancel(self):328 """329 Test canceling a scheduled share330 """331 tab = self.new_share_tab()332 tab.get_mode().mode_settings_widget.toggle_advanced_button.click()333 tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()334 self.run_all_common_setup_tests()335 self.run_all_share_mode_setup_tests(tab)336 self.cancel_the_share(tab)337 self.close_all_tabs()338 def test_clear_all_history_button(self):339 """340 Test clearing all history items341 """342 tab = self.new_share_tab()343 tab.get_mode().autostop_sharing_checkbox.click()344 self.run_all_common_setup_tests()345 self.run_all_clear_all_history_button_tests(tab)346 self.close_all_tabs()347 def test_remove_all_file_selection_button(self):348 """349 Test remove all file items at once350 """351 tab = self.new_share_tab()352 self.run_all_common_setup_tests()353 self.run_all_remove_all_file_selection_button_tests(tab)354 self.close_all_tabs()355 def test_public_mode(self):356 """357 Public mode shouldn't have a password358 """359 tab = self.new_share_tab()360 tab.get_mode().mode_settings_widget.public_checkbox.click()361 self.run_all_common_setup_tests()362 self.run_all_share_mode_tests(tab)363 self.close_all_tabs()364 def test_without_autostop_sharing(self):365 """366 Disable autostop sharing after first download367 """368 tab = self.new_share_tab()369 tab.get_mode().autostop_sharing_checkbox.click()370 self.run_all_common_setup_tests()371 self.run_all_share_mode_tests(tab)372 self.close_all_tabs()373 def test_download(self):374 """375 Test downloading in share mode376 """377 tab = self.new_share_tab()378 self.run_all_common_setup_tests()379 self.run_all_share_mode_tests(tab)380 self.close_all_tabs()381 def test_individual_files_without_autostop_sharing(self):382 """383 Test downloading individual files with autostop sharing disabled384 """385 tab = self.new_share_tab()386 tab.get_mode().autostop_sharing_checkbox.click()387 self.run_all_common_setup_tests()388 self.run_all_share_mode_individual_file_tests(tab)389 self.close_all_tabs()390 def test_individual_files(self):391 """392 Test downloading individual files393 """394 tab = self.new_share_tab()395 self.run_all_common_setup_tests()396 self.run_all_share_mode_individual_file_tests(tab)397 self.close_all_tabs()398 def test_large_download(self):399 """400 Test a large download401 """402 tab = self.new_share_tab()403 self.run_all_common_setup_tests()404 self.run_all_share_mode_setup_tests(tab)405 tab.get_mode().server_status.file_selection.file_list.add_file(406 self.tmpfile_large407 )408 self.run_all_share_mode_started_tests(tab, startup_time=15000)409 self.assertTrue(tab.get_mode().filesize_warning.isVisible())410 self.download_share(tab)411 self.server_is_stopped(tab)412 self.web_server_is_stopped(tab)413 self.server_status_indicator_says_closed(tab)414 self.close_all_tabs()415 def test_persistent_password(self):416 """417 Test a large download418 """419 tab = self.new_share_tab()420 tab.get_mode().mode_settings_widget.persistent_checkbox.click()421 self.run_all_common_setup_tests()422 self.run_all_share_mode_setup_tests(tab)423 self.run_all_share_mode_started_tests(tab)424 password = tab.get_mode().server_status.web.password425 self.run_all_share_mode_download_tests(tab)426 self.run_all_share_mode_started_tests(tab)427 self.assertEqual(tab.get_mode().server_status.web.password, password)428 self.run_all_share_mode_download_tests(tab)429 self.close_all_tabs()430 def test_autostop_timer(self):431 """432 Test the autostop timer433 """434 tab = self.new_share_tab()435 tab.get_mode().mode_settings_widget.toggle_advanced_button.click()436 tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()437 self.run_all_common_setup_tests()438 self.run_all_share_mode_setup_tests(tab)439 self.set_timeout(tab, 5)440 self.run_all_share_mode_started_tests(tab)441 self.autostop_timer_widget_hidden(tab)442 self.server_timed_out(tab, 10000)443 self.web_server_is_stopped(tab)444 self.close_all_tabs()445 def test_autostop_timer_too_short(self):446 """447 Test the autostop timer when the timeout is too short448 """449 tab = self.new_share_tab()450 tab.get_mode().mode_settings_widget.toggle_advanced_button.click()451 tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()452 def accept_dialog():453 window = tab.common.gui.qtapp.activeWindow()454 if window:455 window.close()456 self.run_all_common_setup_tests()457 self.run_all_share_mode_setup_tests(tab)458 # Set a low timeout459 self.set_timeout(tab, 2)460 QtTest.QTest.qWait(2100, self.gui.qtapp)461 QtCore.QTimer.singleShot(2200, accept_dialog)462 tab.get_mode().server_status.server_button.click()463 self.assertEqual(tab.get_mode().server_status.status, 0)464 self.close_all_tabs()465 def test_unreadable_file(self):466 """467 Sharing an unreadable file should throw a warning468 """469 tab = self.new_share_tab()470 def accept_dialog():471 window = tab.common.gui.qtapp.activeWindow()472 if window:473 window.close()474 self.run_all_share_mode_setup_tests(tab)475 QtCore.QTimer.singleShot(200, accept_dialog)476 tab.get_mode().server_status.file_selection.file_list.add_file(477 "/tmp/nonexistent.txt"478 )479 self.file_selection_widget_has_files(tab, 3)480 self.close_all_tabs()481 def test_401_triggers_ratelimit(self):482 """483 Rate limit should be triggered484 """485 tab = self.new_share_tab()486 def accept_dialog():487 window = tab.common.gui.qtapp.activeWindow()488 if window:489 window.close()490 tab.get_mode().autostop_sharing_checkbox.click()491 self.run_all_common_setup_tests()492 self.run_all_share_mode_tests(tab)493 self.hit_401(tab)494 self.close_all_tabs()495 def test_401_public_skips_ratelimit(self):496 """497 Public mode should skip the rate limit498 """499 tab = self.new_share_tab()500 def accept_dialog():501 window = tab.common.gui.qtapp.activeWindow()502 if window:503 window.close()504 tab.get_mode().autostop_sharing_checkbox.click()505 tab.get_mode().mode_settings_widget.public_checkbox.click()506 self.run_all_common_setup_tests()507 self.run_all_share_mode_tests(tab)508 self.hit_401(tab)509 self.close_all_tabs()510 def test_405_page_returned_for_invalid_methods(self):511 """512 Our custom 405 page should return for invalid methods513 """514 tab = self.new_share_tab()515 tab.get_mode().autostop_sharing_checkbox.click()516 tab.get_mode().mode_settings_widget.public_checkbox.click()517 self.run_all_common_setup_tests()518 self.run_all_share_mode_setup_tests(tab)519 self.run_all_share_mode_started_tests(tab)520 url = f"http://127.0.0.1:{tab.app.port}/"521 self.hit_405(url, expected_resp="OnionShare: 405 Method Not Allowed", data = {'foo':'bar'}, methods = ["put", "post", "delete", "options"])522 self.history_widgets_present(tab)...

Full Screen

Full Screen

gui_base_test.py

Source:gui_base_test.py Github

copy

Full Screen

...125 """Test that the status bar is visible"""126 self.assertTrue(self.gui.status_bar.isVisible())127 def mode_settings_widget_is_visible(self, tab):128 """Test that the mode settings are visible"""129 self.assertTrue(tab.get_mode().mode_settings_widget.isVisible())130 def mode_settings_widget_is_hidden(self, tab):131 """Test that the mode settings are hidden when the server starts"""132 self.assertFalse(tab.get_mode().mode_settings_widget.isVisible())133 def click_toggle_history(self, tab):134 """Test that we can toggle Download or Upload history by clicking the toggle button"""135 currently_visible = tab.get_mode().history.isVisible()136 tab.get_mode().toggle_history.click()137 self.assertEqual(tab.get_mode().history.isVisible(), not currently_visible)138 def history_indicator(self, tab, indicator_count="1"):139 """Test that we can make sure the history is toggled off, do an action, and the indiciator works"""140 # Make sure history is toggled off141 if tab.get_mode().history.isVisible():142 tab.get_mode().toggle_history.click()143 self.assertFalse(tab.get_mode().history.isVisible())144 # Indicator should not be visible yet145 self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())146 if type(tab.get_mode()) == ReceiveMode:147 # Upload a file148 files = {"file[]": open(self.tmpfiles[0], "rb")}149 url = f"http://127.0.0.1:{tab.app.port}/upload"150 if tab.settings.get("general", "public"):151 requests.post(url, files=files)152 else:153 requests.post(154 url,155 files=files,156 auth=requests.auth.HTTPBasicAuth(157 "onionshare", tab.get_mode().web.password158 ),159 )160 QtTest.QTest.qWait(2000, self.gui.qtapp)161 if type(tab.get_mode()) == ShareMode:162 # Download files163 url = f"http://127.0.0.1:{tab.app.port}/download"164 if tab.settings.get("general", "public"):165 requests.get(url)166 else:167 requests.get(168 url,169 auth=requests.auth.HTTPBasicAuth(170 "onionshare", tab.get_mode().web.password171 ),172 )173 QtTest.QTest.qWait(2000, self.gui.qtapp)174 # Indicator should be visible, have a value of "1"175 self.assertTrue(tab.get_mode().toggle_history.indicator_label.isVisible())176 self.assertEqual(177 tab.get_mode().toggle_history.indicator_label.text(), indicator_count178 )179 # Toggle history back on, indicator should be hidden again180 tab.get_mode().toggle_history.click()181 self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())182 def history_is_not_visible(self, tab):183 """Test that the History section is not visible"""184 self.assertFalse(tab.get_mode().history.isVisible())185 def history_is_visible(self, tab):186 """Test that the History section is visible"""187 self.assertTrue(tab.get_mode().history.isVisible())188 def server_working_on_start_button_pressed(self, tab):189 """Test we can start the service"""190 # Should be in SERVER_WORKING state191 tab.get_mode().server_status.server_button.click()192 self.assertEqual(tab.get_mode().server_status.status, 1)193 def toggle_indicator_is_reset(self, tab):194 self.assertEqual(tab.get_mode().toggle_history.indicator_count, 0)195 self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())196 def server_status_indicator_says_starting(self, tab):197 """Test that the Server Status indicator shows we are Starting"""198 self.assertEqual(199 tab.get_mode().server_status_label.text(),200 strings._("gui_status_indicator_share_working"),201 )202 def server_status_indicator_says_scheduled(self, tab):203 """Test that the Server Status indicator shows we are Scheduled"""204 self.assertEqual(205 tab.get_mode().server_status_label.text(),206 strings._("gui_status_indicator_share_scheduled"),207 )208 def server_is_started(self, tab, startup_time=2000):209 """Test that the server has started"""210 QtTest.QTest.qWait(startup_time, self.gui.qtapp)211 # Should now be in SERVER_STARTED state212 self.assertEqual(tab.get_mode().server_status.status, 2)213 def web_server_is_running(self, tab):214 """Test that the web server has started"""215 try:216 requests.get(f"http://127.0.0.1:{tab.app.port}/")217 self.assertTrue(True)218 except requests.exceptions.ConnectionError:219 self.assertTrue(False)220 def have_a_password(self, tab):221 """Test that we have a valid password"""222 if not tab.settings.get("general", "public"):223 self.assertRegex(tab.get_mode().server_status.web.password, r"(\w+)-(\w+)")224 else:225 self.assertIsNone(tab.get_mode().server_status.web.password, r"(\w+)-(\w+)")226 def add_button_visible(self, tab):227 """Test that the add button should be visible"""228 if platform.system() == "Darwin":229 self.assertTrue(230 tab.get_mode().server_status.file_selection.add_files_button.isVisible()231 )232 self.assertTrue(233 tab.get_mode().server_status.file_selection.add_folder_button.isVisible()234 )235 else:236 self.assertTrue(237 tab.get_mode().server_status.file_selection.add_button.isVisible()238 )239 def url_description_shown(self, tab):240 """Test that the URL label is showing"""241 self.assertTrue(tab.get_mode().server_status.url_description.isVisible())242 def have_copy_url_button(self, tab):243 """Test that the Copy URL button is shown and that the clipboard is correct"""244 self.assertTrue(tab.get_mode().server_status.copy_url_button.isVisible())245 tab.get_mode().server_status.copy_url_button.click()246 clipboard = tab.common.gui.qtapp.clipboard()247 if tab.settings.get("general", "public"):248 self.assertEqual(clipboard.text(), f"http://127.0.0.1:{tab.app.port}")249 else:250 self.assertEqual(251 clipboard.text(),252 f"http://onionshare:{tab.get_mode().server_status.web.password}@127.0.0.1:{tab.app.port}",253 )254 def have_show_qr_code_button(self, tab):255 """Test that the Show QR Code URL button is shown and that it loads a QR Code Dialog"""256 self.assertTrue(257 tab.get_mode().server_status.show_url_qr_code_button.isVisible()258 )259 def accept_dialog():260 window = tab.common.gui.qtapp.activeWindow()261 if window:262 window.close()263 QtCore.QTimer.singleShot(500, accept_dialog)264 tab.get_mode().server_status.show_url_qr_code_button.click()265 def server_status_indicator_says_started(self, tab):266 """Test that the Server Status indicator shows we are started"""267 if type(tab.get_mode()) == ReceiveMode:268 self.assertEqual(269 tab.get_mode().server_status_label.text(),270 strings._("gui_status_indicator_receive_started"),271 )272 if type(tab.get_mode()) == ShareMode:273 self.assertEqual(274 tab.get_mode().server_status_label.text(),275 strings._("gui_status_indicator_share_started"),276 )277 def web_page(self, tab, string):278 """Test that the web page contains a string"""279 url = f"http://127.0.0.1:{tab.app.port}/"280 if tab.settings.get("general", "public"):281 r = requests.get(url)282 else:283 r = requests.get(284 url,285 auth=requests.auth.HTTPBasicAuth(286 "onionshare", tab.get_mode().web.password287 ),288 )289 self.assertTrue(string in r.text)290 def history_widgets_present(self, tab):291 """Test that the relevant widgets are present in the history view after activity has taken place"""292 self.assertFalse(tab.get_mode().history.empty.isVisible())293 self.assertTrue(tab.get_mode().history.not_empty.isVisible())294 def counter_incremented(self, tab, count):295 """Test that the counter has incremented"""296 self.assertEqual(tab.get_mode().history.completed_count, count)297 def server_is_stopped(self, tab):298 """Test that the server stops when we click Stop"""299 if (300 type(tab.get_mode()) == ReceiveMode301 or (302 type(tab.get_mode()) == ShareMode303 and not tab.settings.get("share", "autostop_sharing")304 )305 or (type(tab.get_mode()) == WebsiteMode)306 or (type(tab.get_mode()) == ChatMode)307 ):308 tab.get_mode().server_status.server_button.click()309 self.assertEqual(tab.get_mode().server_status.status, 0)310 self.assertFalse(311 tab.get_mode().server_status.show_url_qr_code_button.isVisible()312 )313 self.assertFalse(tab.get_mode().server_status.copy_url_button.isVisible())314 self.assertFalse(tab.get_mode().server_status.url.isVisible())315 self.assertFalse(tab.get_mode().server_status.url_description.isVisible())316 self.assertFalse(317 tab.get_mode().server_status.copy_hidservauth_button.isVisible()318 )319 def web_server_is_stopped(self, tab):320 """Test that the web server also stopped"""321 QtTest.QTest.qWait(800, self.gui.qtapp)322 try:323 requests.get(f"http://127.0.0.1:{tab.app.port}/")324 self.assertTrue(False)325 except requests.exceptions.ConnectionError:326 self.assertTrue(True)327 def server_status_indicator_says_closed(self, tab):328 """Test that the Server Status indicator shows we closed"""329 if type(tab.get_mode()) == ReceiveMode:330 self.assertEqual(331 tab.get_mode().server_status_label.text(),332 strings._("gui_status_indicator_receive_stopped"),333 )334 if type(tab.get_mode()) == ShareMode:335 if not tab.settings.get("share", "autostop_sharing"):336 self.assertEqual(337 tab.get_mode().server_status_label.text(),338 strings._("gui_status_indicator_share_stopped"),339 )340 else:341 self.assertEqual(342 tab.get_mode().server_status_label.text(),343 strings._("closing_automatically"),344 )345 def clear_all_history_items(self, tab, count):346 if count == 0:347 tab.get_mode().history.clear_button.click()348 self.assertEqual(len(tab.get_mode().history.item_list.items.keys()), count)349 def file_selection_widget_has_files(self, tab, num=3):350 """Test that the number of items in the list is as expected"""351 self.assertEqual(352 tab.get_mode().server_status.file_selection.get_num_files(), num353 )354 def add_remove_buttons_hidden(self, tab):355 """Test that the add and remove buttons are hidden when the server starts"""356 if platform.system() == "Darwin":357 self.assertFalse(358 tab.get_mode().server_status.file_selection.add_files_button.isVisible()359 )360 self.assertFalse(361 tab.get_mode().server_status.file_selection.add_folder_button.isVisible()362 )363 else:364 self.assertFalse(365 tab.get_mode().server_status.file_selection.add_button.isVisible()366 )367 self.assertFalse(368 tab.get_mode().server_status.file_selection.remove_button.isVisible()369 )370 # Auto-stop timer tests371 def set_timeout(self, tab, timeout):372 """Test that the timeout can be set"""373 timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)374 tab.get_mode().mode_settings_widget.autostop_timer_widget.setDateTime(timer)375 self.assertTrue(376 tab.get_mode().mode_settings_widget.autostop_timer_widget.dateTime(), timer377 )378 def autostop_timer_widget_hidden(self, tab):379 """Test that the auto-stop timer widget is hidden when share has started"""380 self.assertFalse(381 tab.get_mode().mode_settings_widget.autostop_timer_widget.isVisible()382 )383 def server_timed_out(self, tab, wait):384 """Test that the server has timed out after the timer ran out"""385 QtTest.QTest.qWait(wait, self.gui.qtapp)386 # We should have timed out now387 self.assertEqual(tab.get_mode().server_status.status, 0)388 def hit_405(self, url, expected_resp, data = {}, methods = [] ):389 """Test various HTTP methods and the response"""390 for method in methods:391 if method == "put":392 r = requests.put(url, data = data)393 if method == "post":394 r = requests.post(url, data = data)395 if method == "delete":396 r = requests.delete(url)397 if method == "options":398 r = requests.options(url)399 self.assertTrue(expected_resp in r.text)400 self.assertFalse('Werkzeug' in r.headers)401 # Grouped tests follow from here...

Full Screen

Full Screen

test_stat.py

Source:test_stat.py Github

copy

Full Screen

1import unittest2import os3import stat4from test.support import TESTFN, run_unittest5def get_mode(fname=TESTFN):6 return stat.filemode(os.lstat(fname).st_mode)7class TestFilemode(unittest.TestCase):8 def setUp(self):9 try:10 os.remove(TESTFN)11 except OSError:12 try:13 os.rmdir(TESTFN)14 except OSError:15 pass16 tearDown = setUp17 def test_mode(self):18 with open(TESTFN, 'w'):19 pass20 if os.name == 'posix':21 os.chmod(TESTFN, 0o700)22 self.assertEqual(get_mode(), '-rwx------')23 os.chmod(TESTFN, 0o070)24 self.assertEqual(get_mode(), '----rwx---')25 os.chmod(TESTFN, 0o007)26 self.assertEqual(get_mode(), '-------rwx')27 os.chmod(TESTFN, 0o444)28 self.assertEqual(get_mode(), '-r--r--r--')29 else:30 os.chmod(TESTFN, 0o700)31 self.assertEqual(get_mode()[:3], '-rw')32 def test_directory(self):33 os.mkdir(TESTFN)34 os.chmod(TESTFN, 0o700)35 if os.name == 'posix':36 self.assertEqual(get_mode(), 'drwx------')37 else:38 self.assertEqual(get_mode()[0], 'd')39 @unittest.skipUnless(hasattr(os, 'symlink'), 'os.symlink not available')40 def test_link(self):41 try:42 os.symlink(os.getcwd(), TESTFN)43 except (OSError, NotImplementedError) as err:44 raise unittest.SkipTest(str(err))45 else:46 self.assertEqual(get_mode()[0], 'l')47 @unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available')48 def test_fifo(self):49 os.mkfifo(TESTFN, 0o700)50 self.assertEqual(get_mode(), 'prwx------')51def test_main():52 run_unittest(TestFilemode)53if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful