Python实现WEB实际测试方法介绍

开发 后端
Python实现WEB在实际应用中是一个比较常见的应用技巧。我们在这篇文章中主要是通过对其的测试方法进行了详细的介绍。

其实,我们可以使用纯Python语言来实现WEB,那么在实现之后还是需要对这一功能进行相关测试。在这里我们就会通过一定的方法来进行Python实现WEB的测试,希望大家可以以此为学习参考对象。#t#

Python实现WEB测试环境:

服务器配置: 4 x Intel(R) Xeon(R) CPU E5405 @ 2.00GHz, 4G内存, 操作系统: CentOS 5.3 x86_64

nginx前端 + 4 tornado(0.2) web process

tornado: http://www.tornadoweb.org (已被墙)

Python实现WEB测试场景:

http get请求,服务器端直接返回"hello world"

Python实现WEB代码及nginx配置:

  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. }  

以上就是对Python实现WEB的相关测试方法。

责任编辑:曹凯 来源: 博客园
相关推荐

2009-12-30 15:53:28

Silverlight

2010-03-04 11:12:02

Python AOP

2017-07-18 15:13:17

2010-01-07 18:17:00

VB.NET连接SAP

2020-11-30 10:15:00

Python突变测试编程语言

2010-03-09 14:23:37

Python列表内涵

2010-03-25 09:38:03

Eclipse开发Py

2010-03-19 14:59:00

python Stri

2010-03-05 13:48:24

Python for

2010-03-16 09:20:25

Python时间

2010-02-06 18:04:21

Android 接口

2011-07-04 17:53:48

快速测试

2010-01-04 16:50:04

Silverlight

2010-01-07 10:46:27

VB.NET Sock

2010-03-22 09:54:38

Python开发环境

2010-03-23 18:20:26

Python os.g

2010-03-17 15:58:08

Python环境

2010-01-26 17:36:17

Android实现全屏

2010-02-03 16:35:45

C++回文

2009-12-28 11:14:29

WPF显示文本
点赞
收藏

51CTO技术栈公众号