Skip to content
This repository
Browse code

Use FCGI and Python instead of PHP for QA test 299

  • Loading branch information...
commit a163d5db2975cf9555fe8561988e6e60afe60e20 1 parent 435910e
David Beitey authored

Showing 1 changed file with 43 additions and 21 deletions. Show diff stats Hide diff stats

  1. 64  qa/299-MethodsRequestBodyHandling.py
64  qa/299-MethodsRequestBodyHandling.py
... ...
@@ -1,7 +1,11 @@
  1
+import os
1 2
 from base import *
2 3
 
3  
-DIR = "299-MethodsRequestBodyHandling"
  4
+DIR = "/299-MethodsRequestBodyHandling/"
4 5
 MAGIC = "Report bugs to http://bugs.cherokee-project.com"
  6
+PORT   = get_free_port()
  7
+PYTHON = look_for_python()
  8
+SOURCE = get_next_source()
5 9
 
6 10
 METHODS = {
7 11
     'required': [
@@ -35,10 +39,34 @@
35 39
 }
36 40
 
37 41
 CONF = """
38  
-vserver!1!rule!1280!match = directory
39  
-vserver!1!rule!1280!match!directory = /%s
40  
-vserver!1!rule!1280!handler = common
41  
-""" % (DIR)
  42
+vserver!1!rule!2990!match = directory
  43
+vserver!1!rule!2990!match!directory = %(DIR)s
  44
+vserver!1!rule!2990!handler = fcgi
  45
+vserver!1!rule!2990!handler!check_file = 0
  46
+vserver!1!rule!2990!handler!balancer = round_robin
  47
+vserver!1!rule!2990!handler!balancer!source!1 = %(SOURCE)d
  48
+
  49
+source!%(SOURCE)d!type = interpreter
  50
+source!%(SOURCE)d!host = localhost:%(PORT)d
  51
+source!%(SOURCE)d!interpreter = %(PYTHON)s %(fcgi_file)s
  52
+"""
  53
+
  54
+SCRIPT = """
  55
+from fcgi import *
  56
+
  57
+def app (environ, start_response):
  58
+    start_response('200 OK', [("Content-Type", "text/plain")])
  59
+    
  60
+    response = "Method: %%s\\n" %% environ['REQUEST_METHOD']
  61
+    if 'CONTENT_LENGTH' in environ:
  62
+        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
  63
+        request_body = environ['wsgi.input'].read(request_body_size)
  64
+        response += "Body: %%s\\n" %% request_body
  65
+
  66
+    return [response]
  67
+
  68
+WSGIServer(app, bindAddress=("localhost",%d)).run()
  69
+""" % (PORT)
42 70
 
43 71
 
44 72
 class TestEntry (TestBase):
@@ -48,7 +76,7 @@ class TestEntry (TestBase):
48 76
 
49 77
     def __init__ (self, method, send_input, input_required):
50 78
         TestBase.__init__ (self, __file__)
51  
-        self.request = "%s /%s/ HTTP/1.0\r\n" % (method, DIR) +\
  79
+        self.request = "%s %s HTTP/1.0\r\n" % (method, DIR) +\
52 80
                        "Content-type: text/xml\r\n"
53 81
         self.expected_content = []
54 82
         
@@ -70,24 +98,18 @@ class Test (TestCollection):
70 98
 
71 99
     def __init__ (self):
72 100
         TestCollection.__init__ (self, __file__)
73  
-
74 101
         self.name = "Method Request Body Handling"
75  
-        self.conf = CONF
76  
-        self.proxy_suitable = True
77 102
 
78 103
     def Prepare (self, www):
79  
-        d = self.Mkdir (www, DIR)
80  
-        f = self.WriteFile (d, "test_index.php", 0444,
81  
-                            """
82  
-<?php echo 'Method: '.$_SERVER['REQUEST_METHOD']; ?>
83  
-
84  
-<?php
85  
-    $body = @file_get_contents('php://input');
86  
-    if (strlen($body) > 0):
87  
-        echo "Body: $body";
88  
-    endif;
89  
-?>
90  
-                            """)
  104
+        fcgi_file = self.WriteFile (www, "fcgi_test_methods.cgi", 0444, SCRIPT)
  105
+        
  106
+        fcgi = os.path.join (www, 'fcgi.py')
  107
+        if not os.path.exists (fcgi):
  108
+            self.CopyFile ('fcgi.py', fcgi)
  109
+
  110
+        vars = globals()
  111
+        vars['fcgi_file'] = fcgi_file
  112
+        self.conf = CONF % (vars)
91 113
 
92 114
     def JustBefore (self, www):
93 115
         # Create sub-request objects

0 notes on commit a163d5d

Please sign in to comment.
Something went wrong with that request. Please try again.