用于zope的测试层。testrunner:apacheds、cassandra、memcached、mongodb、mysql、nginx、openldap、postgresql

lovely.testlayers的Python项目详细描述


**************************************************
与zope一起使用的可爱测试层。testrunnery基于网络的
服务器实现。


==
虽然有基于"hexagonit.recipe.cmmi"和"zc.recipe.cmmi"的构建目标,用于构建PostgreSQL和Memcached内联,
使用
各自服务的本机系统安装是非常好的。




==========
``lovely.test layers``附带了一组内置的自我测试
,用于验证各个测试层的功能。

若要开始此操作,请继续阅读`<;tests.rst>;` ` ` `.



==ectories
==



有一个mixin类,它提供了生成
工作目录并制作其快照的有用方法。

>;>;从lovely.testlayers.layer导入workdirectorylayer


让我们创建一个示例层。

>;>gt;类MyLayer(工作目录层):
…定义初始化(self,name):
…self.\uu name\uuu=name

>;>;mylayer=mylayer('mylayer')


初始化创建目录结构所需的目录。

>;>;mylayer.setupwd()

我们可以使用os.path连接语法获取相对路径。

>;mylayer.wdpath('a','b')
'…/(u内置的)mylayer.mylayer/work/a/b'

>让我们创建一个目录。

>;>;导入os
>;>;os.mkdir(mylayer.wdpath('first directory')

并制作一个快照。

>;>;mylayer.make snapshot('first')

我们可以检查是否有快照。

>;>mylayer.hassnapshot('first')
true

"…ss_first.tar.gz"

,现在我们生成第二个目录和另一个快照。

>;>os.mkdir(mylayer.wdpath('second directory')
>;
dpath())
['firstdirectory','seconddirectory']


/>
>;>;mylayer.restoresnapshot('second')
>;>;排序(os.listdir(mylayer.wdpath()))
['firstdirectory','seconddirectory']


我们还可以覆盖快照。

>;>;os.mkdir(mylayer.wdpath('thirddirectory')
>;>;mylayer.makesnapshot('first')
>;>mylayer.restoresnapshot('first')
>;>例如,stet到项目目录。

>;>;mylayer2=mylayer('mylayer2')
>;>;导入tempfile
>;>;mylayer2.setupwd()

>;>;mylayer2.snapdir=tempfile.mkdtemp()
>;>;os.mkdir(mylayer2.wdpath('adir')

>;>mylayer2.makesnapshot('first')
>;>os.listdir(mylayer2.snapdir)
['ss_first.tar.gz']

>;>os.mkdir(mylayer2.wdpath('bdir')
>;>sorted(os.listdir(mylayer2.wdpath())
['adir','bdir']

>;>mylayer2.restoreSnapshot('first')

>;>sorted(os.listdir(mylayer2.wdpath()))
['adir']




===

===

特定端口,通过提供启动命令。

>;>from lovely.testlayers import server
>;>sl=server.serverlayer('sl1',servers=['localhost:33333'],
…start_cmd='nc-k-l 33333')


设置层将启动服务器。


>;sl.setup()


>现在我们可以访问服务器端口。

>;>;从可爱的测试层导入util
>;>;util.isup('localhost',33333)
true

拆卸后。

>;>sl.teardown()
>;>util.isup('localhost',33333)
false

启动"sl.setup()
traceback(最近一次调用的最后一次):

systemerror:启动服务器失败rc=1 cmd=false

logging
----


os
>;>;log path=project_path('var','log','stdout.log')
>;>;sl=server.serverlayer('sl2',servers=['localhost:33333'],
…start_cmd='nc-k-l 33333',
…stdout=logpath)


设置层启动服务器::

>;>;sl.setup()


获取stdout的当前位置::

>;>;pos=sl.stdout.tell()

向服务器发送消息::

>;>;run('echo"get/http/1.0"&nc localhost 33333')


将消息记录到stdout::

>;>;>print(sl.stdout.read())
get/http/1.0

ed
true

再次调用安装程序后,文件将被重新发送:

>;>;sl.setup()
>;>;pos=sl.stdout.tell()
>;>;run('echo"hi"nc localhost 33333')
>;>;sl.stdout.seek(pos)
>;>;打印(sl.stdout.read())
hi
>;>sl.teardown()


sl2',服务器=['localhost:33333'],
…start_cmd='nc-k-l 33333',
…stdout=f)
>;>sl.setup()

>;>pos=sl.stdout.tell()
>;>uu=run("echo"测试";nc localhost 33333")
>;>;>print(sl.stdout.read())
test

>;sl.teardown()。

拆卸后,文件将被关闭::

>;>sl.stdout.closed
true

t 33333’)
>;>;\=sl.stdout.seek(pos)
>;>>打印(sl.stdout.read())
文件重新打开
>;>sl.teardown()

start_cmd='nc-k-l 33333',
…stdout=路径,
…stderr=path)
>gt>gt>gt>gt>gt>lt>br/>>gt>gt>gt>gt>gt>lt>gt>gt>gt>gt>lt>sl.stdout.name
var/log/mylayer-stdout.log'


>gt>gt>lt>sl.stderr.name
var/log/mylayer-stderr.log'

>gt>gt>gt>lt.sl.teardown()

>

>


===========================================
memcached测试层并在给定端口上停止memcached守护进程(默认值
为11222)



>;>;导入os
>;>;此处=os.path.dirname(文件目录)
>;>;项目目录=os.path.dirname(os.path.dirname(os.path.dirname(此处))
>;>;路径=os.path.join(项目目录,'parts','memcached','bin','memcached')
>;>>从可爱的.testlayers导入memcached
>;>ml=memcached.memcachedlayer('ml',path=path)

让我们设置服务器。

>;>ml.setup()

现在我们可以访问端口11222上的memcached。

>;>导入telnetlib
>;>tn=telnetlib.telnet('localh11222)
>>>gt>gt;tn.close()

>
>拆卸后不再使用。


>>>gt>gt;ml.teardown()
>>gt;tn=telnetliblib.telnet('localhost',11222)
回溯(最近一次呼叫最后一次):

错误:…连接被拒绝…


>

===============
nginx测试层
nginx测试层
br/>>。================

此测试层启动并停止nginx服务器。

nginx命令的可选路径
和运行nginx的前缀目录。为了演示这一点,我们需要创建一个临时nginx home,nginx应该在其中运行。

>;>;导入tempfile,shuil,os
>;>;tmp=tempfile.mkdtemp()
>;>;nginx前缀=os.path.join(tmp,"nginx home")
>;>;os.mkdir(nginx前缀)

方位角让我们定义一个
最小配置文件。

>;>os.mkdir(os.path.join(nginx_prefix,'conf'))
>;>cfg=文件(os.path.join(nginx_prefix,'conf','nginx.conf','w')
>;'cfg.write(""
…事件{
…工作连接10;
…}
…http{
…服务器{
…听127.0.0.1:12345;
…}
…}""
>;>cfg.close()

和日志目录。

>;>os.mkdir(os.path.join(nginx_prefix,"logs")

在这个包的根目录中已经有一个通过buildout安装的
,因此我们获取这个可执行文件的路径。使用通过buildout构建的特殊nginx是使用该层的常见方法。这样,同样的
nginx可以用于本地开发,配置由构建定义。


>;…os.path.dirname(os.path.dirname(os.path.abspath(uuu file_uuu))),
…。"parts"、"openresty"、"nginx"、"sbin"、"nginx"、"nginx"、"openresty"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"nginx"、"ngin>我们现在可以了发出请求,我们会得到404,因为我们没有安装
任何URL,但对于测试而言,这是正常的。

>;>;导入urllib2
>;>;urllib2.urlopen('http://localhost:12345/',无,1)
回溯(最后一次最近的调用):

http error:http error 404:未找到

停止。

>;>nl.teardown()

拒绝>;

fg=文件(cfg_file,'w')
>;>cfg.write(""
…事件{
…工作连接10;
…}
…http{
…服务器{
…听127.0.0.1:23456;
…}
…}""
>;>cfg.close()

>;>nginx.nginxlayer('nl',nginx_prefix+"2",nginx_cmd,cfg_file)
<;lovely.testlayers.nginx.nginxlayer对象位于x…>;


failures
==

例如,如果我们尝试两次删除该层。


>;>nl.tear down()
回溯(最后一次调用):

运行时错误:nginx stop failed…nginx.pid"failed
(2:没有这样的文件或目录)

.

>;>nl.setup()
>;>nl.setup()
回溯(最近一次调用):

运行时错误:nginx start failed nginx:[emerg]bind()…
nginx:[emerg]bind()到127.0.0.1:12345失败(48:地址已在使用)

nginx:[emerg]仍然无法绑定()

>;>nl.teardown()


cleanup the temporary directory,我们不需要它从
这一点进行测试。

>;
然后,ayer进行配置检查。

让我们提供一个不存在的前缀路径。

>;>nginx.nginxlayer('nl','something')
回溯(最近一次调用的最后一次):

断言错误:前缀不是目录'…/something/'

d.

>;>nginx.nginxlayer('nl','.','not an nginx')
回溯(最近一次调用的最后一次):

运行时错误:nginx检查失败/bin/sh:notan nginx:command not found

或缺少aka breaked配置。我们只提供我们的工作目录
作为前缀,实际上不包含任何配置。

>;>nginx.nginxlayer('nl',',','nginx_cmd)
回溯(最近一次调用时间):
运行时错误:nginx检查失败nginx版本:ngx_openresty/…
nginx:[警报]无法打开错误日志文件…
…[emerg]…
nginx:配置文件…/conf/nginx.conf测试失败



======
email/smtp测试层
======


此层在给定端口(默认1025)上启动和停止smtp守护进程:

>;>;>layer=mail.smtpserverlayer(port=1025)

tils从smtplib import smtp导入formatdate
>;>;msg=mimetext('testmessage',\u charset='utf-8')
>;>;msg['subject']='第一封电子邮件'
>>gt;gt;gt;gt;gt;msg['from']='来自@exexample.org'
>>;gt;gt;gt;gt;gt;gt;msg['to']='收件人@example.org'
>;gt;gt;gt;msg['date']=formattate(localtime=true)

>>;gt;s=smsmtp()
>;gt;s=smsmsmtp()
>;gt;gt;gt;gt;gt;gt;gt;gt;gt;gt;gt;gt;第一封电子邮件'
>>>>;gt;gt;gt;gt;gt;gt.org,""回复cipient@example.com',msg.a s_string())
>;>;msg['subject']="第二封电子邮件"
>;>;&uu=s.sendmail('from@example.org','recipient@example.com',msg.as_string())

>;>;s.quit()
(221,'bye')

testlayer公开了一个"server"属性,可用于访问接收的电子邮件s.

使用"mbox(recipient)`"方法获取正确的邮箱:

