~pkunal-parmar/ubuntu-calendar-app/ICalImport

« back to all changes in this revision

Viewing changes to tests/autopilot/calendar_app/tests/__init__.py

  • Committer: Tarmac
  • Author(s): nskaggs
  • Date: 2014-05-30 17:24:18 UTC
  • mfrom: (294.1.6 fix-ap-env-setup)
  • Revision ID: tarmac-20140530172418-v8uwra8uqiv5gm06
Tweaks for apparmor to allow _patch_home to function properly on the phone.

Approved by Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
        # Unset the current locale to ensure locale-specific data
79
79
        # (day and month names, first day of the week, …) doesn’t get
80
80
        # in the way of test expectations.
81
 
        self.patch_environment('LC_ALL', 'C')
 
81
        self.useFixture(fixtures.EnvironmentVariable('LC_ALL', newvalue='C'))
82
82
 
83
83
        self.app = launcher()
84
84
 
107
107
    def _copy_xauthority_file(self, directory):
108
108
        """ Copy .Xauthority file to directory, if it exists in /home
109
109
        """
110
 
        xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
 
110
        #If running under xvfb, as jenkins does,
 
111
        #xsession will fail to start without xauthority file
 
112
        #Thus if the Xauthority file is in the home directory
 
113
        #make sure we copy it to our temp home directory
 
114
 
 
115
        xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
 
116
                                   '.Xauthority'))
111
117
        if os.path.isfile(xauth):
112
 
            logger.debug("Copying .Xauthority to " + directory)
 
118
            logger.debug("Copying .Xauthority to %s" % directory)
113
119
            shutil.copyfile(
114
 
                os.path.expanduser(os.path.join('~', '.Xauthority')),
 
120
                os.path.expanduser(os.path.join(os.environ.get('HOME'),
 
121
                                   '.Xauthority')),
115
122
                os.path.join(directory, '.Xauthority'))
116
123
 
117
124
    def _patch_home(self):
120
127
        #click requires apparmor profile, and writing to special dir
121
128
        #but the desktop can write to a traditional /tmp directory
122
129
        if self.test_type == 'click':
123
 
            temp_dir = os.path.join('~', 'autopilot', 'fakeenv')
124
 
            logger.debug(temp_dir)
125
 
            temp_dir_fixture = fixtures.TempDir(temp_dir)
126
 
        else:
127
 
            temp_dir_fixture = fixtures.TempDir()
128
 
        self.useFixture(temp_dir_fixture)
129
 
        temp_dir = temp_dir_fixture.path
130
 
        logger.debug(temp_dir)
131
 
 
132
 
        #If running under xvfb, as jenkins does,
133
 
        #xsession will fail to start without xauthority file
134
 
        #Thus if the Xauthority file is in the home directory
135
 
        #make sure we copy it to our temp home directory
136
 
        self._copy_xauthority_file(temp_dir)
137
 
 
138
 
        #click requires using initctl env (upstart), but the desktop can set
139
 
        #an environment variable instead
140
 
        if self.test_type == 'click':
 
130
            env_dir = os.path.join(os.environ.get('HOME'), 'autopilot',
 
131
                                   'fakeenv')
 
132
 
 
133
            if not os.path.exists(env_dir):
 
134
                os.makedirs(env_dir)
 
135
 
 
136
            temp_dir_fixture = fixtures.TempDir(env_dir)
 
137
            self.useFixture(temp_dir_fixture)
 
138
 
 
139
            #apparmor doesn't allow the app to create needed directories,
 
140
            #so we create them now
 
141
            temp_dir = temp_dir_fixture.path
 
142
            temp_dir_cache = os.path.join(temp_dir, '.cache')
 
143
            temp_dir_cache_font = os.path.join(temp_dir_cache, 'fontconfig')
 
144
            temp_dir_cache_media = os.path.join(temp_dir_cache, 'media-art')
 
145
            temp_dir_cache_write = os.path.join(temp_dir_cache,
 
146
                                                'tncache-write-text.null')
 
147
            temp_dir_config = os.path.join(temp_dir, '.config')
 
148
            temp_dir_toolkit = os.path.join(temp_dir_config,
 
149
                                            'ubuntu-ui-toolkit')
 
150
            temp_dir_font = os.path.join(temp_dir_cache, '.fontconfig')
 
151
            temp_dir_local = os.path.join(temp_dir, '.local', 'share')
 
152
            temp_dir_confined = os.path.join(temp_dir, 'confined')
 
153
 
 
154
            if not os.path.exists(temp_dir_cache):
 
155
                os.makedirs(temp_dir_cache)
 
156
            if not os.path.exists(temp_dir_cache_font):
 
157
                os.makedirs(temp_dir_cache_font)
 
158
            if not os.path.exists(temp_dir_cache_media):
 
159
                os.makedirs(temp_dir_cache_media)
 
160
            if not os.path.exists(temp_dir_cache_write):
 
161
                os.makedirs(temp_dir_cache_write)
 
162
            if not os.path.exists(temp_dir_config):
 
163
                os.makedirs(temp_dir_config)
 
164
            if not os.path.exists(temp_dir_toolkit):
 
165
                os.makedirs(temp_dir_toolkit)
 
166
            if not os.path.exists(temp_dir_font):
 
167
                os.makedirs(temp_dir_font)
 
168
            if not os.path.exists(temp_dir_local):
 
169
                os.makedirs(temp_dir_local)
 
170
            if not os.path.exists(temp_dir_confined):
 
171
                os.makedirs(temp_dir_confined)
 
172
 
 
173
            #before we set fixture, copy xauthority if needed
 
174
            self._copy_xauthority_file(temp_dir)
141
175
            self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
142
176
                            HOME=temp_dir))
143
177
        else:
 
178
            temp_dir_fixture = fixtures.TempDir()
 
179
            self.useFixture(temp_dir_fixture)
 
180
            temp_dir = temp_dir_fixture.path
 
181
 
 
182
            #before we set fixture, copy xauthority if needed
 
183
            self._copy_xauthority_file(temp_dir)
144
184
            self.useFixture(fixtures.EnvironmentVariable('HOME',
145
185
                                                         newvalue=temp_dir))
146
186
 
147
 
        logger.debug("Patched home to fake home directory " + temp_dir)
148
 
 
 
187
        logger.debug("Patched home to fake home directory %s" % temp_dir)
149
188
        return temp_dir
150
189
 
151
190
    @property