~boiko/dialer-app/rtm-fix_call_hangup_and_test_multi_call

« back to all changes in this revision

Viewing changes to tests/autopilot/dialer_app/fixture_setup.py

  • Committer: Gustavo Pichorim Boiko
  • Date: 2015-04-16 16:21:47 UTC
  • Revision ID: gustavo.boiko@canonical.com-20150416162147-hybrjhhok69i55y6
Make sure the correct call is finished when pressing the hangup button on a multi-call scenario.
Also add autopilot tests to avoid this happening in the future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import fixtures
21
21
import subprocess
 
22
import os
 
23
import shutil
22
24
 
23
25
 
24
26
class TestabilityEnvironment(fixtures.Fixture):
48
50
                'QT_LOAD_TESTABILITY'
49
51
            ]
50
52
        )
 
53
 
 
54
 
 
55
class FillCustomHistory(fixtures.Fixture):
 
56
 
 
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
 
61
 
 
62
    prefilled_history_local = os.path.join(data_local, history_db)
 
63
    prefilled_history_system = os.path.join(data_sys, history_db)
 
64
 
 
65
    def setUp(self):
 
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()
 
73
 
 
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)
 
77
        else:
 
78
            shutil.copy(self.prefilled_history_system, self.database_path)
 
79
 
 
80
    def _clear_test_data(self):
 
81
        if os.path.exists(self.database_path):
 
82
            os.remove(self.database_path)
 
83
 
 
84
    def _kill_service_to_respawn(self):
 
85
        subprocess.call(['pkill', 'history-daemon'])
 
86
 
 
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)
 
91
 
 
92
 
 
93
class UseEmptyHistory(FillCustomHistory):
 
94
    database_path = ':memory:'
 
95
 
 
96
    def setUp(self):
 
97
        super(UseEmptyHistory, self).setUp()
 
98
 
 
99
    def _prepare_history_data(self):
 
100
        # just avoid doing anything
 
101
        self.database_path = ':memory:'
 
102
 
 
103
    def _clear_test_data(self):
 
104
        # don't do anything
 
105
        self.database_path = ''
 
106
 
 
107
 
 
108
class UsePhonesimModem(fixtures.Fixture):
 
109
 
 
110
    def setUp(self):
 
111
        super().setUp()
 
112
 
 
113
        # configure the cleanups
 
114
        self.addCleanup(self._hangupLeftoverCalls)
 
115
        self.addCleanup(self._restoreModems)
 
116
 
 
117
        self._switchToPhonesim()
 
118
 
 
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'])
 
124
 
 
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"])
 
128
 
 
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'])