>;>;mailbox=layer.server.mbox('recipient@example.com')


返回x::

>;>;emptyBox=layer.server.mbox('invalid@example.com')
>;>;emptyBox.is_empty()
true


>;>;打印(mailbox.popleft())
内容类型:text/plain;charset="utf-8"
mime版本:1.0
内容传输编码:base64
主题:第一封电子邮件
发件人:from@example.org
收件人:recipient@example.org

<;blankline>;



e电子邮件::

>;>s=smtp()
>;>s.connect('localhost:1025')
回溯(最近一次调用的最后一次):

错误:[errno…]连接被拒绝

验证setup()和teardown()是否适用于后续调用::

>;>layer.setup()

>;>_=s.connect('localhost:1025')
>>s.sendmail('from@example.org','recipient@example.com',msg.as_string())
>>print(mailbox.popleft())
内容类型:text/plain;charset="utf-8"
mime版本:1.0
内容传输编码:base64
主题:第一封电子邮件
发件人:from@example。或g
收件人:recipient@example.org

<;blankline>;


>;>;>layer.teardown()
>;回溯(最近一次调用):

错误:[errno…]连接被拒绝

d ``server``属性为none::

>>>>gt;layer=mail.smtpserverlayer(port=1025)
>>>gt>layer.layer=mail.smtpserverlayer(port=1025)
>>gt;layer.layer.server为none




