【发布时间】:2012-06-06 01:16:29
【问题描述】:
我正在使用Django Internationalization 工具从我的应用程序中翻译一些字符串。代码如下所示:
from django.utils.translation import ugettext as _
def my_view(request):
output = _("Welcome to my site.")
return HttpResponse(output)
然后,我正在使用Django test client 编写单元测试。这些测试向视图发出请求并比较返回的内容。
如何在运行单元测试时禁用翻译?我的目标是这样做:
class FoobarTestCase(unittest.TestCase):
def setUp(self):
# Do something here to disable the string translation. But what?
# I've already tried this, but it didn't work:
django.utils.translation.deactivate_all()
def testFoobar(self):
c = Client()
response = c.get("/foobar")
# I want to compare to the original string without translations.
self.assertEquals(response.content.strip(), "Welcome to my site.")
【问题讨论】:
标签: python django unit-testing