annotate test/test_admin.py @ 6178:227c05ce2d85

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.
author John Rouillard <rouilj@ieee.org>
date Tue, 19 May 2020 01:14:48 -0400
parents 41907e1f9c3f
children 49f599f187e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5713
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 #
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2 # Copyright (C) 2007 Stefan Seefeld
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 # All rights reserved.
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
4 # For license terms see the file COPYING.txt.
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
5 #
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 from __future__ import print_function
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 import unittest, os, shutil, errno, sys, difflib, cgi, re
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 from roundup.admin import AdminTool
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 from . import db_test_base
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 from .test_mysql import skip_mysql
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 from .test_postgresql import skip_postgresql
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
16 #from roundup import instance
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
17
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
18 # https://stackoverflow.com/questions/4219717/how-to-assert-output-with-nosetest-unittest-in-python
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
19 # lightly modified
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
20 from contextlib import contextmanager
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
21 _py3 = sys.version_info[0] > 2
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
22 if _py3:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
23 from io import StringIO # py3
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
24 else:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
25 from StringIO import StringIO # py2
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
26
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
27 @contextmanager
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
28 def captured_output():
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
29 new_out, new_err = StringIO(), StringIO()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
30 old_out, old_err = sys.stdout, sys.stderr
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
31 try:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
32 sys.stdout, sys.stderr = new_out, new_err
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
33 yield sys.stdout, sys.stderr
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
34 finally:
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
35 sys.stdout, sys.stderr = old_out, old_err
5713
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
36
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
37 class AdminTest(object):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
38
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
39 backend = None
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
40
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
41 def setUp(self):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
42 self.dirname = '_test_admin'
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
43
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
44 def tearDown(self):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
45 try:
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
46 shutil.rmtree(self.dirname)
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
47 except OSError as error:
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
48 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
49
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
50 def install_init(self, type="classic",
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
51 settings="mail_domain=example.com," +
6177
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
52 "mail_host=localhost," +
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
53 "tracker_web=http://test/," +
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
54 "rdbms_name=rounduptest," +
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
55 "rdbms_user=rounduptest," +
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
56 "rdbms_password=rounduptest," +
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
57 "rdbms_template=template0"
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
58 ):
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
59 ''' install tracker with settings for required config.ini settings.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
60 '''
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
61
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
62 admin=AdminTool()
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
63 admin.force = True # force it to nuke existing tracker
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
64
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
65 # Run under context manager to suppress output of help text.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
66 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
67 sys.argv=['main', '-i', '_test_admin', 'install',
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
68 type, self.backend, settings ]
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
69 ret = admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
70 self.assertEqual(ret, 0)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
71
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
72 # nuke any existing database (mysql/postgreql)
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
73 # possible method in case admin.force doesn't work
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
74 #tracker = instance.open(self.dirname)
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
75 #if tracker.exists():
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
76 # tracker.nuke()
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
77
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
78 # initialize tracker with initial_data.py. Put password
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
79 # on cli so I don't have to respond to prompting.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
80 sys.argv=['main', '-i', '_test_admin', 'initialise', 'admin']
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
81 admin.force = True # force it to nuke existing database
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
82 ret = admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
83 self.assertEqual(ret, 0)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
84
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
85
5713
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
86 def testInit(self):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
87 import sys
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
88 self.admin=AdminTool()
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
89 sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend]
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
90 ret = self.admin.main()
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
91 print(ret)
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
92 self.assertTrue(ret == 0)
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
93 self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
94 self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
5762
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
95
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
96 def testInitWithConfig_ini(self):
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
97 import sys
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
98 from roundup.configuration import CoreConfig
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
99 self.admin=AdminTool()
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
100 sys.argv=['main', '-i', '_test_admin', 'install', 'classic', self.backend]
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
101 # create a config_ini.ini file in classic template
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
102 templates=self.admin.listTemplates()
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
103 config_ini_content = "[mail]\n# comment\ndebug = SendMail.LOG\n"
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
104 config_ini_path = templates['classic']['path'] + '/config_ini.ini'
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
105 config_ini_file = open(config_ini_path, "w")
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
106 config_ini_file.write(config_ini_content)
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
107 config_ini_file.close()
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
108
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
109 try:
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
110 ret = self.admin.main()
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
111 finally:
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
112 try:
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
113 # ignore file not found
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
114 os.remove(config_ini_path)
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
115 except OSError as e: # FileNotFound exception under py3
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
116 if e.errno == 2:
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
117 pass
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
118 else:
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
119 raise
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
120
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
121 print(ret)
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
122 self.assertTrue(ret == 0)
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
123 self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
124 self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
125 config=CoreConfig(self.dirname)
b76be13e027e issue2551029: Jinja2 template install error.
John Rouillard <rouilj@ieee.org>
parents: 5713
diff changeset
126 self.assertEqual(config['MAIL_DEBUG'], self.dirname + "/SendMail.LOG")
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
127
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
128 def testFind(self):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
129 ''' Note the tests will fail if you run this under pdb.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
130 the context managers capture the pdb prompts and this screws
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
131 up the stdout strings with (pdb) prefixed to the line.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
132 '''
6177
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
133 import sys
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
134
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
135 self.admin=AdminTool()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
136 self.install_init()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
137
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
138 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
139 sys.argv=['main', '-i', '_test_admin', 'create', 'issue',
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
140 'title="foo bar"', 'assignedto=admin' ]
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
141 ret = self.admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
142
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
143 out = out.getvalue().strip()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
144 print(out)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
145 self.assertEqual(out, '1')
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
146
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
147 self.admin=AdminTool()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
148 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
149 sys.argv=['main', '-i', '_test_admin', 'create', 'issue',
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
150 'title="bar foo bar"', 'assignedto=anonymous' ]
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
151 ret = self.admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
152
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
153 out = out.getvalue().strip()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
154 print(out)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
155 self.assertEqual(out, '2')
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
156
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
157 self.admin=AdminTool()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
158 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
159 sys.argv=['main', '-i', '_test_admin', 'find', 'issue',
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
160 'assignedto=1']
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
161 ret = self.admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
162
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
163 out = out.getvalue().strip()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
164 print(out)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
165 self.assertEqual(out, "['1']")
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
166
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
167 # Reopen the db closed by previous filter call
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
168 self.admin=AdminTool()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
169 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
170 ''' 1,2 should return all entries that have assignedto
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
171 either admin or anonymous
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
172 '''
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
173 sys.argv=['main', '-i', '_test_admin', 'find', 'issue',
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
174 'assignedto=1,2']
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
175 ret = self.admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
177 out = out.getvalue().strip()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
178 print(out)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
179 # out can be "['2', '1']" or "['1', '2']"
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
180 # so eval to real list so Equal can do a list compare
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
181 self.assertEqual(sorted(eval(out)), ['1', '2'])
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
182
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
183 # Reopen the db closed by previous filter call
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
184 self.admin=AdminTool()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
185 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
186 ''' 1,2 should return all entries that have assignedto
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
187 either admin or anonymous
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
188 '''
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
189 sys.argv=['main', '-i', '_test_admin', 'find', 'issue',
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
190 'assignedto=admin,anonymous']
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
191 ret = self.admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
192
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
193 out = out.getvalue().strip()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
194 print(out)
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
195 # out can be "['2', '1']" or "['1', '2']"
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
196 # so eval to real list so Equal can do a list compare
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
197 self.assertEqual(sorted(eval(out)), ['1', '2'])
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
198
6177
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
199 def testFilter(self):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
200 ''' Note the tests will fail if you run this under pdb.
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
201 the context managers capture the pdb prompts and this screws
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
202 up the stdout strings with (pdb) prefixed to the line.
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
203 '''
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
204 import sys
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
205
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
206 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
207 self.install_init()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
208
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
209 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
210 sys.argv=['main', '-i', '_test_admin', 'create', 'issue',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
211 'title="foo bar"', 'assignedto=admin' ]
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
212 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
213
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
214 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
215 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
216 self.assertEqual(out, '1')
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
217
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
218 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
219 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
220 sys.argv=['main', '-i', '_test_admin', 'create', 'issue',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
221 'title="bar foo bar"', 'assignedto=anonymous' ]
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
222 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
223
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
224 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
225 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
226 self.assertEqual(out, '2')
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
227
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
228
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
229 # Reopen the db closed by previous filter call
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
230 # test string - one results, one value, substring
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
231 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
232 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
233 sys.argv=['main', '-i', '_test_admin', 'filter', 'user',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
234 'username=admin']
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
235 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
236
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
237 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
238 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
239 self.assertEqual(out, "['1']")
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
240
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
241 # Reopen the db closed by previous filter call
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
242 # test string - two results, two values, substring
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
243 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
244 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
245 ''' a,n should return all entries that have an a and n
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
246 so admin or anonymous
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
247 '''
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
248 sys.argv=['main', '-i', '_test_admin', 'filter', 'user',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
249 'username=a,n']
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
250 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
251
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
252 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
253 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
254 # out can be "['2', '1']" or "['1', '2']"
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
255 # so eval to real list so Equal can do a list compare
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
256 self.assertEqual(sorted(eval(out)), ['1', '2'])
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
257
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
258 # Reopen the db closed by previous filter call
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
259 # test string - one result, two values, substring
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
260 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
261 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
262 ''' a,y should return all entries that have an a and y
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
263 so anonymous
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
264 '''
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
265 sys.argv=['main', '-i', '_test_admin', 'filter', 'user',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
266 'username=a,y']
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
267 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
268
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
269 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
270 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
271 self.assertEqual(out, "['2']")
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
272
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
273 # Reopen the db closed by previous filter call
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
274 # test string - no results
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
275 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
276 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
277 ''' will return empty set as admin!=anonymous
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
278 '''
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
279 sys.argv=['main', '-i', '_test_admin', 'filter', 'user',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
280 'username=admin,anonymous']
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
281 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
282
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
283 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
284 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
285 self.assertEqual(out, "[]")
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
286
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
287 # Reopen the db closed by previous filter call
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
288 # test link using ids
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
289 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
290 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
291 sys.argv=['main', '-i', '_test_admin', 'filter', 'issue',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
292 'assignedto=1,2']
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
293 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
294
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
295 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
296 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
297 self.assertEqual(sorted(eval(out)), ['1', '2'])
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
298
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
299 # Reopen the db closed by previous filter call
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
300 # test link using names
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
301 self.admin=AdminTool()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
302 with captured_output() as (out, err):
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
303 ''' will return empty set as admin!=anonymous
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
304 '''
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
305 sys.argv=['main', '-i', '_test_admin', 'filter', 'issue',
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
306 'assignedto=admin,anonymous']
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
307 ret = self.admin.main()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
308
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
309 out = out.getvalue().strip()
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
310 print(out)
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
311 self.assertEqual(sorted(eval(out)), ['1', '2'])
41907e1f9c3f Fix postgres/mysql testing; test filter.
John Rouillard <rouilj@ieee.org>
parents: 6176
diff changeset
312
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
313 def testSpecification(self):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
314 ''' Note the tests will fail if you run this under pdb.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
315 the context managers capture the pdb prompts and this screws
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
316 up the stdout strings with (pdb) prefixed to the line.
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
317 '''
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
318 import sys
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
319
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
320 self.install_init()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
321 self.admin=AdminTool()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
322
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
323 self.maxDiff = 0
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
324 import inspect
5713
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
325
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
326 spec= [ 'username: <roundup.hyperdb.String> (key property)',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
327 'alternate_addresses: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
328 'realname: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
329 'roles: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
330 'organisation: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
331 'queries: <roundup.hyperdb.Multilink to "query">',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
332 'phone: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
333 'address: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
334 'timezone: <roundup.hyperdb.String>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
335 'password: <roundup.hyperdb.Password>',
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
336 ]
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
337
6176
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
338 with captured_output() as (out, err):
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
339 sys.argv=['main', '-i', '_test_admin', 'specification', 'user']
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
340 ret = self.admin.main()
d25638d1826c Add roundup-admin filter command; fix bad doc example; add tests
John Rouillard <rouilj@ieee.org>
parents: 5762
diff changeset
341
6178
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
342 outlist = out.getvalue().strip().split("\n")
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
343 print(outlist)
227c05ce2d85 Nuke database on install and fix specification test
John Rouillard <rouilj@ieee.org>
parents: 6177
diff changeset
344 self.assertEqual(sorted(outlist), sorted(spec))
5713
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
345
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
346
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
347 class anydbmAdminTest(AdminTest, unittest.TestCase):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
348 backend = 'anydbm'
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
349
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
350
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
351 @skip_mysql
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
352 class mysqlAdminTest(AdminTest, unittest.TestCase):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
353 backend = 'mysql'
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
354
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
355
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
356 class sqliteAdminTest(AdminTest, unittest.TestCase):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
357 backend = 'sqlite'
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
358
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
359
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
360 @skip_postgresql
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
361 class postgresqlAdminTest(AdminTest, unittest.TestCase):
95dfdbaf5aa6 A basic set of tests for admin.py. Triggered by
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
362 backend = 'postgresql'

Roundup Issue Tracker: http://roundup-tracker.org/