cassandra测试层

cassandra测试层

=====br=====br/>




>该层开始和停止具有给定存储的cassandra实例的cassandra实例

模板。有关cassandra的信息,请参见:
http://en.wikipedia.org/wiki/cassandra(database)


>;>from lovely.testlayers import cass


>此目录中存在一个示例模板,我们现在将其用于此示例。

>;>;…storage-conf.xml.in')

评估模板时提供以下键。让我们在示例文件中查找它们。

>m=tmpl_pat.匹配(l)
…如果m:
…conf_keys.add(M.组(1))


thrift_port、storage_port和control_port是构造函数的可选关键字参数,默认为标准端口
+10000。

>;>l=cass.cassandralayer('l',storage_conf=storage_conf_tmpl)
>;>l.thrift_port
19160

我们设置服务器。

>;>l.setup()

我们通过telnet将
连接到Thrift端口进行测试。

>>;>;import telnetlib
>;>;tn=telnetlib.telnet('localhost',l.thrift\&u port)
>;>;tn.close()

r/>
>;>>telnetlib.telnet('localhost',l.thrift廑port)
回溯(最近的最后一次调用):

错误:…连接被拒绝mysql
>;>;导入tempfile,os
>;>;tmp=tempfile.mkdtemp()
>;>;dbdir=os.path.join(tmp,'db')
>;>;dbdirfake=os.path.join(tmp,'dbfake')

>;dbname='测试'

让我们创建一个mysql服务器。

>>>srv=mysql.server(dbdir,port=17777)


并初始化数据库。

>;>;>srv.start()

>;>import time
>;>time.sleep(3)

>;>srv.createdb(dbname)

一个数据库列表。

>;>sorted(srv.list databases())
['mysql','test','testing']



ambda:none

>;>;srv.start()
回溯(最近一次调用的最后一次):
ioerror:未找到mysqld。是否安装了MySQL服务器?

>;>;srv.mysqld_path=srv.orig_method


运行SQL脚本
==


我们可以从文件系统运行脚本。

