Beispiel #1
0
    def setUpClass(cls):
        super(Tests, cls).setUpClass()

        if os.environ.get('PERCY_ENABLED', False):
            loader = percy.ResourceLoader(webdriver=cls.driver)
            percy_config = percy.Config(default_widths=[1280])
            cls.percy_runner = percy.Runner(loader=loader, config=percy_config)
            cls.percy_runner.initialize_build()
    def test_snapshot(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        webdriver = FakeWebdriver()
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/', webdriver=webdriver)
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        response_text = json.dumps(SIMPLE_BUILD_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/', text=response_text)
        runner.initialize_build()

        # Plain snapshot without a missing resource.
        response_text = json.dumps(SIMPLE_SNAPSHOT_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/123/snapshots/', text=response_text)
        mock.post('https://percy.io/api/v1/snapshots/256/finalize', text='{"success": true}')
        runner.snapshot()

        # Snapshot with a missing resource.
        response_text = json.dumps({
            'data': {
                'id': '256',
                'type': 'snapshots',
                'relationships': {
                    'self': '/api/v1/snapshots/256',
                    'missing-resources': {
                        'data': [
                            {
                                'type': 'resources',
                                'id': loader.snapshot_resources[0].sha,
                            },
                        ],
                    },
                },
            },
        })
        mock.post('https://percy.io/api/v1/builds/123/snapshots/', text=response_text)
        mock.post('https://percy.io/api/v1/builds/123/resources/', text='{"success": true}')
        mock.post('https://percy.io/api/v1/snapshots/256/finalize', text='{"success": true}')
        runner.snapshot(name='foo', enable_javascript=True, widths=[1280])

        # Assert that kwargs are passed through correctly to create_snapshot.
        assert mock.request_history[3].json()['data']['attributes'] == {
            'enable-javascript': True,
            'name': 'foo',
            'widths': [1280],
        }

        # Assert that the snapshot resource was uploaded correctly.
        assert mock.request_history[4].json() == {
            'data': {
                'type': 'resources',
                'id': loader.snapshot_resources[0].sha,
                'attributes': {
                    'base64-content': utils.base64encode(FakeWebdriver.page_source)
                },
            },
        }
Beispiel #3
0
 def Percy_Initialize_Build(self, access_token):
     driver = BuiltIn().get_library_instance('Selenium2Library')._current_browser()
     root_static_dir = os.path.join(os.path.dirname(__file__), '/Users/InternDN19.01.02/Documents/joomla_build2')
     loader = percy.ResourceLoader(
       root_dir=root_static_dir,
       base_url='/joomla_build2',
       webdriver=driver,
     )
     config = percy.Config(access_token=access_token)
     self.percy_runner = percy.Runner(loader=loader, config=config)
     self.percy_runner.initialize_build()
Beispiel #4
0
    def test_initialize_build_raises_error_when_token_incorrect(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/')
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        response_text = json.dumps(SIMPLE_ERROR_RESPONSE_FIXTURE)
        mock.post('https://percy.io/api/v1/repos/foo/bar/builds/',
                  text=response_text)

        self.assertRaises(errors.AuthError,
                          lambda: runner.initialize_build(repo='foo/bar'))
Beispiel #5
0
def percy(request):
    import percy

    # Initialize Percy.
    loader = percy.ResourceLoader(
        root_dir=settings.STATIC_ROOT, base_url=quote(settings.STATIC_URL)
    )
    percy_config = percy.Config(default_widths=settings.PERCY_DEFAULT_TESTING_WIDTHS)
    percy = percy.Runner(loader=loader, config=percy_config)
    percy.initialize_build()

    request.addfinalizer(percy.finalize_build)
    return percy
    def test_initialize_build(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/')
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        response_text = json.dumps(SIMPLE_BUILD_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/', text=response_text)
        runner.initialize_build()

        # Whitebox check that the current build data is set correctly.
        assert runner._current_build == SIMPLE_BUILD_FIXTURE
        assert runner.build_id == SIMPLE_BUILD_FIXTURE['data']['id']
    def test_finalize_build(self, mock):
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config)

        self.assertRaises(errors.UninitializedBuildError, lambda: runner.finalize_build())

        response_text = json.dumps(SIMPLE_BUILD_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/', text=response_text)
        runner.initialize_build()

        mock.post('https://percy.io/api/v1/builds/123/finalize', text='{"success": true}')
        runner.finalize_build()
        assert mock.request_history[1].json() == {}

        # Whitebox check that the current build data is reset.
        assert runner._current_build == None
Beispiel #8
0
    def __init__(self, loader=None, config=None, client=None):
        self.loader = loader
        self.config = config or percy.Config()
        self.client = client or percy.Client(config=self.config)
        self._current_build = None

        self._is_enabled = os.getenv('PERCY_ENABLE', '1') == '1'

        # Sanity check environment and auth setup. If in CI and Percy is disabled, print an error.
        if self._is_enabled:
            try:
                self.client.config.access_token
            except errors.AuthError:
                if self.client.environment.current_ci:
                    utils.print_error('[percy] Warning: Percy is disabled, no PERCY_TOKEN set.')
                self._is_enabled = False
 def Percy_Initialize_Build(self, **kwargs):
     driver = BuiltIn().get_library_instance('SeleniumLibrary').driver
     loader = percy.ResourceLoader(root_dir=kwargs.get('root_dir'),
                                   base_url=kwargs.get('base_url'),
                                   webdriver=driver)
     # api_url
     # access_token
     # default_widths
     config = percy.Config(**kwargs)
     self.percy_runner = percy.Runner(loader=loader, config=config)
     # branch
     # pull_request_number
     # parallel_nonce
     # parallel_total_shards
     # commit_data
     self.percy_runner.initialize_build(**kwargs)
Beispiel #10
0
    def test_initialize_build_sends_missing_resources(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/')
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        build_fixture = {
            'data': {
                'id': '123',
                'type': 'builds',
                'relationships': {
                    'self': "/api/v1/snapshots/123",
                    'missing-resources': {
                        'data': [
                            {
                                'type': 'resources',
                                'id': loader.build_resources[0].sha,
                            },
                        ],
                    },
                },
            },
        }
        mock.post('https://percy.io/api/v1/repos/foo/bar/builds/',
                  text=json.dumps(build_fixture))
        mock.post('https://percy.io/api/v1/builds/123/resources/',
                  text='{"success": true}')
        runner.initialize_build(repo='foo/bar')

        # Make sure the missing resources were uploaded. The mock above will not fail if not called.
        with open(loader.build_resources[0].local_path, 'r') as f:
            content = f.read()
        assert len(content) > 0
        assert mock.request_history[1].json() == {
            'data': {
                'type': 'resources',
                'id': loader.build_resources[0].sha,
                'attributes': {
                    'base64-content': utils.base64encode(content)
                },
            },
        }
Beispiel #11
0
    def setUp(self):
        config = percy.Config(access_token='foo')
        environment = percy.Environment()

        self.percy_connection = connection.Connection(config, environment)
Beispiel #12
0
 def setUp(self):
     percy_config = percy.Config(access_token='abcd1234',
                                 default_widths=[1280, 375])
     self.percy_client = percy.Client(config=percy_config)
Beispiel #13
0
 def setUp(self):
     self.config = percy.Config(access_token='foo')
     self.environment = percy.Environment()
 def test_init(self):
     runner = percy.Runner()
     assert runner.client.config.default_widths == []
     runner = percy.Runner(config=percy.Config(default_widths=[1280, 375]))
     assert runner.client.config.default_widths == [1280, 375]