def process_all(self):
     for r_url, val in iteritems(self):
         if val is None:
             logger.debug("No response for {}".format(r_url))
             val = VGResource.EMPTY(r_url)
             self[r_url] = val
     return self
Beispiel #2
0
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 process_all(self):
     with self.lock:
         for r_url in self:
             val = self.get(r_url)
             if val is None:
                 logger.debug("No response for {}".format(r_url))
                 val = VGResource.EMPTY(r_url)
                 self[r_url] = val
     return self
Beispiel #4
0
 def get_resource(link):
     # type: (Text) -> VGResource
     if link.startswith("data:"):
         # resource already in blob
         return VGResource.EMPTY(link)
     response = self.eyes_connector.download_resource(link)
     return VGResource.from_response(link,
                                     response,
                                     on_created=handle_resources)
Beispiel #5
0
    def parse_frame_dom_resources(self, data):  # noqa
        # type: (Dict) -> RGridDom
        base_url = data["url"]
        resource_urls = data.get("resourceUrls", [])
        blobs = data.get("blobs", [])
        frames = data.get("frames", [])
        discovered_resources_urls = []

        def handle_resources(content_type, content):
            urls_from_css, urls_from_svg = [], []
            if content_type.startswith("text/css"):
                urls_from_css = parsers.get_urls_from_css_resource(content)
            if content_type.startswith("image/svg"):
                urls_from_svg = parsers.get_urls_from_svg_resource(content)
            for discovered_url in urls_from_css + urls_from_svg:
                target_url = _apply_base_url(discovered_url, base_url)
                with self.discovered_resources_lock:
                    discovered_resources_urls.append(target_url)

        def get_resource(link):
            # type: (Text) -> VGResource
            if link.startswith("data:"):
                # resource already in blob
                return VGResource.EMPTY(link)
            response = self.eyes_connector.download_resource(link)
            return VGResource.from_response(link,
                                            response,
                                            on_created=handle_resources)

        for f_data in frames:
            f_data["url"] = _apply_base_url(f_data["url"], base_url)
            self.request_resources[f_data[
                "url"]] = self.parse_frame_dom_resources(f_data).resource

        for blob in blobs:
            resource = VGResource.from_blob(blob, on_created=handle_resources)
            if resource.url.rstrip("#") == base_url:
                continue

            self.all_blobs.append(resource)
            self.request_resources[resource.url] = resource

        for r_url in set(resource_urls + discovered_resources_urls):
            self.resource_cache.fetch_and_store(r_url, get_resource)

        for r_url, val in iteritems(self.resource_cache):
            if val is None:
                val = VGResource.EMPTY(r_url)
            self.request_resources[r_url] = val

        return RGridDom(url=base_url,
                        dom_nodes=data["cdt"],
                        resources=self.request_resources)
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",
            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) == json.loads(
        json_utils.to_json(requests))