def test_render_request_serialize(browser_type): request_resources = {"url": VGResource.EMPTY("some-url.com")} dom_url = "dom-url.com" r_info = RenderInfo( width=500, height=600, size_mode="full-page", selector=None, region=None, emulation_info=None, ) dom = RGridDom( url=dom_url, dom_nodes=[{}], resources=request_resources, ) requests = [ RenderRequest( webhook="some-webhook.com", agent_id="my-agent-id", url=dom_url, dom=dom, resources=request_resources, render_info=r_info, browser_name=browser_type, platform="linux", script_hooks=dict(), selectors_to_find_regions_for=[], send_dom=False, ) ] RESULT_PATTERN = '[{"agentId": "my-agent-id", "browser": {"name": "%s", "platform": "linux"}, "dom": {"hash": "a67486a8bc9ba45f878e5b0d8ff9bc68ec6ed9db0382709751327d1793898e16", "hashFormat": "sha256"}, "renderId": null, "renderInfo": {"height": 600, "sizeMode": "full-page", "width": 500}, "resources": {"url": {"contentType": "application/empty-response", "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "hashFormat": "sha256"}}, "scriptHooks": {}, "selectorsToFindRegionsFor": [], "sendDom": false, "url": "dom-url.com", "webhook": "some-webhook.com"}]' assert RESULT_PATTERN % (browser_type.value) == json_utils.to_json( requests)
def prepare_data_for_rg(self, data): # type: (Dict) -> RenderRequest base_url = data["url"] resource_urls = data.get("resourceUrls", []) blobs = data.get("blobs", []) for blob in blobs: resource = VGResource.from_blob(blob) if resource.url.rstrip("#") == base_url: continue self.all_blobs.append(resource) self.request_resources[resource.url] = resource if resource.content_type == "text/css": urls_from_css = _get_urls_from_css_resource(resource) resource_urls.extend(urls_from_css) def get_resource(link): # type: (Text) -> VGResource response = self.eyes_connector.download_resource(link) return VGResource.from_response(link, response) for r_url in set(resource_urls): self.resource_cache.fetch_and_store(r_url, get_resource) self.request_resources.update(self.resource_cache) r_info = RenderInfo( width=self.running_test.browser_info.width, height=self.running_test.browser_info.height, size_mode=self.size_mode, region=self.region_to_check, emulation_info=self.running_test.browser_info.emulation_info, ) dom = RGridDom( url=base_url, dom_nodes=data["cdt"], resources=self.request_resources ) return RenderRequest( webhook=self.rendering_info.results_url, agent_id=self.agent_id, url=base_url, dom=dom, resources=self.request_resources, render_info=r_info, browser_name=self.running_test.browser_info.browser_type, platform=self.running_test.browser_info.platform, script_hooks={}, selectors_to_find_regions_for=self.region_selectors, send_dom=self.running_test.configuration.send_dom, )
def prepare_rg_requests(self, dom, request_resources): # type: (RGridDom, Dict) -> List[RenderRequest] if self.size_mode == "region" and self.region_to_check is None: raise EyesError("Region to check should be present") if self.size_mode == "selector" and not isinstance( self.selector, VisualGridSelector): raise EyesError("Selector should be present") requests = [] region = None for running_test in self.running_tests: if self.region_to_check: region = dict( x=self.region_to_check.x, y=self.region_to_check.y, width=self.region_to_check.width, height=self.region_to_check.height, ) r_info = RenderInfo.from_( size_mode=self.size_mode, selector=self.selector, region=region, render_browser_info=running_test.browser_info, ) requests.append( RenderRequest( webhook=self.rendering_info.results_url, agent_id=self.agent_id, url=dom.url, stitching_service=self.rendering_info. stitching_service_url, dom=dom, resources=request_resources, render_info=r_info, browser_name=running_test.browser_info.browser, platform_name=running_test.browser_info.platform, script_hooks=self.script_hooks, selectors_to_find_regions_for=list( chain(*self.region_selectors)), send_dom=running_test.configuration.send_dom, options=self.request_options, )) return requests
def job_info(self): # type: () -> JobInfo if self._job_info: return self._job_info render_requests = [ RenderRequest( render_info=RenderInfo.from_( size_mode=None, region=None, selector=None, render_browser_info=self._browser_info, ), platform_name=self._browser_info.platform, browser_name=self._browser_info.browser, ) ] self._job_info = self.server_connector.job_info(render_requests)[0] return self._job_info
def test_render_request_serialize(browser_type): request_resources = { "url": VGResource( "some-url.com", content_type="application/png", content=b"some-content" ) } dom_url = "dom-url.com" r_info = RenderInfo( width=500, height=600, size_mode="full-page", selector=None, region=None, emulation_info=None, ) dom = RGridDom(url=dom_url, dom_nodes=[{}], resources=request_resources) requests = [ RenderRequest( webhook="some-webhook.com", agent_id="my-agent-id", stitching_service="https://some.stitchingserviceuri.com", url=dom_url, dom=dom, resources=request_resources, render_info=r_info, browser_name=browser_type.value, platform_name="linux", script_hooks=dict(), selectors_to_find_regions_for=[], send_dom=False, ) ] test_results_data = get_resource("unit/renderResult.json").decode("utf-8") test_results_data %= browser_type.value assert json.loads(test_results_data.replace("\n", "")) == json.loads( json_utils.to_json(requests) )
def prepare_rg_requests(self, running_test, dom, request_resources): # type: (RunningTest, RGridDom, Dict) -> RenderRequest if self.size_mode == "region" and self.region_to_check is None: raise EyesError("Region to check should be present") if self.size_mode == "selector" and not isinstance( self.selector, VisualGridSelector): raise EyesError("Selector should be present") region = None if self.region_to_check: region = dict( x=self.region_to_check.x, y=self.region_to_check.y, width=self.region_to_check.width, height=self.region_to_check.height, ) r_info = RenderInfo( width=running_test.browser_info.width, height=running_test.browser_info.height, size_mode=self.size_mode, selector=self.selector, region=region, emulation_info=running_test.browser_info.emulation_info, ) return RenderRequest( webhook=self.rendering_info.results_url, agent_id=self.agent_id, url=dom.url, dom=dom, resources=request_resources, render_info=r_info, browser_name=running_test.browser_info.browser_type, platform=running_test.browser_info.platform, script_hooks=self.script_hooks, selectors_to_find_regions_for=list(chain(*self.region_selectors)), send_dom=running_test.configuration.send_dom, )