我想为我所有与HTTP相关的测试都包含一个Web服务器.它不需要非常复杂.我宁愿不依赖在线.所以我可以测试一下我的程序的一些选项.
有关此代码的任何提示都会有所帮助.我用BaseHTTPServer尝试了一些但尚未成功的东西.nosetests命令似乎无限期地等待.
import unittest
from foo import core
class HttpRequests(unittest.TestCase):
"""Tests for HTTP"""
def setUp(self):
"Starting a Web server"
self.port = 8080
# Here we need to start the server
#
# Then define a couple of URIs and their HTTP headers
# so we can test the code.
pass
def testRequestStyle(self):
"Check if we receive a text/css content-type"
myreq = core.httpCheck()
myuri = 'http://127.0.0.1/style/foo'
myua = "Foobar/1.1"
self.asserEqual(myreq.mimetype(myuri, myua), "text/css")
def testRequestLocation(self):
"another test"
pass …Run Code Online (Sandbox Code Playgroud)