我想知道是否可以使用TestCase或LiveServerTestCase运行django测试来模拟多个服务器的存在。在
例如,我想使用Firefox在本地主机端口8081上启动“客户机服务器”,在端口8082上使用Chrome启动“资源服务器”。客户机服务器应该能够向资源服务器发出请求,以便检索json数据。每个服务器都应该有自己的设置。简而言之,我想做点什么
MyTestCase(LiveServerTestCase):
@override_settings(DATABASE={... client db config ...})
def launch_client(self):
self.client = webdriver.Firefox() # on port 8081
@override_settings(DATABASE={... resource db config ...})
def launch_resource(self):
self.resource = webdriver.Chrome() # on port 8082
def test_get_json(self):
self.client.get('http://127.0.0:8082/get/data/') # which should return data from the resource server ...
到目前为止,我提供了以下解决方案,但这些解决方案不起作用:
最基本的:使用LiveServerTestCase同时启动两个webdriver。Ie公司
^{2美元但这不起作用,因为两个webdriver将运行在同一个端口上,并且不允许在每台服务器上设置不同的设置。在
使用带有多进程选项(https://github.com/nosedjango/nosedjango#parallel-test-running-via-multiprocess)的django nose。但这只是单独运行测试。
使用这里描述的pyvows(https://realpython.com/blog/python/asynchronous-testing-with-django-and-pyvows/)。这个选项实际上在多个端口上启动多个应用程序,但是会导致非常不一致的结果(线程找不到自己的服务器,等等)。另外,如果没有黑客攻击,从另一个服务器请求一个服务器是不可能的。
有什么想法吗?非常感谢你。在
您可以使用多个LiveServerThread而不是一个LiveServerThread来实现自己的LiveServerTestCase mixin。在
相关问题 更多 >
编程相关推荐