- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我从 webtest 文档中了解到:
The best way to simulate authentication is if your application looks in environ['REMOTE_USER'] to see if someone is authenticated. Then you can simply set that value, like:
app.get('/secret', extra_environ=dict(REMOTE_USER='bob'))
我正在尝试做同样的事情,但在 Google App 引擎环境中。我想模拟一个登录用户和一个管理员用户。
如果可能,我必须在 extra_environ 中设置哪些字典值才能完成此操作?
最佳答案
设置用户:
os.environ['USER_EMAIL'] = 'info@example.com'
设置管理员:
os.environ['USER_IS_ADMIN'] = '1'
这就是我的整个测试的样子。我的示例使用 webtest、nose、nosegae 和 gaetestbed。
class TestingRoutes(WebTestCase, unittest.TestCase):
APPLICATION = application()
def tearDown(self):
os.environ['USER_EMAIL'] = ''
os.environ['USER_IS_ADMIN'] = ''
#AdminIndex .....
def test_adminindex_no_user(self):
#No user: redirect to login form
response = app.get( url_map['adminindex'] )
self.assertRedirects(response)
def test_adminindex_user(self):
os.environ['USER_EMAIL'] = 'info@example.com'
response = app.get( url_map['adminindex'] )
self.assertForbidden(response)
def test_adminindex_admin(self):
os.environ['USER_EMAIL'] = 'info@example.com'
os.environ['USER_IS_ADMIN'] = '1'
response = app.get( url_map['adminindex'] )
self.assertOK(response)
希望对您有所帮助。
关于python - 谷歌应用引擎 : Webtest simulating logged in user and administrator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3587022/
我正在使用 VS2017 - 有没有什么方法可以在不安装 VS2017 Enterprise 的情况下让网络测试工作?我只需要 mstest.exe - 而不是 GUI 或 IDE。 最佳答案 不,对
当我尝试使用 webtest 在我的开发服务器上运行 gaeunit 时,出现此错误。 No module named webtest Status: 404 Not Found Conten
我正在使用webtest插件作为grails的功能测试组件。 它可以正常工作,但是非常慢-在测试中,整个应用程序的响应时间很短(每页大于1分钟)。我的感觉是,这是因为当我通过IDE(test-app
在django-webtest ,每个测试 TestCase 子类都带有 self.app,它是 webtest.TestApp 的一个实例,然后我可以通过 self.app.get('/',user
我正在使用 WebTest 测试表单。但是,有些字段是使用 JS 动态创建的,因此这些字段不在 Form 中。当我尝试设置以下字段之一时出现错误: >>> resp.form['new_field']
我有一个 Google App Engine 应用程序,我的请求 hadler 有一个执行身份验证的装饰器。通过 WebTest 我发现 yesterday如何设置登录用户和管理员。 今天我的身份验证
我正在使用 Microsoft WebTest 并希望能够执行类似于 NUnit 的 Assert.Fail() 的操作。我想出的最好办法是 throw new webTestException()
我正在使用 Python 和 Webtest 来测试一个 WSGI 应用程序。我发现处理程序代码中引发的异常往往会被 Webtest 吞噬,然后引发泛型: AppError: Bad response
如果我发送请求,并且我希望响应通过 SignalR 来,是否可以在 Visual Studio 中使用 LoadTest 或 PerformanceTest 进行测试? 最佳答案 简短回答:是的 我已
Azure 上的 Application Insights 允许我上传 .webtest 文件来监控应用程序可用性。我的应用程序是 REST/JSON 服务,因此我的 .webtest 引用从 Ext
我已在此站点中阅读了 Grails 和 Webtest 的文档: http://www.grails.org/plugin/webtest 而且它非常未更新。那里列出的大多数脚本都不起作用。 我正在寻
我无法在Grails 2.3.11上运行webtests。运行grails test-app我得到这个: Error Fatal error running tests: couldn't find
** 更新后 ** 对于 Microsoft Dynamics 环境中的系统和集成测试,我们使用 Visual Studio 2010 Coded UI。我是一个没有经验的 Visual Studio
我为一个看起来运行良好的网站创建了一个网络性能测试。这是一个用于登录和测试导航的简单测试。运行该测试每次都有效。但是当我在 LoadTest 中调用该测试时,问题就出现了。因此,我创建了一个负载测试,
我完全不熟悉使用 Python WebTest 进行功能测试,请多多包涵 我在看 https://webtest.readthedocs.org/en/latest/webtest.html , 所以
我配置了我的 pyramid 应用程序,以便在根据 official tutorial 进行身份验证后将 user 对象附加到 request .到目前为止一切顺利......但是虽然它工作得很好并且
我有一个 .webtest,我打算用它来加载测试将文件上传到网站。我正在使用 Visual Studio 中内置的 WebTest 框架,目的是从 Azure 运行更大规模的测试。 我创建了一个新的网
有谁知道我如何使用 WebTest 测试图像上传。我目前的代码是: form['avatar'] =('avatar', os.path.join(settings.PROJECT_PATH, 'st
我有一个 Azure 资源管理器模板,它是一组嵌套模板的一部分。它创建一个 App Insights 组件、针对禁止请求的网站的警报规则、多步骤 Web 测试以及针对 Web 测试的警报规则。除针对
我有一个 Pyramid 应用程序,它将某些功能锁定为 HTTPS 连接。 服务器前面是 nginx(通常),我使用 PasteDeploy 来检测 HTTPS 连接。从我的环境.ini: [filt
我是一名优秀的程序员,十分优秀!