Mercurial > p > roundup > code
comparison test/test_admin.py @ 6177:41907e1f9c3f
Fix postgres/mysql testing; test filter.
Apparently I killed the testFilter test by using it for the testFind
check.
Also testing showed that filter issue assignedto=admin,anonymous
wasn't properly mapped to be the same as assignedto=1,2.
Also set all rdbms properties to allow roundup-admin to create the
databses for postgres and mysql. Pulled props from
test/db_test_base.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 19 May 2020 00:16:21 -0400 |
| parents | d25638d1826c |
| children | 227c05ce2d85 |
comparison
equal
deleted
inserted
replaced
| 6176:d25638d1826c | 6177:41907e1f9c3f |
|---|---|
| 45 except OSError as error: | 45 except OSError as error: |
| 46 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | 46 if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 47 | 47 |
| 48 def install_init(self, type="classic", | 48 def install_init(self, type="classic", |
| 49 settings="mail_domain=example.com," + | 49 settings="mail_domain=example.com," + |
| 50 "mail_host=localhost," + "tracker_web=http://test/" ): | 50 "mail_host=localhost," + |
| 51 "tracker_web=http://test/," + | |
| 52 "rdbms_name=rounduptest," + | |
| 53 "rdbms_user=rounduptest," + | |
| 54 "rdbms_password=rounduptest," + | |
| 55 "rdbms_template=template0" | |
| 56 ): | |
| 51 ''' install tracker with settings for required config.ini settings. | 57 ''' install tracker with settings for required config.ini settings. |
| 52 ''' | 58 ''' |
| 53 | 59 |
| 54 admin=AdminTool() | 60 admin=AdminTool() |
| 55 | 61 |
| 111 def testFind(self): | 117 def testFind(self): |
| 112 ''' Note the tests will fail if you run this under pdb. | 118 ''' Note the tests will fail if you run this under pdb. |
| 113 the context managers capture the pdb prompts and this screws | 119 the context managers capture the pdb prompts and this screws |
| 114 up the stdout strings with (pdb) prefixed to the line. | 120 up the stdout strings with (pdb) prefixed to the line. |
| 115 ''' | 121 ''' |
| 116 import sys, json | 122 import sys |
| 117 | 123 |
| 118 self.admin=AdminTool() | 124 self.admin=AdminTool() |
| 119 self.install_init() | 125 self.install_init() |
| 120 | 126 |
| 121 with captured_output() as (out, err): | 127 with captured_output() as (out, err): |
| 175 | 181 |
| 176 out = out.getvalue().strip() | 182 out = out.getvalue().strip() |
| 177 print(out) | 183 print(out) |
| 178 # out can be "['2', '1']" or "['1', '2']" | 184 # out can be "['2', '1']" or "['1', '2']" |
| 179 # so eval to real list so Equal can do a list compare | 185 # so eval to real list so Equal can do a list compare |
| 186 self.assertEqual(sorted(eval(out)), ['1', '2']) | |
| 187 | |
| 188 def testFilter(self): | |
| 189 ''' Note the tests will fail if you run this under pdb. | |
| 190 the context managers capture the pdb prompts and this screws | |
| 191 up the stdout strings with (pdb) prefixed to the line. | |
| 192 ''' | |
| 193 import sys | |
| 194 | |
| 195 self.admin=AdminTool() | |
| 196 self.install_init() | |
| 197 | |
| 198 with captured_output() as (out, err): | |
| 199 sys.argv=['main', '-i', '_test_admin', 'create', 'issue', | |
| 200 'title="foo bar"', 'assignedto=admin' ] | |
| 201 ret = self.admin.main() | |
| 202 | |
| 203 out = out.getvalue().strip() | |
| 204 print(out) | |
| 205 self.assertEqual(out, '1') | |
| 206 | |
| 207 self.admin=AdminTool() | |
| 208 with captured_output() as (out, err): | |
| 209 sys.argv=['main', '-i', '_test_admin', 'create', 'issue', | |
| 210 'title="bar foo bar"', 'assignedto=anonymous' ] | |
| 211 ret = self.admin.main() | |
| 212 | |
| 213 out = out.getvalue().strip() | |
| 214 print(out) | |
| 215 self.assertEqual(out, '2') | |
| 216 | |
| 217 | |
| 218 # Reopen the db closed by previous filter call | |
| 219 # test string - one results, one value, substring | |
| 220 self.admin=AdminTool() | |
| 221 with captured_output() as (out, err): | |
| 222 sys.argv=['main', '-i', '_test_admin', 'filter', 'user', | |
| 223 'username=admin'] | |
| 224 ret = self.admin.main() | |
| 225 | |
| 226 out = out.getvalue().strip() | |
| 227 print(out) | |
| 228 self.assertEqual(out, "['1']") | |
| 229 | |
| 230 # Reopen the db closed by previous filter call | |
| 231 # test string - two results, two values, substring | |
| 232 self.admin=AdminTool() | |
| 233 with captured_output() as (out, err): | |
| 234 ''' a,n should return all entries that have an a and n | |
| 235 so admin or anonymous | |
| 236 ''' | |
| 237 sys.argv=['main', '-i', '_test_admin', 'filter', 'user', | |
| 238 'username=a,n'] | |
| 239 ret = self.admin.main() | |
| 240 | |
| 241 out = out.getvalue().strip() | |
| 242 print(out) | |
| 243 # out can be "['2', '1']" or "['1', '2']" | |
| 244 # so eval to real list so Equal can do a list compare | |
| 245 self.assertEqual(sorted(eval(out)), ['1', '2']) | |
| 246 | |
| 247 # Reopen the db closed by previous filter call | |
| 248 # test string - one result, two values, substring | |
| 249 self.admin=AdminTool() | |
| 250 with captured_output() as (out, err): | |
| 251 ''' a,y should return all entries that have an a and y | |
| 252 so anonymous | |
| 253 ''' | |
| 254 sys.argv=['main', '-i', '_test_admin', 'filter', 'user', | |
| 255 'username=a,y'] | |
| 256 ret = self.admin.main() | |
| 257 | |
| 258 out = out.getvalue().strip() | |
| 259 print(out) | |
| 260 self.assertEqual(out, "['2']") | |
| 261 | |
| 262 # Reopen the db closed by previous filter call | |
| 263 # test string - no results | |
| 264 self.admin=AdminTool() | |
| 265 with captured_output() as (out, err): | |
| 266 ''' will return empty set as admin!=anonymous | |
| 267 ''' | |
| 268 sys.argv=['main', '-i', '_test_admin', 'filter', 'user', | |
| 269 'username=admin,anonymous'] | |
| 270 ret = self.admin.main() | |
| 271 | |
| 272 out = out.getvalue().strip() | |
| 273 print(out) | |
| 274 self.assertEqual(out, "[]") | |
| 275 | |
| 276 # Reopen the db closed by previous filter call | |
| 277 # test link using ids | |
| 278 self.admin=AdminTool() | |
| 279 with captured_output() as (out, err): | |
| 280 sys.argv=['main', '-i', '_test_admin', 'filter', 'issue', | |
| 281 'assignedto=1,2'] | |
| 282 ret = self.admin.main() | |
| 283 | |
| 284 out = out.getvalue().strip() | |
| 285 print(out) | |
| 286 self.assertEqual(sorted(eval(out)), ['1', '2']) | |
| 287 | |
| 288 # Reopen the db closed by previous filter call | |
| 289 # test link using names | |
| 290 self.admin=AdminTool() | |
| 291 with captured_output() as (out, err): | |
| 292 ''' will return empty set as admin!=anonymous | |
| 293 ''' | |
| 294 sys.argv=['main', '-i', '_test_admin', 'filter', 'issue', | |
| 295 'assignedto=admin,anonymous'] | |
| 296 ret = self.admin.main() | |
| 297 | |
| 298 out = out.getvalue().strip() | |
| 299 print(out) | |
| 180 self.assertEqual(sorted(eval(out)), ['1', '2']) | 300 self.assertEqual(sorted(eval(out)), ['1', '2']) |
| 181 | 301 |
| 182 def testSpecification(self): | 302 def testSpecification(self): |
| 183 ''' Note the tests will fail if you run this under pdb. | 303 ''' Note the tests will fail if you run this under pdb. |
| 184 the context managers capture the pdb prompts and this screws | 304 the context managers capture the pdb prompts and this screws |
