~zsombi/ubuntu-ui-toolkit/dynamic-tabs-test-failure

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntuuitoolkit/tests/test_fixture_setup.py

  • Committer: CI bot
  • Author(s): Leo Arias
  • Date: 2014-04-04 11:02:58 UTC
  • mfrom: (947.7.11 initctl_env_var)
  • Revision ID: ps-jenkins@lists.canonical.com-20140404110258-v1u81uzptpgjn9w9
Added a helper for autopilot tests to override the values of initctl vars during tests. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from autopilot import testcase as autopilot_testcase
27
27
from testtools.matchers import Contains, Not, FileExists
28
28
 
29
 
from ubuntuuitoolkit import base, fixture_setup
 
29
from ubuntuuitoolkit import base, environment, fixture_setup
30
30
 
31
31
 
32
32
class FakeApplicationTestCase(testtools.TestCase):
166
166
 
167
167
        # We can select a component from the application.
168
168
        self.application.select_single('Label', objectName='testLabel')
 
169
 
 
170
 
 
171
class InitctlEnvironmentVariableTestCase(testtools.TestCase):
 
172
 
 
173
    def test_use_initctl_environment_variable_with_unset_variable(self):
 
174
        """Test the initctl env var fixture when the var is unset.
 
175
 
 
176
        During the test, the new value must be in place.
 
177
        After the test, the variable must be unset again.
 
178
 
 
179
        """
 
180
        initctl_env_var = fixture_setup.InitctlEnvironmentVariable(
 
181
            testenvvarforfixture='test value')
 
182
 
 
183
        result = testtools.TestResult()
 
184
 
 
185
        def inner_test():
 
186
            class TestWithInitctlEnvVar(testtools.TestCase):
 
187
                def test_it(self):
 
188
                    self.useFixture(initctl_env_var)
 
189
                    self.assertEqual(
 
190
                        'test value',
 
191
                        environment.get_initctl_env_var(
 
192
                            'testenvvarforfixture'))
 
193
            return TestWithInitctlEnvVar('test_it')
 
194
 
 
195
        inner_test().run(result)
 
196
 
 
197
        self.assertTrue(
 
198
            result.wasSuccessful(), 'Failed to set the environment variable.')
 
199
        self.assertFalse(
 
200
            environment.is_initctl_env_var_set('testenvvarforfixture'))
 
201
 
 
202
    def test_use_initctl_environment_variable_with_set_variable(self):
 
203
        """Test the initctl env var fixture when the var is unset.
 
204
 
 
205
        During the test, the new value must be in place.
 
206
        After the test, the old value must be set again.
 
207
 
 
208
        """
 
209
        self.addCleanup(
 
210
            environment.unset_initctl_env_var, 'testenvvarforfixture')
 
211
        environment.set_initctl_env_var(
 
212
            'testenvvarforfixture', 'original test value')
 
213
 
 
214
        initctl_env_var = fixture_setup.InitctlEnvironmentVariable(
 
215
            testenvvarforfixture='new test value')
 
216
 
 
217
        result = testtools.TestResult()
 
218
 
 
219
        def inner_test():
 
220
            class TestWithInitctlEnvVar(testtools.TestCase):
 
221
                def test_it(self):
 
222
                    self.useFixture(initctl_env_var)
 
223
                    self.assertEqual(
 
224
                        'new test value',
 
225
                        environment.get_initctl_env_var(
 
226
                            'testenvvarforfixture'))
 
227
            return TestWithInitctlEnvVar('test_it')
 
228
 
 
229
        inner_test().run(result)
 
230
 
 
231
        self.assertTrue(
 
232
            result.wasSuccessful(), 'Failed to set the environment variable.')
 
233
        self.assertEqual(
 
234
            'original test value',
 
235
            environment.get_initctl_env_var('testenvvarforfixture'))