hydrus/include/TestConstants.py

103 lines
2.4 KiB
Python
Raw Normal View History

2013-12-11 22:09:25 +00:00
import collections
2017-03-22 22:38:15 +00:00
import ClientConstants as CC
2013-07-10 20:25:57 +00:00
import HydrusConstants as HC
2017-06-28 20:23:21 +00:00
import HydrusGlobals as HG
2013-07-17 20:56:13 +00:00
import HydrusTags
2013-07-10 20:25:57 +00:00
import os
import random
2013-12-11 22:09:25 +00:00
import threading
2014-06-18 21:53:48 +00:00
import weakref
2015-03-25 22:04:19 +00:00
import HydrusData
2017-06-28 20:23:21 +00:00
import HydrusThreading
2017-03-22 22:38:15 +00:00
import wx
2013-07-31 21:26:38 +00:00
2016-10-12 21:52:50 +00:00
DB_DIR = None
2017-07-19 21:21:41 +00:00
tiniest_gif = '\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x00\xFF\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00\x3B'
2013-07-10 20:25:57 +00:00
2017-04-26 21:58:12 +00:00
LOCAL_RATING_LIKE_SERVICE_KEY = HydrusData.GenerateKey()
LOCAL_RATING_NUMERICAL_SERVICE_KEY = HydrusData.GenerateKey()
def ConvertServiceKeysToContentUpdatesToComparable( service_keys_to_content_updates ):
comparable_dict = {}
for ( service_key, content_updates ) in service_keys_to_content_updates.items():
comparable_dict[ service_key ] = set( content_updates )
return comparable_dict
2017-06-28 20:23:21 +00:00
class MockController( object ):
def __init__( self ):
self.model_is_shutdown = False
def CallToThread( self, callable, *args, **kwargs ):
return HG.test_controller.CallToThread( callable, *args, **kwargs )
def ModelIsShutdown( self ):
2017-07-05 21:09:28 +00:00
return self.model_is_shutdown or HG.test_controller.ModelIsShutdown()
2017-06-28 20:23:21 +00:00
2017-10-25 21:45:15 +00:00
class MockServicesManager( object ):
2013-07-31 21:26:38 +00:00
2017-10-25 21:45:15 +00:00
def __init__( self, services ):
2013-11-06 18:22:07 +00:00
2017-10-25 21:45:15 +00:00
self._service_keys_to_services = { service.GetServiceKey() : service for service in services }
2013-07-31 21:26:38 +00:00
2017-10-25 21:45:15 +00:00
def GetName( self, service_key ):
2013-07-31 21:26:38 +00:00
2017-10-25 21:45:15 +00:00
return self._service_keys_to_services[ service_key ].GetName()
2013-07-31 21:26:38 +00:00
2017-10-25 21:45:15 +00:00
def GetService( self, service_key ):
2016-12-14 21:19:07 +00:00
2017-10-25 21:45:15 +00:00
return self._service_keys_to_services[ service_key ]
2016-12-14 21:19:07 +00:00
2017-10-25 21:45:15 +00:00
def ServiceExists( self, service_key ):
2013-07-31 21:26:38 +00:00
2017-10-25 21:45:15 +00:00
return service_key in self._service_keys_to_services
2013-07-31 21:26:38 +00:00
2013-12-04 22:44:16 +00:00
class FakeWebSessionManager():
2017-07-27 00:47:13 +00:00
def EnsureLoggedIn( self, name ):
pass
def GetCookies( self, *args, **kwargs ):
return { 'session_cookie' : 'blah' }
2016-12-14 21:19:07 +00:00
2017-03-22 22:38:15 +00:00
class TestFrame( wx.Frame ):
def __init__( self ):
wx.Frame.__init__( self, None )
def SetPanel( self, panel ):
vbox = wx.BoxSizer( wx.VERTICAL )
vbox.AddF( panel, CC.FLAGS_EXPAND_BOTH_WAYS )
self.SetSizer( vbox )
self.Fit()
self.Show()