def test_it_redirects_to_via3_view_pdf_directly_for_google_drive( self, pyramid_request): google_drive_url = "https://drive.google.com/uc?id=<SOME-ID>&export=download" final_url = via_url(pyramid_request, google_drive_url) assert final_url == Any.url.matching( "http://test_via3_server.is/pdf").containing_query( {"url": google_drive_url})
def test_if_creates_the_correct_via_url(self, pyramid_request): url = "http://example.com" final_url = via_url(pyramid_request, url) assert final_url == Any.url.matching( "http://test_via3_server.is/route").with_query( dict(self.DEFAULT_OPTIONS, url=url))
def add_document_url(self, document_url): """ Set the document to the document at the given document_url. :raise HTTPBadRequest: if a request param needed to generate the config is missing """ self._config["viaUrl"] = via_url(self._request, document_url) self._add_canvas_speedgrader_settings(document_url=document_url)
def test_it_merges_params_correctly(self, pyramid_request, params, expected_extras): final_url = via_url( pyramid_request, f"http://doc.example.com/?{urlencode(params, doseq=True)}") assert final_url == Any.url.containing_query(self.DEFAULT_OPTIONS) if expected_extras: assert final_url == Any.url.containing_query(expected_extras)
def via_url(self): """ Return the Via URL for annotating the given Canvas file. :raise lms.services.CanvasAPIError: if the Canvas API request fails. This exception is caught and handled by an exception view. """ public_url = self.canvas_api_client.public_url( self.request.matchdict["file_id"]) # Currently we only let users pick PDF files, so we can save a little # time by specifying this, instead of Via having to work it out via_url = helpers.via_url(self.request, public_url, content_type="pdf") return {"via_url": via_url}
def test_it_passes_through_the_url(self, pyramid_request, url): final_url = via_url(pyramid_request, url) assert final_url == Any.url.with_host( "test_legacy_via_server.is").with_path(url)
def test_it_redirects_to_via3_view_pdf_directly_if_content_type_is_pdf( self, pyramid_request): final_url = via_url(pyramid_request, "any url", content_type="pdf") assert (final_url == Any.url.matching( "http://test_via3_server.is/pdf").with_query())