使用JasmineJS编写测试时,我有许多测试具有类似的beforeEach/afterEach代码.
有没有办法使用JasmineJS测试套件实现继承模型?
我可以将所有测试组合describe
在一起,但在这种情况下,我将以包含所有测试的单个HUGE JS文件结束.
我想分开每个页面的测试.
这是一个例子:
describe('Services Page', function() {
beforeEach(function() {
login_as_admin()
})
beforeEach(function() {
browser().navigateTo('/services')
})
if('Some test for services page', function() {})
afterEach(function() {
logout()
})
})
describe('Administrators Page', function() {
beforeEach(function() {
login_as_admin()
})
beforeEach(function() {
browser().navigateTo('/administrators')
})
if('Some test for administrators page', function() {})
afterEach(function() {
logout()
})
})
Run Code Online (Sandbox Code Playgroud) 我从这里开始关注AngularJS文档
问题是文档只描述了代码的"成功/快乐"分支,并且没有如何测试"失败"分支的示例.
我想要做的是设置触发$scope.status = 'ERROR!'
代码的前提条件.
这是一个最小的例子.
// controller
function MyController($scope, $http) {
this.saveMessage = function(message) {
$scope.status = 'Saving...';
$http.post('/add-msg.py', message).success(function(response) {
$scope.status = '';
}).error(function() {
$scope.status = 'ERROR!';
});
};
}
// testing controller
var $httpBackend;
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
}));
it('should send msg to server', function() {
$httpBackend.expectPOST('/add-msg.py', 'message content').respond(500, '');
var controller = scope.$new(MyController);
$httpBackend.flush();
controller.saveMessage('message content');
$httpBackend.flush();
// Here is the question: How to set $httpBackend.expectPOST to trigger
// …
Run Code Online (Sandbox Code Playgroud) 使用PyCrypto我能够为RSA密钥生成公共和私有PEM序列化,但在PyCrypto中,DSA类没有exportKey()方法.
尝试使用PyOpenSSL我能够为RSA和DSA密钥生成私有PEM序列化,但PyOpenSSL中没有crypto.dump_publickey方法.
我正在寻找如何为RSA和DSA密钥生成PEM序列化的建议.
非常感谢!
PS:同时我已经更改了PyOpenSSL代码,也为crypto API导出了dump_privatekey方法.PyOpenSSL错误和补丁可以在以下网址找到:https://bugs.launchpad.net/pyopenssl/+bug/780089
我已经在使用Twisted.conch所以我通过使用PyCrypto手动生成DSA/RSA密钥然后使用此密钥初始化twisted.conch.ssh.key.Key来解决此问题.Conch的Key类为字符串序列化提供了toString方法.
这是对此问题的跟进:当没有数据通过Twisted TLSConnection发送时,SSL握手失败
我已经实现了一个简单的SSL服务器,一旦客户端连接就关闭连接.
我用openssl测试它,我得到了这次握手失败:
$ openssl s_client -connect localhost:12345
CONNECTED(00000003) 2329:error:140790E5:SSL routines:SSL23_WRITE
:ssl handshake failure:s23_lib.c:188:
Run Code Online (Sandbox Code Playgroud)
问题是TLS.Connection.loseConnection
不等待正在进行的握手,只是断开客户端.
附加的回调OpenSSL.SSL.Connection.do_handshake
会很棒......但不幸的是我不知道是否可以这样做......或者如何做到这一点.
我非常感谢任何有关如何测试TLS握手的提示.非常感谢!
这是代码
class ApplicationProtocol(Protocol):
'''Protocol that closes the connection when connection is made.'''
def connectionMade(self):
self.transport.loseConnection()
# Here is a barebone TLS Server
serverFactory = ServerFactory()
serverFactory.protocol = ApplicationProtocol
server_cert_path = 'server.pem'
serverContextFactory = DefaultOpenSSLContextFactory(
privateKeyFileName = server_cert_path,
certificateFileName = server_cert_path,
sslmethod=SSL.SSLv23_METHOD)
tlsFactory = TLSMemoryBIOFactory(serverContextFactory, False, serverFactory)
reactor.listenTCP(12345, tlsFactory)
#reactor.listenSSL(12345, serverFactory, serverContextFactory)
Run Code Online (Sandbox Code Playgroud)
现在我解决这个问题非常脏,而且不是100%有效.
def tls_lose_connection(self):
"""
Monkey patching …
Run Code Online (Sandbox Code Playgroud) 我正在使用Twisted Web static.File资源用于Web服务器的静态部分.
对于开发,我希望能够添加新文件或修改当前静态文件,而无需重新启动Twisted Web服务器.
我在getChild方法中查看static.File的源代码,我无法看到如何缓存资源:http: //twistedmatrix.com/trac/browser/tags/releases/twisted-11.0.0/twisted/web /static.py#L280
根据我的理解,getChild方法在每次调用时返回一个新资源.任何有关创建非缓存的static.File资源的帮助都非常感谢.
非常感谢,阿迪
我正在开发一个基于TDD的应用程序.
对于服务器端来说一切都很好,因为Python测试运行器很棒.
对于JS,我开始使用mocha也很棒.
我用Karma和Angular Scenario Runner编写了我的第一个测试,它也很棒.
问题是,在现实生活中开始使用Angular Scenario Runner后不久,我最终进行了60次e2s测试.运行所有测试需要1分钟.
现在,当我写一个新测试时,每次我想检查测试时,我都要等待60秒.
在Mocka中,有一个选项,只能使用.visionly运行特定的测试http://visionmedia.github.io/mocha/#exclusive-tests
看起来像Angular Scenario Runner被简要记录,但不知何故模仿Jasmine.
查看Angular Scenario Runner代码我只能找到xit定义,用于跳过测试.
是否有一个技巧要求Angular Scenario Runner仅运行测试的子集?
我已经实现了一个xdescribe空白方法来跳过整个套件......但从长远来看这是可行的.
非常感谢!
angularjs ×2
openssl ×2
pyopenssl ×2
testing ×2
twisted ×2
dry ×1
jasmine ×1
javascript ×1
pycrypto ×1
python ×1
ssl ×1
tdd ×1
twisted.web ×1
unit-testing ×1