Skip to content

Commit 445549f

Browse files
committed
Nuke database on install and fix specification test
Need to empty database as part of install_init(). Wasn't a problem for sqlite/anydbm as those got nuked by killing the test directory on each new test. For postgres/mysql in CI it needs to be nuked. Using admin.force=True to get the admin.py module to do it. If that doesn't work can open the instance and nuke it manually. Fields listed when getting specification for class are in different orders for different databases backends and versions. Use sorted lines for comparison.
1 parent 4cb97b5 commit 445549f

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

test/test_admin.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from .test_mysql import skip_mysql
1414
from .test_postgresql import skip_postgresql
1515

16+
#from roundup import instance
17+
1618
# https://stackoverflow.com/questions/4219717/how-to-assert-output-with-nosetest-unittest-in-python
1719
# lightly modified
1820
from contextlib import contextmanager
@@ -58,6 +60,7 @@ def install_init(self, type="classic",
5860
'''
5961

6062
admin=AdminTool()
63+
admin.force = True # force it to nuke existing tracker
6164

6265
# Run under context manager to suppress output of help text.
6366
with captured_output() as (out, err):
@@ -66,12 +69,20 @@ def install_init(self, type="classic",
6669
ret = admin.main()
6770
self.assertEqual(ret, 0)
6871

72+
# nuke any existing database (mysql/postgreql)
73+
# possible method in case admin.force doesn't work
74+
#tracker = instance.open(self.dirname)
75+
#if tracker.exists():
76+
# tracker.nuke()
77+
6978
# initialize tracker with initial_data.py. Put password
7079
# on cli so I don't have to respond to prompting.
7180
sys.argv=['main', '-i', '_test_admin', 'initialise', 'admin']
81+
admin.force = True # force it to nuke existing database
7282
ret = admin.main()
7383
self.assertEqual(ret, 0)
7484

85+
7586
def testInit(self):
7687
import sys
7788
self.admin=AdminTool()
@@ -309,27 +320,28 @@ def testSpecification(self):
309320
self.install_init()
310321
self.admin=AdminTool()
311322

323+
self.maxDiff = 0
312324
import inspect
313325

314-
spec='''username: <roundup.hyperdb.String> (key property)
315-
alternate_addresses: <roundup.hyperdb.String>
316-
realname: <roundup.hyperdb.String>
317-
roles: <roundup.hyperdb.String>
318-
organisation: <roundup.hyperdb.String>
319-
queries: <roundup.hyperdb.Multilink to "query">
320-
phone: <roundup.hyperdb.String>
321-
address: <roundup.hyperdb.String>
322-
timezone: <roundup.hyperdb.String>
323-
password: <roundup.hyperdb.Password>'''
324-
325-
spec = inspect.cleandoc(spec)
326+
spec= [ 'username: <roundup.hyperdb.String> (key property)',
327+
'alternate_addresses: <roundup.hyperdb.String>',
328+
'realname: <roundup.hyperdb.String>',
329+
'roles: <roundup.hyperdb.String>',
330+
'organisation: <roundup.hyperdb.String>',
331+
'queries: <roundup.hyperdb.Multilink to "query">',
332+
'phone: <roundup.hyperdb.String>',
333+
'address: <roundup.hyperdb.String>',
334+
'timezone: <roundup.hyperdb.String>',
335+
'password: <roundup.hyperdb.Password>',
336+
]
337+
326338
with captured_output() as (out, err):
327339
sys.argv=['main', '-i', '_test_admin', 'specification', 'user']
328340
ret = self.admin.main()
329341

330-
out = out.getvalue().strip()
331-
print(out)
332-
self.assertEqual(out, spec)
342+
outlist = out.getvalue().strip().split("\n")
343+
print(outlist)
344+
self.assertEqual(sorted(outlist), sorted(spec))
333345

334346

335347
class anydbmAdminTest(AdminTest, unittest.TestCase):

0 commit comments

Comments
 (0)