def test_invalidMethod(self):
     """
     L{UserDirectory.render} raises L{UnsupportedMethod} in response to a
     non-I{GET} request.
     """
     request = DummyRequest([""])
     request.method = "POST"
     self.assertRaises(server.UnsupportedMethod, self.directory.render, request)
Ejemplo n.º 2
0
def create_request(params={}, path='/', method='POST'):
    """
    Creates a dummy Vas2Nets request for testing our resources with
    """
    request = DummyRequest(path)
    request.method = method
    request.args = params
    return request
Ejemplo n.º 3
0
def do_request(resource, t=None, method="GET"):
    req = DummyRequest([])
    req.method = method
    req.args = {}
    if t:
        req.args["t"] = [t]
    req.render(resource)
    return "".join(req.written), req
Ejemplo n.º 4
0
 def test_invalidMethod(self):
     """
     L{UserDirectory.render} raises L{UnsupportedMethod} in response to a
     non-I{GET} request.
     """
     request = DummyRequest([""])
     request.method = "POST"
     self.assertRaises(server.UnsupportedMethod, self.directory.render, request)
Ejemplo n.º 5
0
def create_request(params={}, path='/', method='POST'):
    """
    Creates a dummy Vas2Nets request for testing our resources with
    """
    request = DummyRequest(path)
    request.method = method
    request.args = params
    return request
Ejemplo n.º 6
0
def do_request(resource, t=None, method="GET"):
    req = DummyRequest([])
    req.method = method
    req.args = {}
    if t:
        req.args["t"] = [t]
    req.render(resource)
    return "".join(req.written), req
Ejemplo n.º 7
0
def make_request(uri='', method='GET', args={}):
    site = make_site(authenticator=Mock())
    request = DummyRequest(uri.split('/'))
    request.method = method
    request.args = args
    resource = site.getResourceFor(request)
    request.render(resource)
    request.data = "".join(request.written)
    return request
Ejemplo n.º 8
0
def request_generator(url, method='GET', content=True, headers=True):
    request = DummyRequest(url)
    request.method = method
    if content:
        request.content = StringIO()
    if headers:
        request.requestHeaders = Headers()

    return request
Ejemplo n.º 9
0
 def makeRequest(self, method='GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     request = DummyRequest('/')
     request.method = method
     request.client = clientAddress
     return request
Ejemplo n.º 10
0
def request_generator(url, method='GET', content=True, headers=True):
    request = DummyRequest(url)
    request.method = method
    if content:
        request.content = StringIO()
    if headers:
        request.requestHeaders = Headers()

    return request
Ejemplo n.º 11
0
 def makeRequest(self, method='GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     request = DummyRequest('/')
     request.method = method
     request.client = clientAddress
     return request
Ejemplo n.º 12
0
 def test_renderHEAD(self):
     """
     The rendering behavior of L{UnauthorizedResource} for a I{HEAD} request
     is like its handling of a I{GET} request, but no response body is
     written.
     """
     request = DummyRequest([''])
     request.method = 'HEAD'
     self._unauthorizedRenderTest(request)
     self.assertEqual('', ''.join(request.written))
Ejemplo n.º 13
0
 def test_renderHEAD(self):
     """
     The rendering behavior of L{UnauthorizedResource} for a I{HEAD} request
     is like its handling of a I{GET} request, but no response body is
     written.
     """
     request = DummyRequest([''])
     request.method = 'HEAD'
     self._unauthorizedRenderTest(request)
     self.assertEqual('', ''.join(request.written))
Ejemplo n.º 14
0
 def makeRequest(self, method=b'GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     if clientAddress is None:
         clientAddress = IPv4Address("TCP", "localhost", 1234)
     request = DummyRequest(b'/')
     request.method = method
     request.client = clientAddress
     return request
Ejemplo n.º 15
0
 def test_renderPOST(self):
     """
     If the method is not C{GET}, L{WebSocketsResource} returns a failed
     request.
     """
     request = DummyRequest("/")
     request.method = "POST"
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     self.assertRequestFail(request)
Ejemplo n.º 16
0
 def test_renderPOST(self):
     """
     If the method is not C{GET}, L{WebSocketsResource} returns a failed
     request.
     """
     request = DummyRequest("/")
     request.method = "POST"
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"
     })
     self.assertRequestFail(request)
Ejemplo n.º 17
0
 def test_withRequest(self):
     """
     When an XML-RPC method is called and the implementation is
     decorated with L{withRequest}, the request object is passed as
     the first argument.
     """
     request = DummyRequest('/RPC2')
     request.method = "POST"
     request.content = StringIO(xmlrpclib.dumps(("foo",), 'withRequest'))
     def valid(n, request):
         data = xmlrpclib.loads(request.written[0])
         self.assertEqual(data, (('POST foo',), None))
     d = request.notifyFinish().addCallback(valid, request)
     self.resource.render_POST(request)
     return d
Ejemplo n.º 18
0
 def test_withRequest(self):
     """
     When an XML-RPC method is called and the implementation is
     decorated with L{withRequest}, the request object is passed as
     the first argument.
     """
     request = DummyRequest('/RPC2')
     request.method = "POST"
     request.content = StringIO(xmlrpclib.dumps(("foo",), 'withRequest'))
     def valid(n, request):
         data = xmlrpclib.loads(request.written[0])
         self.assertEqual(data, (('POST foo',), None))
     d = request.notifyFinish().addCallback(valid, request)
     self.resource.render_POST(request)
     return d
Ejemplo n.º 19
0
 def create_request(self, dictionary={}, path='/', method='POST'):
     """
     Creates a dummy Vas2Nets request for testing our resources with
     """
     request = DummyRequest(path)
     request.method = method
     args = {
         'messageid': [str(uuid4())],
         'time': [self.today.strftime('%Y.%m.%d %H:%M:%S')],
         'sender': ['0041791234567'],
         'destination': ['9292'],
         'provider': ['provider'],
         'keyword': [''],
         'header': [''],
         'text': [''],
         'keyword': [''],
     }
     args.update(dictionary)
     request.args = args
     return request
Ejemplo n.º 20
0
def api_request(**kwargs):
    request = DummyRequest([''])
    request.method = b'POST'
    request.content = six.BytesIO(json.dumps(kwargs).encode('utf-8'))
    return request