HttpRequest.is_ajax() was marked as deprecated since Django 3.1 and will be
removed in Django 4.0 [1].
While the current implementation of is_ajax() relies on a jQuery-specific way
of signifying AJAX as noted in the Django relnotes, horizon works with this.
Thus this commit copies the existing logic of HttpRequest.is_ajax() to the
horizon repo (as horizon.utils.http.is_ajax()) and consumes it.
https: //docs.djangoproject.com/en/4.0/releases/3.1/#features-deprecated-in-3-1
Change-Id: I3def53033524985818a891a1b9d4659fad4ba2ba
In Django 3.0, django.utils.http.urlquote(), urlquote_plus(),
urlunquote(), and urlunquote_plus() are deprecated in favor of
the functions that they’re aliases for: urllib.parse.quote(),
quote_plus(), unquote(), and unquote_plus().
https: //docs.djangoproject.com/en/4.0/releases/3.0/
Change-Id: I37fcd917cbf87b4d3141cfbdd2675aa38f33f2a4
In Django 3.2 CookieStorage stores messages in the RFC 6265 compliant
format [1][2]. This means that horizon messages pass through cookies are
encoded in a different way that messages are encrypted.
Previously horizon UT interpretes messages in cookies literally in its own way,
but the change on CookieStorage in Django 3.2 broke it. Horizon should not
depend on its own way. The suggested way I believe is to use a method defined
in django.contrib.messages.storage.cookie.CookieStorage.
[1] https://docs.djangoproject.com/en/3.2/releases/3.2/#miscellaneous
[2] 2d6179c819
Change-Id: I3e5e12265d0bc7b753bbe1f57acdd663b9dd3587
assertFormErrors() now compares actual and expected messages
after parsing them as HTML. Similar to the previous commit,
after Django 3.0 escaped characters are handled differently
(decimal representation, hexdecimal representation and
unescaped representation) so we need an uniform way to compare
texts. Instead of comparing texts literally, this commit changes
assertFormErrors to compare texts after parsing them as HTML.
Change-Id: I4ff89cdcb27a2671c7d79fb2caec30585696a30f
During reviewing https://review.opendev.org/c/openstack/horizon/+/772603,
we noticed that a method decorated by create_mocks is called multiple time
in a single test. Previously create_mocks decorator does not stop mocking,
so this means that multiple active mock can exist for one method.
In general, it is not a good idea to mock a method multiple times at the
same time.
To cope with this situation, this commit ensures for create_mocks decorator
to stop active mocks when exiting the decorator.
This works for most cases, but it does not work only when mocking and
assertions are handled by separate methods and test logic is placed between
them. To cope with this, "stop_mock" optional argument is introduced.
FYI: Details on why "stop_mock" is needed.
I explored various ways but could not find a good way so far.
create_mocks needs to be a decorator as it needs to refer an object
reference (self). On the other hand, if we would like to merge the logic of
mocking and assertions (for example, _stub_api_calls() and _check_api_calls()
in openstack_dashboard/dashboards/project/overview/tests.py), a context
manager would be good as we would like to call it inside a class.
However, we cannot mix a decorator and a context manger as a decorator is
executed when a context manager is iniitialized and stopping mock in
the create_mocks decorator is done during the initialization of the
context manager and methods are not mocked when test code is run.
Change-Id: I9e37dc1eaa08adf36d11975fed6f5a0a90cdde52
Part of the removal of OPENSTACK_NOVA_EXTENSIONS_BLACKLIST (1/3)
All references of nova extensions in the python code are cleaned up.
Note that the API layer is not touched yet as it is used by the
JavaScript side.
Change-Id: I66cd0a9629253a6462aace9902ef8200b94b2a21
In python3, super() does not always require a class and self reference.
In other words, super() is enough for most cases.
This is much simpler and it is time to switch it to the newer style.
pylint provides a check for this.
Let's enable 'super-with-arguments' check.
NOTE: _prepare_mappings() method of FormRegion in
openstack_dashboard/test/integration_tests/regions/forms.py is refactored.
super() (without explicit class and self referece) does not work when
a subclass method calls a same method in a parent class multiple times.
It looks better to prepare a separate method to provide a common logic.
Change-Id: Id9512a14be9f20dbd5ebd63d446570c7b7c825ff
Switching the test runner to pytest in horizon assumes pytest is always
installed, but horizon test helpers are used in horizon plugin tests and
pytest is not used in horizon plugin tests. As a result, all horizon plugin
tests are now broken.
This commit considers a case where pytest does not exist.
A wrapper decorator for pytest.mark.xxxx is introduced and
it acts as a null decorator if pytest is not installed.
Change-Id: I80736b108f5ae9a36c0e756bf386468879be3293
Closes-Bug: #1873532
Changes test invocation from `manage.py test` to `pytest`. Adds addtitional
test requirements like pytest, pytest-django, pytest-html. Adds
`pytest.mark` alongside django's test `tag`. Adds posibility to export test
results into xml and html formats.
Depends-On: https://review.opendev.org/#/c/712315/
Related-Bug: #1866666
Co-Authored-By: Ivan Kolodyazhny <e0ne@e0ne.info>
Change-Id: Idb6e63cd23ca2ba8ca56f36eb8b63069bd211944
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.
Change-Id: I2de669d8e89b8daeb7ee5405ffab35af6307c40b
We don't support Python 2 anymore so we don't need this
compatibility library.
six.reraise usages are left as is until it'll be moved to some
base lib like oslo.utils to not re-implenent this method in
Horizon.
This patch also removes Python2-specific base test case methods
assertItemsEqual and assertNotRegexpMatches in flavor of new
Python 3 analogues.
Change-Id: I26a59176be9e9f213128e4945a58b9459334b626
This commit mainly covers settings in the remaining files
under openstack_dashboard.
Note that HORIZON_CONFIG, horizon and openstack_auth are not covered.
They will be covered by follow-up patches.
Part of blueprint ini-based-configuration
Change-Id: Ibd70e030445a073d9a62da9867850f4893135a89
This commit changes to run test_plugins in a separate process.
test_plugins touches urlpatterns and Site registry during setUp(),
but the cleanup process in tearDown does not recover urlpatterns correctly.
After tests under test_plugins run, the urlpatterns continues to have
entries of test panels and this leads to NoReverseMatch error when
rendering other panels after that.
I investigated details in setUp/tearDown of PluginTestCase but failed
to find a good solution to recover urlpatterns and Horizon Site registry.
As a workaround, runnig test_plugins in a separate process can avoid
the issue.
Closes-Bug: #1809983
Change-Id: I848f6b341b3f93ed055955b2b12d2497811edc5a
This patch rollbacks changes in APITestCase introduced in the
0d16361326 commit to unblock Horizon
plugins gates.
Change-Id: I6b2be31568e4aa4273990f9cfa76ca139620c84b
Closes-bug: #1806053
Closes-bug: #1805240
some of the action pages use workflow,
but the check is using assertFormErrors,
which is unreasonable,
assertFormErrors only checks one step, not all
Change-Id: I764be4a243fb9c4790c195610514663d71e18373
Although the gateway is disabled,
it still checks the format of the gateway ip and
throws an error if there is a problem with the format.
Change-Id: I8d13819175701885412ab4813e19aba0ac63a3c3
Closes-Bug: #1799896
The "request" attribute is not available in
openstack_auth.backend.KeystoneBackend.get_user when session data is restored
and it's the first request to happen after a server restart.
As stated by the function document, the "request" attribute needs to be
monkey-patched by openstack_auth.utils.patch_middleware_get_user
for this function to work properly.
This should happen in openstack_auth.urls at import time. But there is nowhere
in Horizon where this module is imported at startup. It's only introspected
by openstack_dashboard.urls due to AUTHENTICATION_URLS setting.
Without this monkey-patching, the whole authentication mechanism falls back
to "AnonymousUser" and you will get redirected to the login page due
to horizon.exceptions.NotAuthenticated being raised by
horizon.decorators.require_auth as request.user.is_authenticated will be False.
But if a user requests a page under auth/, it will have the side-effect of
monkey-patching django.contrib.auth.middleware as expected. This means that
once this request is completed, all following requests to pages other than
the ones under auth/ will have there sessions properly restored and
you will be properly authenticated.
Therefore this change introduces a dummy middleware which sole purpose is
to perform this monkey-patching as early as possible.
There is also some cleanup to get rid of the previous attempts at
monkeypatching.
Closes-bug: #1764622
Change-Id: Ib9912090a87b716e7f5710f6f360b0df168ec2e3
We announced in the Rocky cycle that use_mox will be dropped
in the beginning of Stein cycle. This commit drops use_mox and
cleans up mox related stuffs in horizon and openstack_dashboard codes.
Note that openstack_auth is under the mock migration,
so we cannot mox3 from test-requirements.txt.
blueprint mock-framework-in-unit-tests
Change-Id: I189daf2d678bef0fa8219acaab5cf45bbe54178f
Selenium tests now runs in our gate,
so this is the time to migrate them to mock.
The arguments of the first calls of image_list_detailed
in test_modal_create_image_from_url and
test_modal_create_image_from_file need to be updated.
It seems mox did not check arguments strictly.
blueprint mock-framework-in-unit-tests
Change-Id: If60734d6dbd667fe37ffe64858b93f503e6b8386
Nose has been in maintenance mode for the past several years. It has
issue with exit code [1] which leads to false positive results for our
seleniun-headless job.
This patch changes test runner for Horizon tests and does the following
things:
* Django test runner executes test in a different order than Nose does.
That's why we've got an issue with side-effect in
horizon.tests.unit.tables.test_tables.MyToggleAction class. This patch
adds workaround to it.
* Rename filename of test files to names starting with 'test_'
so that the django test runner can find tests expectedly.
* '--with-html-output' option is temporary dropped and will be added in
a following patch.
* Integraion tests is marked via django.test.tag mechanism which is
introduced in Django 1.10
* 'selenium-headless' is broken now because we don't have geckodriver on
gates, this patch makes it non-voting.
* 'tox -e cover' is fixed
* Remove @memorized decorator from
dashboards.project.images.images.tables.filter_tenant_ids function.
[1] https://github.com/nose-devs/nose/issues/984
Depends-On: https://review.openstack.org/572095
Depends-On: https://review.openstack.org/572124
Depends-On: https://review.openstack.org/572390
Depends-On: https://review.openstack.org/572391
Related blueprint: improve-horizon-testing
Change-Id: I7fb2fd7dd40f301ea822154b9809a9a07610c507
- Add use_mox = True to tests which still depend on mox
- Remove use_mox = False from all tests converted into mock
- Update the warning messages
- Replace 'S'-release with 'Stein'
Part of blueprint mock-framework-in-unit-tests
Change-Id: I208185e97b2de346304a09643a9cb3f1425a7683
Signed-off-by: Akihiro Motoki <amotoki@gmail.com>
There is no need to use stub_*client() because we can simply use
mock.patch(.object). This commit removed stub_*client().
Part of blueprint mock-framework-in-unit-tests
Change-Id: I1563720e3fc636f7b042d030baf59e0b1a0e9bf0
Signed-off-by: Akihiro Motoki <amotoki@gmail.com>
This patch changes mox to mock for the following test modules:
* openstack_dashboard/test/unit/api/test_network.py
* openstack_dashboard/test/unit/api/test_neutron.py
* openstack_dashboard/test/unit/api/rest/test_network.py
* openstack_dashboard/test/unit/api/rest/test_neutron.py
Partially-Implements: blueprint mock-framework-in-unit-tests
Change-Id: Ib97fb1c06a883fb9fd5ce39b8fe2362a88135692
This completes mock migration in horizon UT.
IsA and IsHttpRequest are moved to horizon.test.helpers
as they are genric enough and IsA is needed in a horizon UT.
Part of blueprint mock-framework-in-unit-tests
Change-Id: I702551fe900224c9ebbbf3ef815206be035b6d14
This commit enhances django tab implementation to allow horizon plugins
to add tabs to a tab group in other repository like the main horizon repo.
New setting "EXTRA_TABS" is introduced to the horizon plugin 'enabled' file.
To this aim, the tab group class looks up HORIZON_CONFIG['extra_tabs']
with its class full name and loads them as extra tabs if any.
HORIZON_CONFIG['extra_tabs'] are populated via horizon plugin settings.
This commit moves update_settings in openstack_dashboard.test.helpers
to horizon as I would like to use it in a new horizon unit test.
blueprint horizon-plugin-tab-for-info-and-quotas
Closes-Bug: #1746754
Change-Id: Ice2469a90553754929826d14d20b4719bd1f62d3
horizon test helpers now depend on mox3.
This prevents horizon plugins from consuming the test helpers
even if a plugin itself is mox free.
This commit makes mox import optional.
Change-Id: I631518d8f4cd9641920f68cd1e405298ddb7965a
Closes-Bug: #1753555
After Django 2.0 support, we no longer supports Django 1.10 or older
(Actually Django 1.10 seems to work though).
The current django.VERSION branches are all related to Django 1.10
or older, so we can drop all conditions.
py35dj20 job is now voting.
blueprint django2-support
Change-Id: Iefc0ab1c62c82f2842ec7761a9b981da9351cbd2
This commit improves examples in the docstring of create_mocks.
Note that we agreed to use a list over a tuple to define methods
to be mocked for consistency in general.
Part of blueprint mock-framework-in-unit-tests
Change-Id: Ie2e31a7a4f4d205b19190be5960770f83e1ce858
During the migration from mox to mock, it turns out there is case where
some method is called multiple times with same parameters and
it is common in openstack dashboard tests.
This commit adds assert_mock_multiple_calls_with_same_arguments assertion
method to ensure to check both call_count and arguments of all calls.
Note that assert_has_calls just checks a subset of called arguments
so it is better to check arguments of all calls.
Part of blueprint mock-framework-in-unit-tests
Change-Id: Id939e61718b0405a02a22a5ec8e55eda9554c545
create_mocks was introduced to mock multiple methods easily,
but its arguments are not compatible with create_stubs for mox.
This requires us to make many many small changes when converting
mox tests into mock. It would be nice if create_mocks is compatible
with create_stubs.
Part of blueprint mock-framework-in-unit-tests
Change-Id: I3d98448b1b9c517c194d692d6b3b53dc00e46223
This patch changes mox to mock for the following test modules:
* openstack_dashboard/test/unit/api/test_keystone.py
* openstack_dashboard/test/unit/api/rest/test_keystone.py
Partially-Implements: blueprint mock-framework-in-unit-tests
Change-Id: I5b57bd46359466ee28bff1531c8a9bfd93842ebe
(In Django 2.0) The django.core.urlresolvers module is removed
in favor of its new location, django.urls.
It was depreacted in Django 1.10:
https://docs.djangoproject.com/en/2.0/releases/1.10/#id3
blueprint django2-support
Change-Id: I46ab5c325491274b8eaffbf848e5d80f83c2fd26
This patch changes mox to mock for the following test modules:
* openstack_dashboard/test/unit/api/test_swift.py
* openstack_dashboard/test/unit/api/rest/test_swift.py
Partially-Implements: blueprint mock-framework-in-unit-tests
Change-Id: I3c920564b781c9c1c97bd6ee22b834504c94cb60
This patch changes mox to mock for the following test modules:
* openstack_dashboard/test/unit/api/test_nova.py
* openstack_dashboard/test/unit/api/rest/test_nova.py
Partially-Implements: blueprint mock-framework-in-unit-tests
Change-Id: I894ba4f1ab2123ce36f451013d8f7ebd70d9bd0f
This commit introduces 'use_mox' attribute to TestCase class.
If this is set to False, TestCase does not setup mox.
In addition, a common method to emit the deprecation warning
was introduced in APITestCase.
Part of blueprint mock-framework-in-unit-tests
Change-Id: I1e3df7ea2a867b8a7aa69523bed2beaab9663dc0
Some duplicated test scenarios were deleted. This patch also doesn't
change Selenium tests because it's out of scope of unit tests.
This patch changes mox to mock for the following test module:
* openstack_dashboard/dashboards/project/images/tests.py
* openstack_dashboard/dashboards/project/images/images/tests.py
* openstack_dashboard/dashboards/project/images/tests.py
Change-Id: I951c2e5ee1c133faa2106e1e1fdba5c72d6f63b7
Partially-Implements: blueprint mock-framework-in-unit-tests
This patch changes mox to mock for the following test modules:
* openstack_dashboard/test/api_tests/glance_tests.py
Change-Id: I282bc6a8ceca851b9755c9637790da055e6b4780
Partially-Implements: blueprint mock-framework-in-unit-tests
Orchestration tab in the admin info panel needs a discussion.
It seems not to be covered by heat-dashboard yet.
blueprint heat-dashboard-split-out
Change-Id: I56e6edb1f2ac72e2f42d0e9f3291308e67f24cad
This patch changes mox to mock for the following test module:
* openstack_dashboard/dashboards/admin/volumes/tests.py
Change-Id: Id487feb397207b3544c9398a446077e3f6a39b1a
Partially-Implements: blueprint mock-framework-in-unit-tests