Mercurial > p > roundup > code
comparison test/test_userauditor.py @ 5036:380d8d8b30a3
Replace existing run_tests.py script with a pytest script
The existing run_test.py script is quite old, a bit restrictive, and
doesn't always behave as documented. The pytest testing tool is mature,
well documented, and maintained.
The run_tests.py script is generating by installing py.test and running:
py.tests --genscript=run_tests.py
Note: to generate a script that is compatible with python2.6 the command
needs to be run using python2.6
| author | John Kristensen <john@jerrykan.com> |
|---|---|
| date | Thu, 20 Aug 2015 18:15:23 +1000 |
| parents | 6e9b9743de89 |
| children | 364c54991861 |
comparison
equal
deleted
inserted
replaced
| 5035:b5bb492e4b3c | 5036:380d8d8b30a3 |
|---|---|
| 1 import os, unittest, shutil | 1 import os, unittest, shutil |
| 2 | |
| 3 import pytest | |
| 4 | |
| 2 from db_test_base import setupTracker | 5 from db_test_base import setupTracker |
| 6 from .test_dates import skip_pytz | |
| 7 | |
| 3 | 8 |
| 4 class UserAuditorTest(unittest.TestCase): | 9 class UserAuditorTest(unittest.TestCase): |
| 5 def setUp(self): | 10 def setUp(self): |
| 6 self.dirname = '_test_user_auditor' | 11 self.dirname = '_test_user_auditor' |
| 7 self.instance = setupTracker(self.dirname) | 12 self.instance = setupTracker(self.dirname) |
| 8 self.db = self.instance.open('admin') | 13 self.db = self.instance.open('admin') |
| 9 self.db.tx_Source = "cli" | 14 self.db.tx_Source = "cli" |
| 10 | |
| 11 try: | |
| 12 import pytz | |
| 13 self.pytz = True | |
| 14 except ImportError: | |
| 15 self.pytz = False | |
| 16 | 15 |
| 17 self.db.user.create(username='kyle', address='kyle@example.com', | 16 self.db.user.create(username='kyle', address='kyle@example.com', |
| 18 realname='Kyle Broflovski', roles='User') | 17 realname='Kyle Broflovski', roles='User') |
| 19 | 18 |
| 20 def tearDown(self): | 19 def tearDown(self): |
| 32 self.assertRaises(ValueError, self.db.user.set, userid, timezone='3000') | 31 self.assertRaises(ValueError, self.db.user.set, userid, timezone='3000') |
| 33 self.assertRaises(ValueError, self.db.user.set, userid, timezone='24') | 32 self.assertRaises(ValueError, self.db.user.set, userid, timezone='24') |
| 34 self.assertRaises(ValueError, self.db.user.set, userid, timezone='-24') | 33 self.assertRaises(ValueError, self.db.user.set, userid, timezone='-24') |
| 35 self.assertRaises(ValueError, self.db.user.set, userid, timezone='-3000') | 34 self.assertRaises(ValueError, self.db.user.set, userid, timezone='-3000') |
| 36 | 35 |
| 37 if self.pytz: | 36 @skip_pytz |
| 38 try: | 37 def testBadTimezonesPyTZ(self): |
| 39 from pytz import UnknownTimeZoneError | 38 userid = self.db.user.lookup('kyle') |
| 40 except: | 39 |
| 41 UnknownTimeZoneError = ValueError | 40 try: |
| 42 self.assertRaises(UnknownTimeZoneError, self.db.user.set, userid, timezone='MiddleOf/Nowhere') | 41 from pytz import UnknownTimeZoneError |
| 42 except: | |
| 43 UnknownTimeZoneError = ValueError | |
| 44 | |
| 45 self.assertRaises(UnknownTimeZoneError, self.db.user.set, userid, | |
| 46 timezone='MiddleOf/Nowhere') | |
| 43 | 47 |
| 44 def testGoodTimezones(self): | 48 def testGoodTimezones(self): |
| 45 self.db.user.create(username='test_user01', timezone='12') | 49 self.db.user.create(username='test_user01', timezone='12') |
| 46 | |
| 47 if self.pytz: | |
| 48 self.db.user.create(username='test_user02', timezone='MST') | |
| 49 | 50 |
| 50 userid = self.db.user.lookup('kyle') | 51 userid = self.db.user.lookup('kyle') |
| 51 | 52 |
| 52 # TODO: roundup should accept non-integer offsets since those are valid | 53 # TODO: roundup should accept non-integer offsets since those are valid |
| 53 # this is the offset for Tehran, Iran | 54 # this is the offset for Tehran, Iran |
| 55 | 56 |
| 56 self.db.user.set(userid, timezone='-23') | 57 self.db.user.set(userid, timezone='-23') |
| 57 self.db.user.set(userid, timezone='23') | 58 self.db.user.set(userid, timezone='23') |
| 58 self.db.user.set(userid, timezone='0') | 59 self.db.user.set(userid, timezone='0') |
| 59 | 60 |
| 60 if self.pytz: | 61 @skip_pytz |
| 61 self.db.user.set(userid, timezone='US/Eastern') | 62 def testGoodTimezonesPyTZ(self): |
| 63 userid = self.db.user.lookup('kyle') | |
| 64 | |
| 65 self.db.user.create(username='test_user02', timezone='MST') | |
| 66 self.db.user.set(userid, timezone='US/Eastern') | |
| 62 | 67 |
| 63 def testBadEmailAddresses(self): | 68 def testBadEmailAddresses(self): |
| 64 userid = self.db.user.lookup('kyle') | 69 userid = self.db.user.lookup('kyle') |
| 65 self.assertRaises(ValueError, self.db.user.set, userid, address='kyle @ example.com') | 70 self.assertRaises(ValueError, self.db.user.set, userid, address='kyle @ example.com') |
| 66 self.assertRaises(ValueError, self.db.user.set, userid, address='one@example.com,two@example.com') | 71 self.assertRaises(ValueError, self.db.user.set, userid, address='one@example.com,two@example.com') |
