Fix the discrepancy between SendBaseModeWeb and Web objects' separate cur_history_id attibutes, ensuring that when we call web.error404() we send a new history_id integer for communicating back to the frontend. Add tests for this

This commit is contained in:
Miguel Jacq 2019-09-09 16:35:05 +10:00
parent 8e238ab2d6
commit 90ebc3aab4
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
9 changed files with 92 additions and 15 deletions

View File

@ -29,6 +29,9 @@ class SendBaseModeWeb:
# one download at a time.
self.download_in_progress = False
# This tracks the history id
self.cur_history_id = 0
self.define_routes()
self.init()
@ -264,4 +267,4 @@ class SendBaseModeWeb:
"""
Inherited class will implement this.
"""
pass
pass

View File

@ -207,11 +207,15 @@ class ShareModeWeb(SendBaseModeWeb):
if self.download_individual_files:
return self.stream_individual_file(filesystem_path)
else:
return self.web.error404()
history_id = self.cur_history_id
self.cur_history_id += 1
return self.web.error404(history_id)
# If it's not a directory or file, throw a 404
else:
return self.web.error404()
history_id = self.cur_history_id
self.cur_history_id += 1
return self.web.error404(history_id)
else:
# Special case loading /
@ -223,7 +227,9 @@ class ShareModeWeb(SendBaseModeWeb):
else:
# If the path isn't found, throw a 404
return self.web.error404()
history_id = self.cur_history_id
self.cur_history_id += 1
return self.web.error404(history_id)
def build_zipfile_list(self, filenames, processed_size_callback=None):
self.common.log("ShareModeWeb", "build_zipfile_list")

View File

@ -63,9 +63,6 @@ class Web:
self.auth = HTTPBasicAuth()
self.auth.error_handler(self.error401)
# This tracks the history id
self.cur_history_id = 0
# Verbose mode?
if self.common.verbose:
self.verbose_mode()
@ -204,9 +201,7 @@ class Web:
r = make_response(render_template('403.html', static_url_path=self.static_url_path), 403)
return self.add_security_headers(r)
def error404(self):
history_id = self.cur_history_id
self.cur_history_id += 1
def error404(self, history_id):
self.add_request(self.REQUEST_INDIVIDUAL_FILE_STARTED, '{}'.format(request.path), {
'id': history_id,
'status_code': 404

View File

@ -539,17 +539,17 @@ class History(QtWidgets.QWidget):
# Header
self.header_label = QtWidgets.QLabel(header_text)
self.header_label.setStyleSheet(self.common.css['downloads_uploads_label'])
clear_button = QtWidgets.QPushButton(strings._('gui_all_modes_clear_history'))
clear_button.setStyleSheet(self.common.css['downloads_uploads_clear'])
clear_button.setFlat(True)
clear_button.clicked.connect(self.reset)
self.clear_button = QtWidgets.QPushButton(strings._('gui_all_modes_clear_history'))
self.clear_button.setStyleSheet(self.common.css['downloads_uploads_clear'])
self.clear_button.setFlat(True)
self.clear_button.clicked.connect(self.reset)
header_layout = QtWidgets.QHBoxLayout()
header_layout.addWidget(self.header_label)
header_layout.addStretch()
header_layout.addWidget(self.in_progress_label)
header_layout.addWidget(self.completed_label)
header_layout.addWidget(self.requests_label)
header_layout.addWidget(clear_button)
header_layout.addWidget(self.clear_button)
# When there are no items
self.empty_image = QtWidgets.QLabel()

View File

@ -285,6 +285,10 @@ class GuiBaseTest(object):
else:
self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically'))
def clear_all_history_items(self, mode, count):
if count == 0:
QtTest.QTest.mouseClick(mode.history.clear_button, QtCore.Qt.LeftButton)
self.assertEquals(len(mode.history.item_list.items.keys()), count)
# Auto-stop timer tests
def set_timeout(self, mode, timeout):

View File

@ -127,3 +127,12 @@ class GuiReceiveTest(GuiBaseTest):
self.autostop_timer_widget_hidden(self.gui.receive_mode)
self.server_timed_out(self.gui.receive_mode, 15000)
self.web_server_is_stopped()
def run_all_clear_all_button_tests(self, public_mode):
"""Test the Clear All history button"""
self.run_all_receive_mode_setup_tests(public_mode)
self.upload_file(public_mode, '/tmp/test.txt', 'test.txt')
self.history_widgets_present(self.gui.receive_mode)
self.clear_all_history_items(self.gui.receive_mode, 0)
self.upload_file(public_mode, '/tmp/test.txt', 'test.txt')
self.clear_all_history_items(self.gui.receive_mode, 2)

View File

@ -196,6 +196,15 @@ class GuiShareTest(GuiBaseTest):
self.run_all_share_mode_started_tests(public_mode)
self.run_all_share_mode_download_tests(public_mode, stay_open)
def run_all_clear_all_button_tests(self, public_mode, stay_open):
"""Test the Clear All history button"""
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(public_mode)
self.individual_file_is_viewable_or_not(public_mode, stay_open)
self.history_widgets_present(self.gui.share_mode)
self.clear_all_history_items(self.gui.share_mode, 0)
self.individual_file_is_viewable_or_not(public_mode, stay_open)
self.clear_all_history_items(self.gui.share_mode, 2)
def run_all_share_mode_individual_file_tests(self, public_mode, stay_open):
"""Tests in share mode when viewing an individual file"""

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .GuiReceiveTest import GuiReceiveTest
class LocalReceiveModeClearAllButtonTest(unittest.TestCase, GuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = GuiReceiveTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiReceiveTest.tear_down()
@pytest.mark.gui
@pytest.mark.skipif(pytest.__version__ < '2.9', reason="requires newer pytest")
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_clear_all_button_tests(False)
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .GuiShareTest import GuiShareTest
class LocalShareModeClearAllButtonTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False,
}
cls.gui = GuiShareTest.set_up(test_settings)
@classmethod
def tearDownClass(cls):
GuiShareTest.tear_down()
@pytest.mark.gui
@pytest.mark.skipif(pytest.__version__ < '2.9', reason="requires newer pytest")
def test_gui(self):
self.run_all_common_setup_tests()
self.run_all_clear_all_button_tests(False, True)
if __name__ == "__main__":
unittest.main()