Initial commit
This commit is contained in:
74
tests/test_ui.py
Normal file
74
tests/test_ui.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from autodeploy.store import Store, DEFAULTS
|
||||
from autodeploy.ui import MainWindow, ProfileDialog, STYLE
|
||||
|
||||
|
||||
class UITests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.app = QApplication.instance() or QApplication([])
|
||||
cls.app.setStyleSheet(STYLE)
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.env = patch.dict(os.environ, AUTODEPLOY_DATA=self.tmp.name)
|
||||
self.env.start()
|
||||
self.window = MainWindow()
|
||||
|
||||
def tearDown(self):
|
||||
self.window.close()
|
||||
self.window.deleteLater()
|
||||
self.app.processEvents()
|
||||
self.env.stop()
|
||||
self.tmp.cleanup()
|
||||
|
||||
def test_empty_state_and_switching_profiles_preserves_files(self):
|
||||
self.assertEqual([self.window.tabs.tabText(i) for i in range(self.window.tabs.count())],
|
||||
['发布部署', 'Nginx 管理', '历史与回滚'])
|
||||
self.assertFalse(self.window.tabs.isAncestorOf(self.window.server_card))
|
||||
self.assertFalse(self.window.deploy_btn.isEnabled())
|
||||
a = self.window.store.save(None, dict(DEFAULTS, host='192.0.2.10', name='A'))
|
||||
b = self.window.store.save(None, dict(DEFAULTS, host='192.0.2.11', name='B'))
|
||||
self.window.refresh_profiles(a)
|
||||
self.assertTrue(self.window.deploy_btn.isEnabled())
|
||||
self.window.war.setText('C:/build/ROOT.war')
|
||||
self.window.cert.setText('C:/cert/server.pem')
|
||||
self.window.servers.setCurrentRow(1)
|
||||
self.assertEqual(self.window.pid, b)
|
||||
self.window.servers.setCurrentRow(0)
|
||||
self.assertEqual(self.window.war.text(), 'C:/build/ROOT.war')
|
||||
self.assertEqual(self.window.cert.text(), 'C:/cert/server.pem')
|
||||
self.assertTrue(self.window.tabs.widget(self.window.nginx_tab_index).isAncestorOf(self.window.cert))
|
||||
self.assertFalse(self.window.tabs.widget(0).isAncestorOf(self.window.cert))
|
||||
self.assertGreaterEqual(self.window.cert.minimumHeight(), 42)
|
||||
self.assertGreaterEqual(self.window.cert_file_btn.minimumWidth(), 118)
|
||||
|
||||
def test_frontend_mode_and_busy_lock(self):
|
||||
a = self.window.store.save(None, dict(DEFAULTS, host='192.0.2.10'))
|
||||
self.window.refresh_profiles(a)
|
||||
self.window.mode.setCurrentIndex(1)
|
||||
self.assertFalse(self.window.war.isEnabled())
|
||||
self.assertTrue(self.window.front.isEnabled())
|
||||
self.window.busy(True)
|
||||
self.assertFalse(self.window.front.isEnabled())
|
||||
self.assertFalse(self.window.cert_deploy_btn.isEnabled())
|
||||
self.assertFalse(self.window.servers.isEnabled())
|
||||
self.window.busy(False)
|
||||
self.assertFalse(self.window.war.isEnabled())
|
||||
|
||||
def test_configuration_dialog_accepts_posix_paths(self):
|
||||
dialog = ProfileDialog(dict(DEFAULTS, host='192.0.2.10'), self.window)
|
||||
dialog.fields['password'].setText('plain password')
|
||||
dialog.save()
|
||||
self.assertEqual(dialog.result(), dialog.DialogCode.Accepted)
|
||||
self.assertEqual(dialog.config['password'], 'plain password')
|
||||
dialog.deleteLater()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user