48
50
'QT_LOAD_TESTABILITY'
55
class FillCustomHistory(fixtures.Fixture):
57
history_db = "history.sqlite"
58
data_sys = "/usr/lib/python3/dist-packages/dialer_app/data/"
59
data_local = "dialer_app/data/"
60
database_path = '/tmp/' + history_db
62
prefilled_history_local = os.path.join(data_local, history_db)
63
prefilled_history_system = os.path.join(data_sys, history_db)
66
super(FillCustomHistory, self).setUp()
67
self.addCleanup(self._clear_test_data)
68
self.addCleanup(self._kill_service_to_respawn)
69
self._clear_test_data()
70
self._prepare_history_data()
71
self._kill_service_to_respawn()
72
self._start_service_with_custom_data()
74
def _prepare_history_data(self):
75
if os.path.exists(self.prefilled_history_local):
76
shutil.copy(self.prefilled_history_local, self.database_path)
78
shutil.copy(self.prefilled_history_system, self.database_path)
80
def _clear_test_data(self):
81
if os.path.exists(self.database_path):
82
os.remove(self.database_path)
84
def _kill_service_to_respawn(self):
85
subprocess.call(['pkill', 'history-daemon'])
87
def _start_service_with_custom_data(self):
88
os.environ['HISTORY_SQLITE_DBPATH'] = self.database_path
89
with open(os.devnull, 'w') as devnull:
90
subprocess.Popen(['history-daemon'], stderr=devnull)
93
class UseEmptyHistory(FillCustomHistory):
94
database_path = ':memory:'
97
super(UseEmptyHistory, self).setUp()
99
def _prepare_history_data(self):
100
# just avoid doing anything
101
self.database_path = ':memory:'
103
def _clear_test_data(self):
105
self.database_path = ''
108
class UsePhonesimModem(fixtures.Fixture):
113
# configure the cleanups
114
self.addCleanup(self._hangupLeftoverCalls)
115
self.addCleanup(self._restoreModems)
117
self._switchToPhonesim()
119
def _switchToPhonesim(self):
120
# make sure the modem is running on phonesim
121
subprocess.call(['mc-tool', 'update', 'ofono/ofono/account0',
122
'string:modem-objpath=/phonesim'])
123
subprocess.call(['mc-tool', 'reconnect', 'ofono/ofono/account0'])
125
def _hangupLeftoverCalls(self):
126
# ensure that there are no leftover calls in case of failed tests
127
subprocess.call(["/usr/share/ofono/scripts/hangup-all", "/phonesim"])
129
def _restoreModems(self):
130
# set the modem objpath in telepathy-ofono to the real modem
131
subprocess.call(['mc-tool', 'update', 'ofono/ofono/account0',
132
'string:modem-objpath=/ril_0'])
133
subprocess.call(['mc-tool', 'reconnect', 'ofono/ofono/account0'])