| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2013-2014 Ryan J Ollos <ryan.j.ollos@gmail.com> |
|---|
| 4 | # |
|---|
| 5 | # This software is licensed as described in the file COPYING, which |
|---|
| 6 | # you should have received as part of this distribution. |
|---|
| 7 | # |
|---|
| 8 | |
|---|
| 9 | import shutil |
|---|
| 10 | import tempfile |
|---|
| 11 | import unittest |
|---|
| 12 | |
|---|
| 13 | from trac.config import Configuration |
|---|
| 14 | from trac.test import EnvironmentStub |
|---|
| 15 | |
|---|
| 16 | from dynfields.options import Options |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | class OptionsTestCase(unittest.TestCase): |
|---|
| 20 | |
|---|
| 21 | def setUp(self): |
|---|
| 22 | self.env = EnvironmentStub(default_data=True, |
|---|
| 23 | enable=['trac.*', 'dynfields.*'], |
|---|
| 24 | path=tempfile.mkdtemp()) |
|---|
| 25 | |
|---|
| 26 | def tearDown(self): |
|---|
| 27 | self.env.reset_db() |
|---|
| 28 | shutil.rmtree(self.env.path) |
|---|
| 29 | |
|---|
| 30 | def test_options(self): |
|---|
| 31 | self.env.config['ticket-custom'].set('version.show_when_type', |
|---|
| 32 | 'enhancement') |
|---|
| 33 | self.env.config['ticket-custom'].set('alwayshidden.clear_on_hide', |
|---|
| 34 | False) |
|---|
| 35 | options = Options(self.env) |
|---|
| 36 | |
|---|
| 37 | self.assertEqual('enhancement', options['version.show_when_type']) |
|---|
| 38 | self.assertEqual('False', options['alwayshidden.clear_on_hide']) |
|---|
| 39 | |
|---|
| 40 | def test_options_inherit(self): |
|---|
| 41 | inherited_config = Configuration('') |
|---|
| 42 | inherited_config['ticket-custom'].set('version.show_when_type', |
|---|
| 43 | 'enhancement') |
|---|
| 44 | inherited_config['ticket-custom'].set('alwayshidden.clear_on_hide', |
|---|
| 45 | False) |
|---|
| 46 | self.env.config.parents.append(inherited_config) |
|---|
| 47 | options = Options(self.env) |
|---|
| 48 | |
|---|
| 49 | self.assertEqual('enhancement', options['version.show_when_type']) |
|---|
| 50 | self.assertEqual('False', options['alwayshidden.clear_on_hide']) |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | def test_suite(): |
|---|
| 54 | suite = unittest.TestSuite() |
|---|
| 55 | suite.addTest(unittest.makeSuite(OptionsTestCase, 'test')) |
|---|
| 56 | return suite |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | if __name__ == '__main__': |
|---|
| 60 | unittest.main(defaultTest='test_suite') |
|---|