|
12 | 12 | # under the License. |
13 | 13 |
|
14 | 14 | import os |
| 15 | +import unittest |
15 | 16 | import warnings |
16 | 17 |
|
17 | 18 | from django.core.handlers import wsgi |
18 | | -from django.utils import unittest |
| 19 | +import mock |
| 20 | +from openstack_dashboard.test import helpers |
19 | 21 |
|
20 | 22 | from monitoring.test.test_data import utils as test_data_utils |
21 | | -from openstack_dashboard.test import helpers as openstack_dashboard_helpers |
22 | 23 |
|
23 | 24 |
|
24 | 25 | # Makes output of failing mox tests much easier to read. |
|
30 | 31 | r'^tuskar_ui[.].*[._]tests$') |
31 | 32 |
|
32 | 33 |
|
33 | | -def create_stubs(stubs_to_create={}): |
34 | | - return openstack_dashboard_helpers.create_stubs(stubs_to_create) |
| 34 | +def create_stubs(stubs_to_create=None): |
| 35 | + if stubs_to_create is None: |
| 36 | + stubs_to_create = {} |
| 37 | + return helpers.create_stubs(stubs_to_create) |
35 | 38 |
|
36 | 39 |
|
37 | | -@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False), |
38 | | - "The SKIP_UNITTESTS env variable is set.") |
39 | | -class TestCase(openstack_dashboard_helpers.TestCase): |
40 | | - """Specialized base test case class for Horizon which gives access to |
41 | | - numerous additional features: |
42 | | -
|
43 | | - * A full suite of test data through various attached objects and |
44 | | - managers (e.g. ``self.servers``, ``self.user``, etc.). See the |
45 | | - docs for :class:`~horizon.tests.test_data.utils.TestData` for more |
46 | | - information. |
47 | | - * The ``mox`` mocking framework via ``self.mox``. |
48 | | - * A set of request context data via ``self.context``. |
49 | | - * A ``RequestFactory`` class which supports Django's ``contrib.messages`` |
50 | | - framework via ``self.factory``. |
51 | | - * A ready-to-go request object via ``self.request``. |
52 | | - * The ability to override specific time data controls for easier testing. |
53 | | - * Several handy additional assertion methods. |
54 | | - """ |
55 | | - def setUp(self): |
56 | | - super(TestCase, self).setUp() |
57 | | - |
58 | | - # load tuskar-specific test data |
| 40 | +class MonitoringTestsMixin(object): |
| 41 | + def _setup_test_data(self): |
| 42 | + super(MonitoringTestsMixin, self)._setup_test_data() |
59 | 43 | test_data_utils.load_test_data(self) |
| 44 | + self.policy_patcher = mock.patch( |
| 45 | + 'openstack_auth.policy.check', lambda action, request: True) |
| 46 | + self.policy_check = self.policy_patcher.start() |
60 | 47 |
|
61 | 48 |
|
62 | | -class BaseAdminViewTests(openstack_dashboard_helpers.BaseAdminViewTests): |
63 | | - """A ``TestCase`` subclass which sets an active user with the "admin" role |
64 | | - for testing admin-only views and functionality. |
65 | | - """ |
66 | | - def setUp(self): |
67 | | - super(BaseAdminViewTests, self).setUp() |
| 49 | +@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False), |
| 50 | + "The SKIP_UNITTESTS env variable is set.") |
| 51 | +class TestCase(MonitoringTestsMixin, helpers.TestCase): |
| 52 | + pass |
68 | 53 |
|
69 | | - # load tuskar-specific test data |
70 | | - test_data_utils.load_test_data(self) |
71 | 54 |
|
| 55 | +class BaseAdminViewTests(MonitoringTestsMixin, helpers.BaseAdminViewTests): |
| 56 | + pass |
72 | 57 |
|
73 | | -class APITestCase(openstack_dashboard_helpers.APITestCase): |
74 | | - """The ``APITestCase`` class is for use with tests which deal with the |
75 | | - underlying clients rather than stubbing out the |
76 | | - openstack_dashboard.api.* methods. |
77 | | - """ |
78 | | - def setUp(self): |
79 | | - super(APITestCase, self).setUp() |
80 | 58 |
|
81 | | - # load tuskar-specfic test data |
82 | | - test_data_utils.load_test_data(self) |
| 59 | +class APITestCase(MonitoringTestsMixin, helpers.APITestCase): |
| 60 | + pass |
0 commit comments