def build_id(self):
     if not self._is_enabled:
         return
     if not self._current_build:
         raise errors.UninitializedBuildError(
             'Cannot get current build id before build is initialized')
     return self._current_build['data']['id']
 def finalize_build(self):
     # Silently pass if Percy is disabled.
     if not self._is_enabled:
         return
     if not self._current_build:
         raise errors.UninitializedBuildError(
             'Cannot finalize_build before build is initialized.')
     self.client.finalize_build(self._current_build['data']['id'])
     self._current_build = None
Exemple #3
0
    def snapshot(self, **kwargs):
        # Silently pass if Percy is disabled.
        if not self._is_enabled:
            return
        if not self._current_build:
            raise errors.UninitializedBuildError('Cannot call snapshot before build is initialized')

        root_resource = self.loader.snapshot_resources[0]
        build_id = self._current_build['data']['id']
        snapshot_data = self.client.create_snapshot(build_id, [root_resource], **kwargs)

        missing_resources = snapshot_data['data']['relationships']['missing-resources']
        missing_resources = missing_resources.get('data', [])

        if missing_resources:
            # There can only be one missing resource in this case, the root_resource.
            self.client.upload_resource(build_id, root_resource.content)

        self.client.finalize_snapshot(snapshot_data['data']['id'])