def screenshot_check(self, vrt_name, vrt_viewport, vrt_os, vrt_device): config = Config( # apiUrl - URL where backend is running apiUrl=Configuration.vrt_apiUrl, # project - Project name or ID project=Configuration.vrt_project, # apiKey - User apiKey apiKey=Configuration.vrt_apiKey, # ciBuildId - Current git commit SHA ciBuildId=Configuration.vrt_ciBuildId, # branch - Current git branch branchName=Configuration.vrt_branchName, # enableSoftAssert - Log errors instead of exceptions enableSoftAssert=Configuration.vrt_enableSoftAssert, ) vrt = VisualRegressionTracker(config) scr = self.screenshot_for_vrt() with vrt: vrt.track(TestRun( name=vrt_name, imageBase64=scr, diffTollerancePercent=0, os=vrt_os, browser='Chrome', viewport=vrt_viewport, device=vrt_device, )) return self
def test_default_uses_defaults(config_env, mocker): mocker.patch('os.path.isfile').return_value = False del config_env['VRT_CIBUILDID'] del config_env['VRT_APIURL'] cfg = Config.default(environment=config_env) assert cfg.apiUrl == Config.apiUrl assert cfg.ciBuildId is None
def test_default_uses_path(config_file): cfg = Config.default(path=config_file, environment={}) assert cfg.apiUrl == 'file api url' assert cfg.ciBuildId == 'file ci build id' assert cfg.branchName == 'file branch name' assert cfg.project == 'file project' assert cfg.apiKey == 'file api key' assert cfg.enableSoftAssert == True
def test_config_from_environment(config_env): cfg = Config.from_environment(config_env) assert cfg.apiUrl == 'env api url' assert cfg.ciBuildId == 'env ci build id' assert cfg.branchName == 'env branch name' assert cfg.project == 'env project' assert cfg.apiKey == 'env api key' assert cfg.enableSoftAssert == False
def test_config_from_file(config_file): cfg = Config.from_file(config_file) assert cfg.apiUrl == 'file api url' assert cfg.ciBuildId == 'file ci build id' assert cfg.branchName == 'file branch name' assert cfg.project == 'file project' assert cfg.apiKey == 'file api key' assert cfg.enableSoftAssert == True
def test_default_uses_environment(config_env, mocker): mocker.patch('os.path.isfile').return_value = False cfg = Config.default(environment=config_env) assert cfg.apiUrl == 'env api url' assert cfg.ciBuildId == 'env ci build id' assert cfg.branchName == 'env branch name' assert cfg.project == 'env project' assert cfg.apiKey == 'env api key' assert cfg.enableSoftAssert == False
def test_default_uses_default_path(mocker, config_file): config_file_data = open(config_file).read() mocker.patch('builtins.open', mocker.mock_open(read_data=config_file_data)) mocker.patch('os.path.isfile').return_value = True cfg = Config.default(environment={}) assert cfg.apiUrl == 'file api url' assert cfg.ciBuildId == 'file ci build id' assert cfg.branchName == 'file branch name' assert cfg.project == 'file project' assert cfg.apiKey == 'file api key' assert cfg.enableSoftAssert == True
import pytest from visual_regression_tracker import \ Config, IgnoreArea, VisualRegressionTracker, \ TestRun, TestRunResponse, TestRunStatus, \ ServerError, TestRunError, VisualRegressionTrackerError from visual_regression_tracker.types import \ _to_dict from visual_regression_tracker.visualRegressionTracker import \ _http_request CONFIG = Config( apiUrl='http://localhost:4200', ciBuildId='CI Build Id', branchName='develop', project='Default project', apiKey='CPKVK4JNK24NVNPNGVFQ853HXXEG', enableSoftAssert=False, ) @pytest.fixture def mock_request(mocker): yield mocker.patch('visual_regression_tracker.visualRegressionTracker' '._http_request') @pytest.fixture def vrt(): yield VisualRegressionTracker(CONFIG)
def test_default_raises_on_missing_settings(mocker, config_env, missing_field): mocker.patch('os.path.isfile').return_value = False del config_env[ENV_MAPPING[missing_field]] with pytest.raises(MissingConfigurationError): Config.default(environment=config_env)
def test_default_raises_on_invalid_path(): with pytest.raises(IOError): Config.default(path='/does/not/exist/vrt.json')
def test_default_prefers_environment(config_env, config_file): del config_env['VRT_PROJECT'] cfg = Config.default(path=config_file, environment=config_env) assert cfg.ciBuildId == 'env ci build id' assert cfg.project == 'file project'
import pytest from visual_regression_tracker import \ Config, VisualRegressionTracker, \ TestRun, TestRunResult, TestRunStatus from visual_regression_tracker.visualRegressionTracker import \ _http_request from visual_regression_tracker.types import \ _to_dict CONFIG = Config( apiUrl='http://localhost:4200', branchName='develop', project='Default project', apiKey='CPKVK4JNK24NVNPNGVFQ853HXXEG', ) @pytest.fixture def mock_request(mocker): yield mocker.patch('visual_regression_tracker.visualRegressionTracker' '._http_request') @pytest.fixture def vrt(): yield VisualRegressionTracker(CONFIG) @pytest.mark.parametrize('buildId,projectId,expectedResult', [ (None, None, False), (None, "some", False),