Skip to content

Commit 05da614

Browse files
author
Richard Jones
committed
Make memorydb pass all tests;
1. re-base off of anydbm and overwrite persistence bits 2. refactor core DB tests to allow in-memory persistence to work 3. remove bogus testing of file content indexing on import
1 parent 4426ce4 commit 05da614

File tree

3 files changed

+203
-111
lines changed

3 files changed

+203
-111
lines changed

test/db_test_base.py

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ def setUp(self):
135135
if os.path.exists(config.DATABASE):
136136
shutil.rmtree(config.DATABASE)
137137
os.makedirs(config.DATABASE + '/files')
138-
self.db = self.module.Database(config, 'admin')
138+
self.open_database()
139139
setupSchema(self.db, 1, self.module)
140140

141+
def open_database(self):
142+
self.db = self.module.Database(config, 'admin')
143+
141144
def testRefresh(self):
142145
self.db.refresh_database()
143146

@@ -147,23 +150,15 @@ def testRefresh(self):
147150
def testCreatorProperty(self):
148151
i = self.db.issue
149152
id1 = i.create(title='spam')
150-
self.db.commit()
151-
self.db.close()
152-
self.db = self.module.Database(config, 'fred')
153-
setupSchema(self.db, 0, self.module)
154-
i = self.db.issue
153+
self.db.journaltag = 'fred'
155154
id2 = i.create(title='spam')
156155
self.assertNotEqual(id1, id2)
157156
self.assertNotEqual(i.get(id1, 'creator'), i.get(id2, 'creator'))
158157

159158
def testActorProperty(self):
160159
i = self.db.issue
161160
id1 = i.create(title='spam')
162-
self.db.commit()
163-
self.db.close()
164-
self.db = self.module.Database(config, 'fred')
165-
setupSchema(self.db, 0, self.module)
166-
i = self.db.issue
161+
self.db.journaltag = 'fred'
167162
i.set(id1, title='asfasd')
168163
self.assertNotEqual(i.get(id1, 'creator'), i.get(id1, 'actor'))
169164

@@ -855,6 +850,7 @@ def testIndexerSearching(self):
855850
self.assertEquals(self.db.indexer.search([], self.db.issue), {})
856851
self.assertEquals(self.db.indexer.search(['hello'], self.db.issue),
857852
{i1: {'files': [f1]}})
853+
# content='world' has the wrong content-type and shouldn't be indexed
858854
self.assertEquals(self.db.indexer.search(['world'], self.db.issue), {})
859855
self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue),
860856
{i2: {}})
@@ -963,45 +959,17 @@ def testForcedReindexing(self):
963959
self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
964960
{'1': {}})
965961

966-
def testIndexingOnImport(self):
967-
# import a message
968-
msgcontent = 'Glrk'
969-
msgid = self.db.msg.import_list(['content', 'files', 'recipients'],
970-
[repr(msgcontent), '[]', '[]'])
971-
msg_filename = self.db.filename(self.db.msg.classname, msgid,
972-
create=1)
973-
support.ensureParentsExist(msg_filename)
974-
msg_file = open(msg_filename, 'w')
975-
msg_file.write(msgcontent)
976-
msg_file.close()
977-
978-
# import a file
979-
filecontent = 'Brrk'
980-
fileid = self.db.file.import_list(['content'], [repr(filecontent)])
981-
file_filename = self.db.filename(self.db.file.classname, fileid,
982-
create=1)
983-
support.ensureParentsExist(file_filename)
984-
file_file = open(file_filename, 'w')
985-
file_file.write(filecontent)
986-
file_file.close()
987-
962+
def testIndexingPropertiesOnImport(self):
988963
# import an issue
989964
title = 'Bzzt'
990965
nodeid = self.db.issue.import_list(['title', 'messages', 'files',
991-
'spam', 'nosy', 'superseder'], [repr(title), repr([msgid]),
992-
repr([fileid]), '[]', '[]', '[]'])
966+
'spam', 'nosy', 'superseder'], [repr(title), '[]', '[]',
967+
'[]', '[]', '[]'])
993968
self.db.commit()
994969

