hydrus/include/TestDialogs.py

208 lines
5.7 KiB
Python
Raw Normal View History

2013-07-31 21:26:38 +00:00
import ClientConstants as CC
2015-03-18 21:46:29 +00:00
import ClientDefaults
2013-07-24 20:26:00 +00:00
import ClientGUIDialogs
2018-03-07 22:48:29 +00:00
import ClientGUIScrolledPanelsEdit
2017-01-18 22:52:39 +00:00
import ClientGUIScrolledPanelsManagement
import ClientGUITopLevelWindows
2018-01-03 22:37:30 +00:00
import ClientThreading
2013-07-24 20:26:00 +00:00
import collections
import HydrusConstants as HC
import os
import TestConstants
import unittest
import wx
2017-05-10 21:33:58 +00:00
import HydrusGlobals as HG
2013-07-24 20:26:00 +00:00
2018-01-03 22:37:30 +00:00
def HitButton( button ):
2018-02-21 21:59:37 +00:00
wx.QueueEvent( button, wx.CommandEvent( commandEventType = wx.EVT_BUTTON.typeId, id = button.GetId() ) )
2018-01-03 22:37:30 +00:00
def HitCancelButton( window ):
2018-02-21 21:59:37 +00:00
wx.QueueEvent( window, wx.CommandEvent( commandEventType = wx.EVT_BUTTON.typeId, id = wx.ID_CANCEL ) )
2018-01-03 22:37:30 +00:00
def HitOKButton( window ):
2018-02-21 21:59:37 +00:00
wx.QueueEvent( window, wx.CommandEvent( commandEventType = wx.EVT_BUTTON.typeId, id = wx.ID_OK ) )
2018-01-03 22:37:30 +00:00
2017-01-18 22:52:39 +00:00
def CancelChildDialog( window ):
children = window.GetChildren()
for child in children:
if isinstance( child, wx.Dialog ):
HitCancelButton( child )
def OKChildDialog( window ):
children = window.GetChildren()
for child in children:
if isinstance( child, wx.Dialog ):
HitOKButton( child )
2018-01-03 22:37:30 +00:00
2013-07-31 21:26:38 +00:00
def PressKey( window, key ):
2018-01-03 22:37:30 +00:00
window.SetFocus()
2013-07-31 21:26:38 +00:00
2018-01-03 22:37:30 +00:00
uias = wx.UIActionSimulator()
2013-07-31 21:26:38 +00:00
2018-01-03 22:37:30 +00:00
uias.Char( key )
2013-07-31 21:26:38 +00:00
class TestDBDialogs( unittest.TestCase ):
def test_dialog_select_booru( self ):
2017-05-10 21:33:58 +00:00
HG.test_controller.SetRead( 'remote_boorus', ClientDefaults.GetDefaultBoorus() )
2013-07-31 21:26:38 +00:00
with ClientGUIDialogs.DialogSelectBooru( None ) as dlg:
2014-01-08 18:40:02 +00:00
HitCancelButton( dlg )
2013-07-31 21:26:38 +00:00
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_CANCEL )
2017-01-18 22:52:39 +00:00
def test_dialog_manage_subs( self ):
title = 'subs test'
2018-03-07 22:48:29 +00:00
with ClientGUITopLevelWindows.DialogEdit( None, title ) as dlg:
2017-01-18 22:52:39 +00:00
2018-03-07 22:48:29 +00:00
panel = ClientGUIScrolledPanelsEdit.EditSubscriptionsPanel( dlg, [] )
2017-01-18 22:52:39 +00:00
dlg.SetPanel( panel )
2018-02-28 22:30:36 +00:00
HG.test_controller.CallLaterWXSafe( dlg, 2, panel.Add )
2017-01-18 22:52:39 +00:00
2018-02-28 22:30:36 +00:00
HG.test_controller.CallLaterWXSafe( dlg, 4, OKChildDialog, panel )
2017-01-18 22:52:39 +00:00
2018-02-28 22:30:36 +00:00
HG.test_controller.CallLaterWXSafe( dlg, 6, HitCancelButton, dlg )
2017-01-18 22:52:39 +00:00
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_CANCEL )
2013-07-31 21:26:38 +00:00
class TestNonDBDialogs( unittest.TestCase ):
2013-07-24 20:26:00 +00:00
def test_dialog_choose_new_service_method( self ):
with ClientGUIDialogs.DialogChooseNewServiceMethod( None ) as dlg:
HitButton( dlg._register )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_OK )
register = dlg.GetRegister()
self.assertEqual( register, True )
with ClientGUIDialogs.DialogChooseNewServiceMethod( None ) as dlg:
HitButton( dlg._setup )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_OK )
register = dlg.GetRegister()
self.assertEqual( register, False )
with ClientGUIDialogs.DialogChooseNewServiceMethod( None ) as dlg:
2014-01-08 18:40:02 +00:00
HitCancelButton( dlg )
2013-07-24 20:26:00 +00:00
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_CANCEL )
def test_dialog_finish_filtering( self ):
2017-04-19 20:58:30 +00:00
with ClientGUIDialogs.DialogFinishFiltering( None, 'keep 3 files and delete 5 files?' ) as dlg:
2013-07-24 20:26:00 +00:00
HitButton( dlg._back )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_CANCEL )
2017-04-19 20:58:30 +00:00
with ClientGUIDialogs.DialogFinishFiltering( None, 'keep 3 files and delete 5 files?' ) as dlg:
2013-07-24 20:26:00 +00:00
HitButton( dlg._commit )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_YES )
2017-04-19 20:58:30 +00:00
with ClientGUIDialogs.DialogFinishFiltering( None, 'keep 3 files and delete 5 files?' ) as dlg:
2013-07-24 20:26:00 +00:00
HitButton( dlg._forget )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_NO )
2013-07-31 21:26:38 +00:00
def test_select_from_list_of_strings( self ):
2017-03-02 02:14:56 +00:00
list_of_tuples = [ ( 'a', 123 ), ( 'b', 456 ), ( 'c', 789 ) ]
2013-07-31 21:26:38 +00:00
2017-03-08 23:23:12 +00:00
with ClientGUIDialogs.DialogSelectFromList( None, 'select from a list of strings', list_of_tuples ) as dlg:
2013-07-31 21:26:38 +00:00
2018-02-28 22:30:36 +00:00
HG.test_controller.CallLaterWXSafe( self, 0.5, dlg._list.Select, 1 )
HG.test_controller.CallLaterWXSafe( self, 1, PressKey, dlg._list, wx.WXK_RETURN )
2013-07-31 21:26:38 +00:00
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_OK )
2017-03-02 02:14:56 +00:00
value = dlg.GetChoice()
2013-07-31 21:26:38 +00:00
2017-03-02 02:14:56 +00:00
self.assertEqual( value, 456 )
2013-07-31 21:26:38 +00:00
def test_dialog_yes_no( self ):
with ClientGUIDialogs.DialogYesNo( None, 'hello' ) as dlg:
HitButton( dlg._yes )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_YES )
with ClientGUIDialogs.DialogYesNo( None, 'hello' ) as dlg:
HitButton( dlg._no )
result = dlg.ShowModal()
self.assertEqual( result, wx.ID_NO )
2017-01-18 22:52:39 +00:00