def test_too_long(self): TOO_LONG_STR = LONG_STR * (0x7fffffff / len(LONG_STR) + 1) pairs = product(STRINGS, (TOO_LONG_STR,)) for pair in pairs: with self.assertRaises(ValueError): pack_pairs((pair,))
def test_too_long(self): TOO_LONG_STR = LONG_STR * int(0x7fffffff / len(LONG_STR) + 1) pairs = product(STRINGS, (TOO_LONG_STR, )) for pair in pairs: with self.assertRaises(ValueError): pack_pairs((pair, ))
def test_pack_unpack(self): pairs = [ (string.ascii_lowercase, string.printable), (string.ascii_letters, string.punctuation), ] self.assertEqual(pairs, list(unpack_pairs(pack_pairs(pairs)))) # check if it works for names/values longer than 127 bytes pairs = [(name * 137, value * 731) for name, value in pairs] self.assertEqual(pairs, list(unpack_pairs(pack_pairs(pairs)))) # check if it works for dict too pairs = dict(pairs) self.assertEqual(pairs, dict(unpack_pairs(pack_pairs(pairs))))
def pack_env(**vars): env = { 'SCRIPT_NAME': '', 'PATH_INFO': '/', 'REQUEST_METHOD': 'GET', 'QUERY_STRING': '', 'CONTENT_TYPE': 'text/plain', 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': '80', 'SERVER_PROTOCOL': 'HTTP/1.0', } if vars: env.update(vars) return pack_pairs(env)
def _run_get_values(self, conn): names = (FCGI_MAX_CONNS, FCGI_MAX_REQS, FCGI_MPXS_CONNS) get_values_record = Record(FCGI_GET_VALUES, pack_pairs(dict.fromkeys(names, '')), FCGI_NULL_REQUEST_ID) conn.write_record(get_values_record) conn.done_writing() done = False for record in conn: self.assertFalse(done) self.assertEquals(record.type, FCGI_GET_VALUES_RESULT) values = dict(unpack_pairs(record.content)) for name in names: self.assertIn(name, values) done = True
def test_get_values(self): req_id = next_req_id records = ( (FCGI_GET_VALUES, pack_pairs( (name, '') for name in ( FCGI_MAX_CONNS, FCGI_MAX_REQS, FCGI_MPXS_CONNS, ) )), ) handler = run_handler(records) assert not handler.requests assert not handler.request_handler.called assert handler.conn.close.called rec = find_rec(handler, FCGI_GET_VALUES_RESULT) assert rec assert unpack_pairs(rec.content)
def test_pack_unpack_pairs(self): pairs = tuple(product(STRINGS, STRINGS)) assert pairs == tuple(unpack_pairs(pack_pairs(pairs)))