>;>;script=os.path.join(tmp,'ascript.sql')
>;>;f=file(script,'w')
>;>;f.write("")如果存在,则删除表a;创建表a(title varchar(64));"""
>;>f.close()
>;>srv.runscripts(dbname,[script])




dump和restore
=dumpa=os.path.join(tmp,'a.sql')
>;>;srv.dump(dbname,dumpa)

conn.query('insert into a values(%i)%i)
>;>conn.commit()

>;>conn.close()


/>
>;>;srv.restore(dbname,dumpa)

>;>;conn=\mysql.connect(host='127.0.0.1',port=17777,user='root',db=dbname)
>;>;conn.query('select count(*)from a')
>;>;conn.store\.result().fetch\.row()
('0',),)

>;gt;conn.close()


现在还原dumpb,我们有5行返回。


>;>srv.restore(dbname,dumpb)

>;>conn=\mysql.connect(host='127.0.0.1',port=17777,user='root',db=dbname)
>;>conn.query('select count(*)from a')
ent call last):

valueerror:没有这样的文件"…/asdf"


>;>;srv.stop()



==


我们可以生成用作命令行脚本的控制脚本。

>;>>dbdir2=os.path.join(tmp,"db2")
>;>main=mysql.mysqldbscript(dbdir2,port=17777)
>;>main.start()
>;>sorted(main.srv.listdatabases())
['mysql','test']
>;main.stop()


启动时创建的数据库。

>;>main=mysql.mysqldbscript(dbdir2,dbname='hoschi',port=17777)
>;>main.start()
>;>sorted(main.srv.listdatabases())
['hoschi','mysql','test']
>;main.stop()

数据库只创建一次。

>;>;main.start()
>;>;main.stop()

>以及要执行的脚本。

>;>;main=mysql.mysqldbscript(dbdir2,dbname='hoschi2',
…scripts=[script],port=17777)
>;>main.start()

请注意,脚本应该始终
无破坏性。因此,如果架构更新到期,则只需
再次运行所有脚本即可。

>;>;main.run scripts()
>;>;main.stop()



==

测试]

我们可以获取存储uri。

>;>layer.storeuri()
'mysql://localhost:16543/testing'

>;>layer.setup()
>;>layer.teardown()

;>;layer.setup()
>;>;layer.teardown()

G:16543

>;>layer.teardown()

还有一个
convenience类,让我们将SQL语句作为安装程序执行。

>;>;setup=mysql.execute sql('create table testing(title varchar(32))')
>;>;layer=mysql.mysqldatabaselayer('testing',setup=setup)
>;layer.setup()
>;>>layer.teardown()
>;>>layer=mysql.mysqldatabaselayer('testing',setup=setup)
>;>layer.setup()
>;>layer.teardown()

=mysql.mysqldatabaselayer('testing2',setup=setup)
>;>;
layer.snapshotident
u'lovely.testlayers.mysql.executesqle449d7734c67c100e0662d3319fe3f410e78ebcf'


>让我们提供一个标识符和脚本。

>;layer=mysql.mysqldatabaselayer('testing3',setup=setup,
…按扣shotident='blah',
…scripts=[script])
>;>layer.snapshotIdentit
'blah'
>;>layer.scripts
['/…/ascript.sql']






在测试设置时,此快照现在已还原。

>;>layer.testsetup()

sting')
>;>conn.store_result().fetch_row()


>;>conn.close()

uery("插入测试值('hoschi')")
>;>conn.commit()

>;>conn.query('select*from testing')
>;>conn.store_result().fetch_row()
('hoschi',),)

>;>conn.close()

>;>layer.testteardown()
>;layer.teardown>


>最后做一些清理工作::

>>>>>导入shutil
>>shutil.rmtree(tmp)shutil.rmtree(tmp)shutil.rmtree(tmp)shutil
>
=======
>pgserver-control
>
>
>
>>>>>>>;从可爱的测试层导入pgsql导入pgsql
>>&pgsql
>>
>>>>
>>>>>>最后做一些清理工作:
燃气轮机;>;>;导入tempfile,os
>;>;tmp=tempfile.mkdtemp()
>;>;dbdir=os.path.join(tmp,"db")
>;>;dbdirfake=os.path.join(tmp,"dbfake")

>;dbname='测试'

请注意,我们为pg廑config可执行文件提供绝对路径
,以便使用此项目中的postgresql
安装。

>;>;pgconfig=project廑path('parts','postgres','bin','pg廑config')
>;>;srv=pgsql.server(dbdir,port=16666,pgconfig=pgcon图,verbose=true)

ostgresqlconf=srv.postgresqlconf)
>;>;srvfake.postgresqlconf==srv.postgresqlconf
true


lueerror:postgresqlconf not found'/not/existing/path'


我们还可以指定pg_config可执行文件,它默认为
'pg_config',因此需要在路径中。

>;>;srv.pgconfig
'/…/pg_config'

>;>;pgsql.server(dbdirfake,pgconfig='notexistingcommand')
回溯(最近一次调用):

值错误:pgconfig未找到'notexistingcommand'

/>然后初始化数据库。

>;>srv.init db()
>;>srv.start()

>;>srv.createdb(dbname)



运行SQL脚本
===

=>我们可以从文件系统运行脚本。

>;>;script=os.path.join(tmp,'ascript.sql')
>;>;f=file(script,'w')
>;>;f.write(""创建表A(title varchar);"")
>;>;f.close()
>;>srv.runscripts(dbname,[脚本])

在共享目录前加上pg_config。因此,让我们安装tsearch2。

>;>;script='pg_config:share:system_views.sql'
>;>;srv.runscripts(dbname,[script])




dump and restore
==

>;>srv.dump(dbname,dumpa)


,现在有一些更改

>;>import psycopg2
>;>cs="dbname='%s'host='127.0.0.1'port='16666'"%dbname
>;>conn=psycopg2.connect(cs)
>;>cur=conn.cursor()

>;>;对于范围(5)内的i:
…cur.execute('insert into a values(%i)%i)
>;>conn.commit()

>;>cur.close()
>;>conn.close()


dumpa和表是emtpy。

>;>srv.restore(dbname,dumpa)

>;>conn=psycopg2.connect(cs)
>;>cur=conn.cursor()

>;>cur.execute('select count(*)from a')
>;cur.fetchone()
(0l,)

>;>;cur.close()
>;>;conn.close()

.execute('select count(*)from a')
>;>cur.fetchone()
(5l,)

>;>cur.close()
>;>conn.close()


k(最近一次调用的最后一次):

valueerror:没有这样的文件"…/asdf"

>;>;srv.stop()



==


我们可以生成用作命令行脚本的控制脚本。


>;>;dbdir2=os.path.join(tmp,"db2")
>;>;main=pgsql.pgdbscript(dbdir2,port=16666,pgconfig=pgconfig)
>;>;main.start()
>;>;排序(main.srv.listdatabases())
['postgres','template0','template1']
>;>;main.stop()



我们还可以定义启动时要创建的数据库。

>;>main=pgsql.pgdbscript(dbdir2,
…pgconfig=pgconfig,
…dbname='hoschi',port=16666)
>;>main.start()
>;>sorted(main.srv.listdatabases())
['hoschi','postgres','template0','template1']
>;>main.stop()

>>>main.stop()

以及要执行的脚本。

>>main=pgsql.pgdbscript(dbdir2,dbname='hoschi2',
…pgconfig=pgconfig,
…script s=[script],port=16666)
>;>main.start()

又来了。请注意,脚本应该始终
无破坏性。因此,如果架构更新到期,则只需
重新运行所有脚本即可。

>>;>;main.run scripts()

>;>;main.stop()



r
===


让我们创建一个层用法:

>;>layer=pgsql.pgdatabaselayer('testing',pgconfig=pgconfig)

第二次启动服务器时,它会获取快照。

>;>;layer.setup()
>;>;layer.teardown()

回溯(最近一次调用):

运行时错误:端口已在侦听:15432
>;>layer.teardown()


还有一个
convenience类,让我们将SQL语句作为安装程序执行。

>;>;setup=pgsql.execute sql('create table testing(title varchar)')
>;>;layer=pgsql.pgdatabaselayer('testing',setup=setup,pgconfig=pgconfig)
>;>;layer.setup()
>;>layer.teardown()
>;>layer=pgsql.pgdatabaselayer('testing',setup=setup,pgconfig=pgconfig)
>;>layer.setup()
>;>layer.teardown()

如果数据库名称不同,也可以使用相同的快照。

>;gt;gt;layer2=pgsql.pgdatabaselayer('testing2',setup=setup,pgconfig=pgconfig)
>;>;layer2.setup()
>;>;layer2.teardown()

参数的。

>;>layer.snapshotIdentit
u'lovely.testlayers.pgsql.executesqlf9bb47b1baeff8d57f8f0dadfc91b99a3ee56991'


让我们提供一个标识符和脚本。

>;>layer=pgsql.pgdatabaselayer('testing3',setup=setup,
…pgconfig=pgconfig,
…snapshotident='blah',
…scripts=['pg_config:share:system_views.sql'])
>>>gt;layer.snapshotident
'blah'
>>>gt;layer.scripts
['pg_config:share:system_views.sql']



ent.

>;>;layer.setup()

testsetup后,此快照现在已还原。

>;>;layer.testsetup()

=psycopg2.connect(cs)
>;>cur=conn.cursor()

>;>cur.execute('select*from testing')
>;>cur.fetchall()
[]br/>
>;>;


>;>;conn=psycopg2.connect(cs)
>;>;cur=conn.cursor()

>;>;cur.execute("插入测试值('hoschi')"
>;>;conn.commit()

>;>;cur.execute('select*from testing')
>;>;cur.fetchall()
[('hoschi',)]

>;>cur.close()
>;>conn.close()

>;>layer.testteardown()

此时需要删除Storm Synch。


>;>import transaction
>;

>;>cur.execute("从测试中选择*)
>;>cur.f>>
>>


>>>>>>>>>>>>>>>>>>>>>>>>
>
>>>>>>>>>>>>>>>>>>>>>
>
>
>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>
>>>>>>
>>>>
>>>
>>>>>>

>>>>
>>>><===


注::

运行此测试::

bin/buildout install mongodb mongodb testngolayer``启动和停止一个mongodb实例。





single server
==



预热
----
我们创建一个新的mongodb层::

>;>;从lovely.testlayers导入mongodb
>;>;mongo=mongodb.mongo layer('mongodb.ss ingle',mongod_bin=project_path('bin','mongod'))
>;>;mongo.storage_port
37017


所以让我们启动服务器::

>;>;mongo.setup()


我们通过telnet将
连接到存储端口来测试这一点:

>>;>import telnetlib
>;>tn=telnetlib.telnet('localhost',mongo.storage嫒port)
>;>tn.close()


ODB客户端:

>;>from pymongo import connection
>;>;>mongo db=mongo conn['foo-db']

"world"}
>;>;文档id
objectid("…")


mongo-db.foobar.foobar.mongo-db.foobar.foobar.find({'hello':'world'}[0]==document
>true



>
>









>
>>>;mongo-conn.mongo-conn.foobobar.foobobar.foobar.mongo.mongo-conn.mongo.mongo.conn.disconnect>
>>>>>>>>>;delmongo-mongo-conn.mongo-conn.mongo-conn.disconnect;del.
>>;del mongo-db




n拒绝

==
==MongoDB测试层-主/从设置注::

运行此测试::

bin/buildout install mongodb mongodb test`` mongomasterslavelayer``启动和停止多个mongodb
实例,并在它们之间配置一个主从连接。



==


--


导入mongodb
>;>;masterslave=mongodb.mongomasterslavelayer('mongodb.masterslave',mongod'u bin=project'u path('bin','mongod')
>;>;主从存储端口
[37020,37021,37022]

pe.testrunner.runner导入聚集层
>;>layers=[]
>;>gt;聚集层(主从,层)
>;>layer.setup()



正在实现连接它使用一个真正的MongoDB客户端:从Pymongo导入连接:

>;>连接('localhost:37020',safe=true,w=3),
…[
…连接('localhost:37021',read_preference=readpreference.secondary),
…连接('localhost:37022',read_preference=readpreference.secondary),
…]
…)
>>>gt;mongoo-db=mongoo-mongoo-u-conn['bar-db']




>提前查询操作计数器,稍后再进行比较:


>>>gt;操作计数器,before=masterslave.get-opcounters()['custom']


>插入一些数据:

>gt>gt;文档,id=mongoo-db.foobar.foobar.insert({'您好':'world'})
>
>>gt>gt;文档,文档,>gt;文档,
gt>gt;文档,
>>>gt;文档你的身份证
objectid("…")

ari``:

>;>opcounters_after=masterslave.get_opcounters()['custom']

>;>opcounters_after['primary.insert']==opcounters_after['primary.insert']+1
true

>;…"['secondary.query']==opcounters'['secondary.query']+1之前,\
…"错误:应为"after==before+1",但得到"after=%s,before=%s"%\
…(['secondary.query']后为opcounter,['secondary.query']]前为opcounter)
















>数据库


>>>>>>>>>mongou conn.mongou conn.mongou conn.mongou conn.mongou conn.mongo数据库('bar-db')
>>>;mongou conn.disconnect;mongou conn.mongo conn.disconnect
>>>>>>
>>>>>>>>>>>/>>;>>;德尔蒙戈数据库





___

拆下后将拒绝连接:

>;>;对于层中的层:
…layer.teardown()

>;>def check_down(*端口):
…对于端口中的端口:
…尝试:
…tn=telnetlib.telnet('localhost',port)
…tn.close()
…除了:
…yield true

>>all(check_down(masterslave.storage_ports))
true


=======================================================================================================================================================注::

要运行此测试::

bin/buildout install mongodb mongodb test
bin/test mongodb--test=mongodb廑replicaset




MongoDB实例并在其上配置副本集。




ifconfig::false
>;>from time import sleep

warning up
----


>我们创建一个新的mongodb层::

>;>from lovely.testlayers import mongodb
>;>replicaset=mongodb.mongoredlicasetlayer('mongodb.replicaset',mongod_bin=project_path('bin','mongod')
>;>;35; replicaset=mongodb.mongoreplicasetlayer('mongodb.replicaset',mongod_bin=project_path('bin','mongod'),cleanup=false)
>;>;replicaset.storage_ports
[37030,37031,37032]



那么让我们从zope.testrunner.runner import gate-gather撸layers
>;>;启动服务器:yers=[]
>;>>收集层(副本集,层)
>;>对于层中的层:
…layer.setup()


并检查副本集是否已正确启动:

>;>;来自pymongo导入连接
>;>;mongo_conn=connection('localhost:37030',safe=true)


>;>;mongo_conn.admin.command('replsetgetstatus')。get('set')
u'mongodb.replicaset'


ready::

>;>mongo-conn.disconnect()
>;>del-mongo-conn



>;>;mongo-uri='mongodb://localhost:37030,localhost:37031,localhost:37032/?replicaset=mongo db.replicaset'
>;>mongo-conn=replicasetconnection(mongo-uri,read-preference=readpreference.secondary,safe=true,w="maist")
>;
>>gt;睡眠(1)
>>gt;opcounters_before=replicaset.get_opcounters()['custom']


插入一些数据::

>>document_id=mongo db.foobar.insert({'hello':'world'})
>;document_id
objectid('…')

并查询它::

>;>>document=mongo-db.foobar.find-one(document-id)
>;>document
{u"id":objectid("…"),u"hello":u"world"}

证明"write"操作被分派到"primary"`,
而"read"操作被分派到任何"secondary"``:

>;>sleep(1)
>;>opcounters_after=replicaset.get_opcounters()['custom']

>;>opcounters_after['primary.insert']==opcounters_before['primary.insert']+1
true

>;…"['secondary.query']==opcounters'['secondary.query']+1之前,\
…"错误:应为"after==before+1",但得到"after=%s,before=%s"%\
…[二次查询]后为操作计数器,[二次查询]前为操作计数器])


















>数据库


>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>蒙哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥哥br/>>;>>del mongo戋db







层中的连接在拆卸后被拒绝:

>;层中的层:
…layer.teardown()

>;>def check_down(*端口):
…对于端口中的端口:
…尝试:
…tn=telnetlib.telnet('localhost',port)
…tn.close()
…除了:
…生成true

>;>;all(检查(复制集存储端口))
true

===
ApacheDS测试层注意::

要运行此测试::

bin/test apacheds--test=apacheds



er``启动和停止单个apacheds实例。



setup
=
=
转到https://directory.apache.org/apacheds/downloads.html





single server
===


waring
----
我们创建了一个新的apacheds层::

>;>;from lovely。testlayers导入apacheds

ht检查现在openldap服务器已经启动并运行。我们在康涅狄格州测试这个g
通过telnet连接到存储端口::

>;>import telnetlib
>;>tn=telnetlib.telnet('localhost',server.port)
>;>tn.close()



get real
----

>;>import ldap
>;>client=ldap.initialize('ldap://localhost:10389')
>;>client.simple_bind_s('uid=admin,ou=system','secret')
(97,[],1,[])


空的dit是-empty::

>;>client.search_s('dc=test,dc=example,dc=com',ldap.scope_子树,'(cn=hotzenplotz*)',['cn','mail'])
回溯(最近一次调用的最后一次):

没有这样的{'info':"没有这样的{u对象:对于消息类型:搜索请求失败…

插入一些数据::

为后缀
>;recor创建DIT上下文d=[('objectClass',['dcobject','organization'],('o','test organization'),('dc','test')]
>;>client.add_s('dc=test,dc=example,dc=com',record)
(105,[])

'],('ou','user s')]
>;>gt;客户端。添加_s('ou=users,dc=test,dc=example,dc=com',record)
(105,[])


create single user
>;…('objectClass',['top','person','organizationalperson','inetorgperson']),
…('cn','user 1'),('sn','user 1'),('uid','user1@test.example.com'),
…('userpassword','{ssha}dniz/2lws6okrgyamkg3/r4smmu+h2gm')
…]
>;>;client.add廑s('cn=user 1,ou=users,dc=test,dc=example,dc=com',record)
(105,[])


>;回复[0][0]
'cn=user 1,ou=users,dc=test,dc=dc=example,dc=com'

>>>gt;回复[0][1]['uid']
>['user1@test.example.com']


>
>>>>gt;回复[0][1]['cn']
['user 1']



>
>






>





各层层
_uuuu

断开连接后拒绝连接:

>;>;server.teardown()

>;>;telnetlib.telnet('localhost',server.port)
回溯(最近一次调用的最后一次):

错误:…连接被拒绝

==/>==


注::

要运行此测试::

bin/test openldap--test=openldap



d停止一个openldap实例。



setup
=
debian linux::


aptitude install slapd



yum install openldap servers


sudo port install openldap



single server
========


预热
----
我们从可爱的.testlayers导入openldap创建一个新的openldap层:

>>>;>;初始化层对象
>;>;server=openldap.openldap layer('openldap',port=3389)

r/>>;>server.add_schema('core.schema')
>;>server.add_schema('cosine.schema')
>;>server.add_schema('inetorgperson.schema')

>;>server.port
3389

tup()



飞行前检查现在openldap服务器已经启动并运行。我们通过telnet将
连接到存储端口进行测试:

>;>;导入telnetlib
>;>;gt;tn=telnetlib.telnet('localhost',server.port)
>;>tn.close()



Getting Real
----


>使用真正的OpenLDAP客户端连接到它:

>;>;导入LDAP
>;>;客户端=LDAP.initialize('ldap://localhost:3389')
>>>gt;客户端。简单绑定('cn=admin,dc=test,dc=example,dc=com,'secret')
(97,[],1,[])

最后一个分调用):

没有这样的对象:{'desc':'没有这样的对象'}


插入一些数据::

t.添加s('dc=test,dc=example,dc=com',record)
(105,[])


/>
创建单个用户
>;>record=[
…('objectClass',['top','person','organizationalperson','inetorgperson']),
…('cn','user 1'),('sn','user 1'),('uid','user1@test.example.com'),
…('userpassword','{ssha}dniz/2lws6okrgyamkg3/r4smmu+h2gm')
…]
>;>;client.add廑s('cn=user 1,ou=users,dc=test,dc=example,dc=com',record)
(105,[])


rs,dc=test,dc=example,dc=com,{'cn':['user1'],'uid':['user1@test.example.com']]







清理















>拆包后拒绝连接:拆包后拒绝连接:

>

>
>>;telnetlib;telnetliblib>>




>
>>>>>>.telnet('locarest,server.port)
回溯(最近一次最后一次呼叫):

错误:…连接被拒绝


====

更改历史

=====





















-将develop.txt重命名为tests.rST改进GiTub < BR/>更新ReMe.RST
Python 2.6 /Java 1.8兼容LDAP测试
BR/> BR/> 2016 /09 /07 0.7.0BR/> StututhEngutoStudioStudioStudio=
< BR/> -从NealEAR到工作空间层的重构通用功能
为OpenLDAP和APACHEDS添加服务器层LDAP服务器

2015/06/02 0.6.3
==
==


-在BaseSQL层的设置方法上与主机本地主机调用isup


/2015/03/13 0.6.2
==


-修复:在sigint上尝试静默停止nginx/>
2015/03/12 2015/03/12 0.6.1
=======



>
-在nginx层(键盘中断)增加sigint处理到nginx层(键盘中断)


<2013/09/06/2013/09/06 0.6.0
======






-server-server-server-server:现在与pytho3.3兼容






2015/03/2013/07/01 0.7/01 0.5.3.5.3

==========

-服务器层:重新打开以"开始"模式而不是"设置"模式下的日志文件

<2013/07/01 0.5.2
==



-服务器层:生成具有正确文件扩展名的日志文件


<2013/07/01 0.5.1
==


-可以指定服务器层的日志记录

-包括缓存在bu中的memcached


>
-使用openresty而不是nginx



>使用openresty而不是nginx



-依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖依赖br/>-添加smtpserverlayer的常规测试

2013/04/03 0.4.2
==

-在smtpserverlayer


2013/04/03 0.4.1/03/03/2013/04/04/03 0.4.1中添加缺少的u-name_uuu-u-name_uuu到smtpserverlayer





<2013/04/03 0.4.4.0/2013/04/04/03 0.4.0
-在smtpserverlayer中添加缺少的u-base_u-u-base_uu-u-base_uu-u添加到smtpserverlayer


>


>
-在smtpserverlayer中添加bootstrap.py和nginx/psql下载位置

2012/11/23 0.3.5
======br/>


>

>服务器层:为打开的子流程添加参数




2012/11/12 0.3.2012/11/12 0.11/12 0.3.4
======br/>===




>2012/11/12 0.3.3


>

==========
============
-服务器层:为打开的子流程添加参数





-发布时不做任何更改,因为previ发布错误2011/12/06 0.3.2


===br/>
>
-修复了服务器层中的一个无止境的循环


>2011/11/29 0.3.3.1
1服务器层中的一个无止境的循环



-在发行版中添加了丢失的自述






>2011/11/29 0.3.0


2011/2011/11/29 0.3.3.0.3.0


=======
==================

-允许在w中设置快照目录工作目录层-此
允许生成非临时快照。

-将服务器层中服务器启动的等待实现移动到
启动,这在调用测试中的启动和停止时很有用,但
在子类时可能会引入不兼容。

-m去GitHub



-postgresql 8.4 compat



>2011/05/18 0.2.2.3
=====
=======


=====

===

==

>-尝试从脚本dir(mysql 5.5)中运行命令



<2011/05/10 0.0.05/2011/05/10 0.0.2.2.2.2

===============

=========2.1
==

-修复了mysqld_路径,以便与更新的mysql版本一起工作


2011/01/07 0.2.0
==


-修复了服务器层中未绑定的本地错误

-不要在服务器层命令中使用shell选项,并清理
mysql层中的ait times

-除了路径之外,还可以在层sql脚本更改检查中使用修改时间
。这样,只有在自上次测试运行以来未修改SQL脚本的情况下才使用测试转储。

-当运行脚本在层设置中失败时停止SQL服务器,因为
否则,在TestRunner退出后服务器仍在运行。

-允许在mysql层

-修复了cassandra层的下载url

-删除了对"zc.buildout"的依赖项,该依赖项现在是一个额外的名为"cassandra"的依赖项,因为它只用于下载"cassandra"。

-删除了对"zope.testing"的依赖项与``transaction``

-不要在基本服务器层中通过管道传输stderr以防止溢出,因为
它永远不会被读取

<2010/10/22 0.1.2
====



-在mysql层的相对libexec dir中查找mysqld表

<2010/10/22 0.1.1
==

-允许在层和服务器中设置mysql-bin-dir

<2010/07/14 0.1.0
==



-修复isup签入服务器层中的等待间隔

-使用hashlib而不是sha,以避免不推荐警告。只有
与python一起工作>;=2.5


2010/03/08 0.1.0a7
====



-使mysql层能够并行处理mysqld的多个实例Ile。如果
所需的配置不在给定前缀下,则使用



2009/12/09 0.1.0a5
====


-计算出memcached层的服务器部分,这现在可以用于任何服务器实现,请参见"memcached.py"作为
示例如何使用它。



2009/11/02 0.1.0a4
===


-如果找不到mysqld,则引发适当的异常(修复3)


-将"transaction"的依赖项移动到extras[pgsql](修复2)

-修复了层中转储数据库的错误路径。(修复1)



2009/10/30 0.1.0a3
==

-postgres和mysql客户端libs现在只定义为额外的依赖项,因此在没有这些libs可用的情况下也可以安装这个包


-添加nginx层请参见nginx.txt



2009/10/29 0.1.0a2
==-增加了覆盖范围

-增加了mysqldatabaselayer

-增加了mysql server

-增加了pgdatabaselayer

-增加了pgsql server



2009/10/14 0.1.0a1
==

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spinner选定值未上载到firebase数据库   java如何通过bukkit中的配置添加消息?   java在SharedReference中保存列表的泛型类型   javascript Java小程序未定义   swt在Java中构建控制台应用程序   java OAuth同意屏幕没有突然显示,没有错误?   java webview选择文件安卓不工作   java Spring boot JPA如何从同一连接添加多个数据库?   java JDBC DB2驱动程序计时器线程处于阻塞状态   java我在vscode中运行flatter时看到一个错误在phone中运行应用程序somone能否帮助我plz   Java:生成JSON:如何避免生成不完整的JSON   java Date compareTo()方法始终返回1   当使用Junit runner运行测试时,java Spring自动连线失败   java Android/Sockets如何将信息从主UI线程发送到socket线程?   java Android内存声明全局变量   java如何在JBoss中拥有多个具有相同JNDI名称的数据源?   python在Java中嵌入CPython时,为什么会挂起?   java如何提供深度模拟对象?   java“find:smallint,expected:integer”Hibernate对informix数据库的验证在短时间内失败