Beispiel #1
0
 def test_address(self):
     unix_socket = 'socket.%s-%s' % (os.getppid(), os.getpid())
     for address in [('127.0.0.1', 47231), unix_socket]:
         with make_server_conn(address) as conn:
             self._run_get_values(conn)
         if address == unix_socket:
             self.assertFalse(os.path.exists(address))
Beispiel #2
0
    def _handle_requests(self, request_ids, records, **server_params):
        responses = dict((request_id, Response(request_id)) for request_id in request_ids)
        
        with make_server_conn(**server_params) as conn:
            map(conn.write_record, records)
            conn.done_writing()

            for record in conn:
                self.assertIn(record.request_id, responses)
                response = responses[record.request_id]
                self.assertIs(response.request_status, None)
                if record.type == FCGI_STDOUT:
                    self.assertFalse(response.stdout_closed)
                    if response.stdout is None:
                        response.stdout = record.content
                    else:
                        response.stdout += record.content
                    if not record.content:
                        response.stdout_closed = True
                elif record.type == FCGI_STDERR:
                    self.assertFalse(response.stderr_closed)
                    if response.stderr is None:
                        response.stderr = record.content
                    else:
                        response.stderr += record.content
                    if not record.content:
                        response.stderr_closed = True
                elif record.type == FCGI_END_REQUEST:
                    response.app_status, response.request_status = end_request_struct.unpack(record.content)
                else:
                    self.fail('Unexpected record type %s' % record.type)

        return responses.values()
Beispiel #3
0
 def test_unknown_record_type(self):
     with make_server_conn() as conn:
         conn.write_record(Record(123))
         conn.done_writing()
         done = False
         for record in conn:
             self.assertFalse(done)
             self.assertEquals(record.type, FCGI_UNKNOWN_TYPE)
             done = True
Beispiel #4
0
    def test_role(self):
        for role in ('responder', 'ResPonDer', 'filter', 'authorizer', FCGI_RESPONDER, FCGI_FILTER, FCGI_AUTHORIZER):
            with make_server_conn(role=role) as conn:
                self._run_get_values(conn)

        for bad_role in (979897, 'sdjflskdfj'):
            with self.assertRaises(ValueError):
                with make_server(role=bad_role):
                    pass
Beispiel #5
0
 def test_bad_request_id(self):
     with make_server_conn() as conn:
         conn.write_record(Record(FCGI_ABORT_REQUEST, '', 666))
         self.assertIs(conn.read_record(), None)