Introduction to Python WEB testing methods

Source: Internet
Author: User

In fact, we can use a pure Python language to implement the WEB. After implementation, we still need to test this function. Here, we will use some methods to test Python WEB implementation. I hope you can take this as a learning reference object.

  • How to compile Python code for capturing Web Images
  • Explanation of the specific application method of the Python submission form
  • Python file type
  • Python yield usage
  • Analysis on the basic operation steps for Python Access Database Operations

Python WEB testing environment:

Server Configuration: 4 x Intel (R) Xeon (R) CPU E5405 @ 2.00 GHz, 4G memory, operating system: CentOS 5.3 x86_64

Nginx frontend + 4 tornado (0.2) web process

Tornado: http://www.tornadoweb.org (walled)

Python WEB testing:

For http get requests, the server directly returns "hello world"

Python implements WEB code and nginx Configuration:

 
 
  1. main.py:  
  2. #!/usr/bin/python  
  3. # -*- coding: utf-8 -*-  
  4. """web main"""  
  5. from tornado.httpserver import HTTPServer  
  6. from tornado.ioloop import IOLoop  
  7. from tornado.web import RequestHandler, Application, authenticated  
  8. #from rockps.auth import AuthHandler  
  9. class MainHandler(RequestHandler):  
  10. def get(self):  
  11. self.write("hello world")  
  12. settings = {  
  13. }  
  14. application = Application([  
  15. (r"/", MainHandler),  
  16. ], **settings)  
  17. if __name__ == "__main__":  
  18. http_server = HTTPServer(application)  
  19. http_server.listen(8081)  
  20. IOLoop.instance().start()  
  21. nginx.conf:  
  22. user root;  
  23. worker_processes 1;  
  24. error_log /var/nginx_error.log;  
  25. pid /var/run/nginx.pid;  
  26. events {  
  27. worker_connections 51200;  
  28. use epoll;  
  29. }  
  30. http {  
  31. # Enumerate all the Tornado servers here  
  32. upstream frontends {  
  33. server 127.0.0.1:8081;  
  34. server 127.0.0.1:8082;  
  35. server 127.0.0.1:8083;  
  36. server 127.0.0.1:8084;  
  37. }  
  38. #include /etc/nginx/mime.types;  
  39. default_type application/octet-stream;  
  40. access_log /var/log/nginx/access22.log;  
  41. keepalive_timeout 65;  
  42. proxy_read_timeout 200;  
  43. sendfile on;  
  44. tcp_nopush on;  
  45. tcp_nodelay on;  
  46. gzip on;  
  47. gzip_min_length 1000;  
  48. gzip_proxied any;   
  49. gzip_types text/plain text/html text/css text/xml  
  50. application/x-javascript application/xml  
  51. application/atom+xml text/javascript;  
  52. # Only retry if there was a communication error, not a timeout  
  53. # on the Tornado server (to avoid propagating "queries of death"  
  54. # to all frontends)  
  55. proxy_next_upstream error;  
  56. server {  
  57. listen 8085;  
  58. # Allow file uploads  
  59. client_max_body_size 50M;  
  60. location ^~ /static/ {  
  61. root /var/www;  
  62. if ($query_string) {  
  63. expires max;  
  64. }  
  65. }  
  66. location = /favicon.ico {  
  67. rewrite (.*) /static/favicon.ico;  
  68. }  
  69. location = /robots.txt {  
  70. rewrite (.*) /static/robots.txt;  
  71. }  
  72. location / {  
  73. proxy_pass_header Server;  
  74. proxy_set_header Host $http_host;  
  75. proxy_set_header X-Real-IP $remote_addr;  
  76. proxy_set_header X-Scheme $scheme;  
  77. proxy_pass http://frontends;  
  78. }  
  79. }  

The above is the test method for implementing WEB in Python.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.