Exemplo n.º 1
0
 def test_unicode_path_info(self):
     web_service_request = WebServiceTestRequest(
         PATH_INFO=u'/api/devel\u1234'.encode('utf-8'))
     browser_request = web_service_request_to_browser_request(
         web_service_request)
     self.assertEqual(web_service_request.get('PATH_INFO'),
                      browser_request.get('PATH_INFO'))
Exemplo n.º 2
0
 def test_unicode_path_info(self):
     web_service_request = WebServiceTestRequest(
         PATH_INFO=u'/api/devel\u1234'.encode('utf-8'))
     browser_request = web_service_request_to_browser_request(
         web_service_request)
     self.assertEqual(
         web_service_request.get('PATH_INFO'),
         browser_request.get('PATH_INFO'))
Exemplo n.º 3
0
 def test_unmarshall(self):
     field = InlineObject(schema=IInlineExample)
     request = WebServiceTestRequest()
     request.setVirtualHostRoot(names=["devel"])
     marshaller = InlineObjectFieldMarshaller(field, request)
     obj = InlineExample(self.factory.makePerson(), JobStatus.WAITING)
     result = marshaller.unmarshall(None, obj)
     self.assertThat(
         result,
         MatchesDict({
             "person_link":
             Equals(canonical_url(obj.person, request=request)),
             "status":
             Equals("Waiting"),
         }))
Exemplo n.º 4
0
    def test_application_url(self):
        """Requests to the /api path should return the original request's
        host, not api.launchpad.net.
        """
        # Simulate a request to bugs.launchpad.net/api
        server_url = 'http://bugs.launchpad.dev'
        env = {
            'PATH_INFO': '/api/devel',
            'SERVER_URL': server_url,
            'HTTP_HOST': 'bugs.launchpad.dev',
        }

        # WebServiceTestRequest will suffice, as it too should conform to
        # the Same Origin web browser policy.
        request = WebServiceTestRequest(environ=env, version="1.0")
        self.assertEqual(request.getApplicationURL(), server_url)
Exemplo n.º 5
0
 def test_marshall_from_json_data(self):
     self.useFixture(ZopeAdapterFixture(inline_example_from_dict))
     field = InlineObject(schema=IInlineExample)
     request = WebServiceTestRequest()
     request.setVirtualHostRoot(names=["devel"])
     marshaller = InlineObjectFieldMarshaller(field, request)
     person = self.factory.makePerson()
     data = {
         "person_link": canonical_url(person, request=request),
         "status": "Running",
     }
     obj = marshaller.marshall_from_json_data(data)
     self.assertThat(
         obj,
         MatchesStructure.byEquality(person=person,
                                     status=JobStatus.RUNNING))
Exemplo n.º 6
0
    def test_application_url(self):
        """Requests to the /api path should return the original request's
        host, not api.launchpad.net.
        """
        # Simulate a request to bugs.launchpad.net/api
        server_url = 'http://bugs.launchpad.dev'
        env = {
            'PATH_INFO': '/api/devel',
            'SERVER_URL': server_url,
            'HTTP_HOST': 'bugs.launchpad.dev',
            }

        # WebServiceTestRequest will suffice, as it too should conform to
        # the Same Origin web browser policy.
        request = WebServiceTestRequest(environ=env, version="1.0")
        self.assertEqual(request.getApplicationURL(), server_url)
Exemplo n.º 7
0
def _generate_web_service_root(version, mimetype):
    """Generate the webservice description for the given version and mimetype.
    """
    url = urlparse.urljoin(allvhosts.configs['api'].rooturl, version)
    # Since we want HTTPS URLs we have to munge the request URL.
    url = url.replace('http://', 'https://')
    request = WebServiceTestRequest(version=version, environ={
        'SERVER_URL': url,
        'HTTP_HOST': allvhosts.configs['api'].hostname,
        'HTTP_ACCEPT': mimetype,
        })
    # We then bypass the usual publisher processing by associating
    # the request with the WebServicePublication (usually done by the
    # publisher) and then calling the root resource - retrieved
    # through getApplication().
    request.setPublication(WebServicePublication(None))
    setupInteractionByEmail(ANONYMOUS, request)
    return request.publication.getApplication(request)(request)
Exemplo n.º 8
0
def _generate_web_service_root(version, mimetype):
    """Generate the webservice description for the given version and mimetype.
    """
    url = urlparse.urljoin(allvhosts.configs['api'].rooturl, version)
    # Since we want HTTPS URLs we have to munge the request URL.
    url = url.replace('http://', 'https://')
    request = WebServiceTestRequest(version=version, environ={
        'SERVER_URL': url,
        'HTTP_HOST': allvhosts.configs['api'].hostname,
        'HTTP_ACCEPT': mimetype,
        })
    # We then bypass the usual publisher processing by associating
    # the request with the WebServicePublication (usually done by the
    # publisher) and then calling the root resource - retrieved
    # through getApplication().
    request.setPublication(WebServicePublication(None))
    setupInteractionByEmail(ANONYMOUS, request)
    return request.publication.getApplication(request)(request)
 def test_unmarshall_not_obfuscated(self):
     # Data is not obfuccated if the user is authenticated.
     marshaller = TextFieldMarshaller(None, WebServiceTestRequest())
     with person_logged_in(self.factory.makePerson()):
         result = marshaller.unmarshall(None, u"*****@*****.**")
     self.assertEqual(u"*****@*****.**", result)
Exemplo n.º 10
0
 def test_unmarshall_obfuscated(self):
     # Data is obfuscated if the user is anonynous.
     marshaller = TextFieldMarshaller(None, WebServiceTestRequest())
     result = marshaller.unmarshall(None, u"*****@*****.**")
     self.assertEqual(u"<email address hidden>", result)
Exemplo n.º 11
0
def create_webservice_error_view(error):
    """Return a view of the error with a webservice request."""
    request = WebServiceTestRequest()
    return getMultiAdapter((error, request), name='index.html')