995970
# Content of title attribute is indexed
996971
self.assertEquals(self.db.indexer.search([title], self.db.issue),
997972
{str(nodeid):{}})
998-
# Content of message is indexed
999-
self.assertEquals(self.db.indexer.search([msgcontent], self.db.issue),
1000-
{str(nodeid):{'messages':[str(msgid)]}})
1001-
# Content of file is indexed
1002-
self.assertEquals(self.db.indexer.search([filecontent], self.db.issue),
1003-
{str(nodeid):{'files':[str(fileid)]}})
1004-
1005973

1006974

1007975
#
@@ -1627,7 +1595,6 @@ def nukeAndCreate(self):
16271595
self.db = self.module.Database(config, 'admin')
16281596
setupSchema(self.db, 0, self.module)
16291597

1630-
16311598
def testImportExport(self):
16321599
# use the filtering setup to create a bunch of items
16331600
ae, filt = self.filteringSetup()
@@ -1897,7 +1864,7 @@ def setUp(self):
18971864
os.makedirs(config.DATABASE + '/files')
18981865

18991866
def test_reservedProperties(self):
1900-
self.db = self.module.Database(config, 'admin')
1867+
self.open_database()
19011868
self.assertRaises(ValueError, self.module.Class, self.db, "a",
19021869
creation=String())
19031870
self.assertRaises(ValueError, self.module.Class, self.db, "a",
@@ -1908,21 +1875,21 @@ def test_reservedProperties(self):
19081875
actor=String())
19091876

19101877
def init_a(self):
1911-
self.db = self.module.Database(config, 'admin')
1878+
self.open_database()
19121879
a = self.module.Class(self.db, "a", name=String())
19131880
a.setkey("name")
19141881
self.db.post_init()
19151882

19161883
def test_fileClassProps(self):
1917-
self.db = self.module.Database(config, 'admin')
1884+
self.open_database()
19181885
a = self.module.FileClass(self.db, 'a')
19191886
l = a.getprops().keys()
19201887
l.sort()
19211888
self.assert_(l, ['activity', 'actor', 'content', 'created',
19221889
'creation', 'type'])
19231890

19241891
def init_ab(self):
1925-
self.db = self.module.Database(config, 'admin')
1892+
self.open_database()
19261893
a = self.module.Class(self.db, "a", name=String())
19271894
a.setkey("name")
19281895
b = self.module.Class(self.db, "b", name=String(),
@@ -1960,7 +1927,7 @@ def test_addNewClass(self):
19601927
self.db.getjournal('b', bid)
19611928

19621929
def init_amod(self):
1963-
self.db = self.module.Database(config, 'admin')
1930+
self.open_database()
19641931
a = self.module.Class(self.db, "a", name=String(), newstr=String(),
19651932
newint=Interval(), newnum=Number(), newbool=Boolean(),
19661933
newdate=Date())
@@ -2004,7 +1971,7 @@ def test_modifyClass(self):
20041971
self.db.getjournal('a', aid2)
20051972

20061973
def init_amodkey(self):
2007-
self.db = self.module.Database(config, 'admin')
1974+
self.open_database()
20081975
a = self.module.Class(self.db, "a", name=String(), newstr=String())
20091976
a.setkey("newstr")
20101977
b = self.module.Class(self.db, "b", name=String())
@@ -2047,7 +2014,7 @@ def test_removeClassKey(self):
20472014

20482015

20492016
def init_amodml(self):
2050-
self.db = self.module.Database(config, 'admin')
2017+
self.open_database()
20512018
a = self.module.Class(self.db, "a", name=String(),
20522019
newml=Multilink('a'))
20532020
a.setkey('name')

0 commit comments

Comments
 (0)