Commit Graph

59 Commits

Author SHA1 Message Date
Corey Bryant b5b22dd183 Fix test failures with Django 4.x
The wsgi.input environment variable is expected to be a stream.

Closes-Bug: #2034952
Change-Id: I602449245b30d5375251bd7138f538f28068a16a
2023-09-13 08:40:51 -04:00
Akihiro Motoki a9d5273f3c Address RemovedInDjango40Warning (1)
force_text() is deprecated in favor of force_str()
smart_text() is deprecated in favor of smart_str()

https://docs.djangoproject.com/en/4.0/releases/3.0/#django-utils-encoding-force-text-and-smart-text

Change-Id: Ic462fa8c3dfa26e8196df19fef5044036a9e97b4
2022-01-31 22:42:41 +09:00
manchandavishal 6efaee23d5 import "collections.abc" explicitly
Collections Abstract Base Classes have been moved to the
collections.abc module, which was part of the collections
module before[1] [2]. Usage from the collections module
directly is deprecated and will be removed from 3.10.
This commit updates to import abc module explicitly
wherever required as the same will no longer be visible/directly
used from the collections module.

[1] https://docs.python.org/3/library/collections.abc.html
[2] http://paste.openstack.org/show/802512/

Change-Id: I173f4d647474c21c5d062280bd5703edffb4978e
2021-03-04 18:47:37 +00:00
Akihiro Motoki e5d09edc20 Use python3-style super()
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
2020-10-15 14:37:20 +09:00
Akihiro Motoki 0c96dcf293 Handle case without pytest for plugin tests
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
2020-04-18 08:44:45 +09:00
Oleksii Petrenko d6fe0170ee Change horizon test runner to pytest
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
2020-04-03 13:47:18 +03:00
Akihiro Motoki ac3d139c06 Cleanup python 2.7 handling logic
We have several codes to handle the differences between py2 and py3.
py2 support has been dropped so there is no need for them now.

Change-Id: I30080f4e1a5ac04860c4341d966ee53131eb2022
2020-02-21 09:02:37 +09:00
Ivan Kolodyazhny e976461d85 Remove six usage from horizon package
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: I0b567382edf4d68674a7b8d0b02333fb57293958
2020-01-15 12:36:11 +02:00
Stephen Finucane 4ece14b28a Handle move of ABCs to collections.abc
Resolves the following warning:

  DeprecationWarning: Using or importing the ABCs from 'collections'
  instead of from 'collections.abc' is deprecated, and in 3.8 it will
  stop working

Change-Id: Ib2214e7560cda1ef510c08859d5ee0726eb66b7b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2019-09-10 19:21:20 +09:00
Akihiro Motoki b5d9aa16ce Clarify middleware public methods
In Django 1.10 the new middleware interface was introduced [1].
process_request and process_response are no longer part of the interface.
On the other hand, process_exception is the part of the interface.

To clarify that we are using the new middleware interface,
it looks better to rename the methods in the old interface to private.

[1] https://docs.djangoproject.com/en/2.0/topics/http/middleware/

Change-Id: I0bb39321f3659458a86beb2b258e9e903392620a
2018-11-07 06:24:24 +09:00
Akihiro Motoki aa1ca195f9 Drop use_mox from horizon test helpers
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
2018-08-18 17:11:15 +09:00
Ivan Kolodyazhny 1f80d94459 Use default Django test runner instead of nose
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
2018-06-08 15:21:12 +03:00
Zuul dc3b803caa Merge "Fix E402 warnings" 2018-04-24 09:49:35 +00:00
Akihiro Motoki 58019a7411 Disable mox usage by default in test helper
- 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>
2018-04-20 03:34:51 +00:00
Akihiro Motoki f0f028ca35 Fix E402 warnings
E402 module level import not at top of file

Change-Id: Ia8425ffe5b1325d00ae482d99b6764fd0fcbf822
2018-04-11 18:57:28 +09:00
Akihiro Motoki 2e3e68ad66 Switch horizon UT from mox to mock
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
2018-03-13 16:14:15 +09:00
Akihiro Motoki a987c039cf TabGroup: Make tabs pluggable via horizon plugin config
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
2018-03-12 21:04:22 +09:00
Zuul ab7e989d40 Merge "django2: adopt New-style middleware" 2018-03-09 16:49:28 +00:00
Akihiro Motoki fb9ef26a7b Allow mox-free horizon plugins to consume horizon test helper
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
2018-03-06 03:48:17 +09:00
Akihiro Motoki 3ecda5ac67 django2: adopt New-style middleware
Django 1.10 introduces a new style of middleware and
the old style was removed in Django 2.0.

https://docs.djangoproject.com/en/2.0/releases/1.10/#new-style-middleware

blueprint django2-support
Change-Id: I2fba2b1b2b528096422df3ed558ad75a1b80bbb9
2018-03-03 07:22:35 +09:00
Akihiro Motoki 1a2c957fbb Provide a way to disable mox completely
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
2018-02-15 08:36:57 +00:00
adrian-turjak 52150749a6 Fixes to allow us to use Django 1.11
Mostly the issue with Horizon was we were using some
undocumented widgets that were cut for version 1.11
django. This patch adds their code into our repo for
now, but we need to do a proper rewrite of our widgets
for Queens to use current widgets in Django.

Also edits some tests because the functionality changed
in Django 1.11

Implements: blueprint dj111
Co-Authored-By: Rob Cresswell <robert.cresswell@outlook.com>
Change-Id: I444d45f274662f4f33701c16cce4ae80cb546654
2017-07-20 01:08:56 +12:00
Akihiro Motoki 95629a337e Fix H405 (multi line docstring) warnings (horizon)
H405: multi line docstring summary not separated with an empty line

Partial-Bug: #1696996
Change-Id: I58f71206def1a25f3eda04b9297f1aa7d3caa646
2017-06-09 16:04:57 +00:00
Gábor Antal 34a3aa0ba8 Handle log message interpolation by the logger
According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.

[1]: http://docs.openstack.org/developer/oslo.i18n/guidelines.html#adding-variables-to-log-messages
Change-Id: I51f50935f1eeffe4960562d6309dfdf05814e595
Closes-Bug: #1596829
2017-03-31 20:59:16 +09:00
Akihiro Motoki 61091388e9 hacking: noqa cleanup in horizon
attribute-level imports are not checked by hacking module now.
most noqa is used to disable warnings on attribute-level imports.
This commit drops noqa for this purpose.

After this, there are 8 noqa under horizon/ :)

In addition to this, the following changes are made.

horizon/exceptions.py: The following imports are dropped.
They are not used anywhere.
  from django.http import HttpRequest
  from django.views.debug import CLEANSED_SUBSTITUTE

horizon/forms/__init__.py:
Some entries were missing in __all__. They are added.

Change-Id: I33b504ef6c396f0675e8a340867e2ca59c77c684
2017-03-17 19:38:47 +00:00
yuhui_inspur 9f8c768e47 [Trivial]Fix some type errors
Change-Id: Ibdefd786222876b976b3cac2bc244bcea5f7cf14
2017-02-07 18:52:32 -08:00
Richard Jones a17612ed97 Merge the two webdrivers
Horizon currently has two webdrivers for selenium-based
testing; this patch merges them into one so all tests
(selenium functional tests and integration tests) benefit
from improvements we make to the webdriver.

Change-Id: Iac471c2c7e40c799711746ef9e3e4ef87aecf098
2016-01-30 11:54:19 +00:00
Rob Cresswell 4b8a1eecb4 [Django 1.9] Replace django.utils.unittest
This patch replaces django.utils.unittest with unittest.
https://docs.djangoproject.com/en/1.9/releases/1.7/#django-utils-unittest

Change-Id: Ifd6138c5afa4a3e952989bf9bb73076c51f1898b
Partially-implements: blueprint drop-dj17
2016-01-18 16:19:00 +00:00
Richard Jones 89ce71c4e9 Remove some old (pre-1.8) Django compatibility code
These lines of code were introduced as Horizon migrated
through several Django versions and are no longer
needed.

Change-Id: I12aae1a843fccc803859da6337a3274339a3741f
Partially-Implements: blueprint drop-dj17
2015-11-06 06:55:22 +00:00
Victor Stinner bc35f98723 TestCase: add aliases to assert methods on py3
The Python 2 assertItemsEqual() method was renamed to
assertCountEqual() in Python 3, and assertNotRegexpMatches() was
renamed to assertNotRegex(). Add aliases in
horizon.test.helpers.TestCase.

tox.ini: add horizon.test.tests.messages to Python 3.4.

Partial-Implements: blueprint porting-python3
Change-Id: If7abd51fd3559a5ab32d433c6dc3476bd678b2bf
2015-09-15 16:17:20 +02:00
Timur Sufiev 2f5e163338 Do not call _assertNotContains override in Django newer than 1.6
Prior to Django 1.7, assertContains and assertNotContains test helper
methods behaved differently regarding the 'streaming' flag of a
response. This patch fixes the override I made earlier by calling it
conditionally only for the Django version prior to 1.7. This should
prevent problems with response._charset attribute that no longer works
in Django 1.8

Partially Implements: blueprint django18

Change-Id: I10cbc016e51b1ec7b959623989e8c4aec5899cbf
2015-07-31 16:39:14 +00:00
Victor Stinner 674a45ffe0 Replace mox with mox3
mox doesn't work on Python 3, whereas mox3 works on Python 2 and Python
3. Cinder, Nova and many other projects already replaced mox with mox3.
mox3 is now maintained by OpenStack.

Partial-Implements: blueprint porting-python3
Change-Id: I10e6a9754ebd58a2640d73ec8966527c3aa1fe9a
2015-07-13 15:02:10 +02:00
David Lyle 78eb15088e Fixing selenium tests to work with Django 1.7
Django changed the functionality of django.test.LiveServerTestCase
in 1.7  The old functionality is now supported by
django.contrib.testing.StaticLiveServerTestCase

This adds a version check to do a conditional import to pull in
either the old test case class or the new.

For more information see:
https://docs.djangoproject.com/en/1.7/ref/contrib/staticfiles/#specialized-test-case-to-support-live-testing

Closes-Bug: #1439169
Change-Id: I182847a8e77de0b9c279eeb305b536d8cdf6c43b
2015-04-03 17:08:38 -06:00
Timur Sufiev 46405d456d Fix web-server memory overrun when downloading objects from Swift
To prevent memory overrun when downloading large objects from Swift
* `resp_chunk_size` keyword should be passed to swiftclient
* `obj.data` iterator returned from swiftclient is passed to HttpResponse
  (or StreamingHttpResponse for Django>=1.5) as usual since both response
  classes work with iterators/files/byte strings (yet StreamingHttpResponse
  does it better).

The commit introduces new setting SWIFT_FILE_TRANSFER_CHUNK_SIZE that
defines the size of chunk in bytes for Swift objects downloading.

DocImpact

Change-Id: I18e5809b86bfa24948dc642da2a55dffaa1a4ce1
Closes-Bug: #1427819
2015-03-31 14:30:23 -07:00
Matt Borland 4d8777bff9 Allow Jasmine failures to fail test
There was a selector bug that caused the Jasmine helper to not find
failures in Jasmine tests.  The selectors are now fixed.

Change-Id: I2f66f4b04cd6e9fc1f7259bdac351ac0fe87e23c
Closes-Bug: 1421788
2015-03-03 18:50:43 +00:00
Radomir Dopieralski e0168e773a Make test helpers properly inheritable/extendable
The helpers.TestCase classes didn't call their superclass' methods
in their setUp and tearDown methods, which made it impossible to
probperly inherit from them and use mixins with them.

I split the code that was differing for them into separate methods,
removed common code and made them use super() correctly.

Due to some inspect magic, the factory creation has to be duplicated.

Change-Id: I0bf909b1e4324c1e36bcdb83daece391bd0cfae7
2015-02-04 10:48:32 +01:00
Christian Berendt ad64a212ba Unify the syntax used for the {{ ... }} delimter in Jinja2 templates
According to the Jinja2 documentation the preferred usage for
the syntax of the {{ ... }} delimter is {{ ... }}. This patch
changes all occurcens of {{... and ...}} to {{ ... }}.

Change-Id: I755475d1476cbfeac190217fa67dc2640917762c
2015-01-19 09:42:24 +00:00
Akihiro Motoki c228358258 Fix E127 errors in horizon/
E127 continuation line over-indented for visual indent

Partial-Bug: #1375931
Change-Id: Ib9ae85a767a85a360e5a720d8392a20069a8c873
2014-10-01 19:49:41 +09:00
Yves-Gwenael Bourhis 4824239730 Checking session timeout before authentication
If both the keystone token and the session expired, the user was asked to login
twice. This is because the token expiration was not checked.
When a user had timed out both in session and keystone token validity, the user
was asked to log in, then the timestamp was checked, and the user logged out
again and asked to log in a second time.

We now check both the timestamp and keystone token validity before
authentication validity and force back the login page to retrieve a new
keystone token, avoiding the timeout race condition between session and token
validity which was forcing a dual login. A keystone token expiration is now
considered as a session timeout too.

Also, a page can start loading while the token is valid, and finish while it's
invalid. This was leading to errors during the page loading.
We now set a TOKEN_TIMEOUT_MARGIN period in seconds which allows defining
a margin before which we consider the token as expired.
This is a configurable parameter in the django settings because the time a page
takes to render is infra and deployment specific. This margin is preset to
ten seconds.

Requires: https://review.openstack.org/101556

Closes-Bug: 1308918

Change-Id: I0bf0d079a9dc000c1a30f0e20dcaa03b22d63e51
2014-09-25 15:06:19 +02:00
Timur Sufiev 65c65dfafc Initialize table action buttons for lazy-loaded tabs
Various checkbox elements listeners that were set only for
horizon.tables should also be set for tabs which are lazy-loaded
(namely, are defined with `preload = False`) - so, they were moved to
a separate function and reused.  Provide tests for the fixed js
regression using SeleniumTestCase with authorization backend being
stubbed out. This allows to use lazy tabs defined in django code
instead of writing html fixtures (as done for QUnit tests).

Change-Id: I39954ddb439f97238511f6eee5f992213690846f
Closes-Bug: #1191006
2014-08-11 18:01:41 +04:00
Felipe Reyes af49cf1f15 Replace force_unicode with force_text
Django changed the name to force_unicode and it's only available in
python2 as an alias of force_text. The new name is available since
Django 1.4.2

Closes-Bug: #1345642
Change-Id: Ida8c545ceec7c31999f2497d540a0dc5a653d286
2014-08-06 14:34:53 +02:00
Pawel Skowron 791f384e3e Fix Flake8 style warnings in horizon/
Warnings H904, H307 and H405 are new or considerably changed, and will
be fixed in a separate patch.

Partial-bug: #1347472

Change-Id: Id9325a40d443f77242d3634002789501afbfc35a
Co-Authored-By: Juan M. Olle <juan.m.olle@intel.com>
2014-07-29 20:38:49 +00:00
Julie Pichon 29da865d45 Make xvfbwrapper import dependent on the selenium imports
It will not be required unless Selenium is also present.

Change-Id: I9da1c596ad68b68c3ce4e8cd215646209dbaebe7
Closes-Bug: #1336243
2014-06-27 21:41:05 +01:00
marianitadn 44055c1676 Add CLI option for running Selenium tests headless
- Add requirement for xfvbwrapper
- Add CLI option for running tests headless
- Update Selenium TestCase to start virtual display if the option is set
- Update documentation about running Selenium tests

Change-Id: Icb1ac3491b8eef6c168bf1421cf073da67600982
Closes-Bug: #1290329
2014-06-05 15:44:04 +03:00
Jenkins 542ae1ad73 Merge "Fixed several typos in comments" 2014-05-27 05:56:58 +00:00
Kieran Spear 1cea1cc9a0 Make selenium tests more robust
The selenium tests are often hanging in the gate due to rogue
'firefox -silent' processes. Borrow a fix from SST that overrides
the default Firefox WebDriver so it doesn't spawn the processes in the
first place.

There's also a ~10% timeout failure in the qunit/jasmine tests.
Make sure the default socket timeout is set early enough so
the initial selenium/testserver setup doesn't occasionally fail on the
first test of a test case. This gets it down to around 5% failure rate.

Also wrap each test case in a sleep() sandwich to give services time to
settle before the tests start. This isn't ideal as it makes the tests
take longer, but with this change I finally get no false negatives at all
over 100+ runs.

Change-Id: I24963f575fd6eeb81dbff883404c7cff45e97397
Closes-bug: 1317630
2014-05-26 10:41:55 +10:00
Alex Gaynor c1b4269443 Fixed several typos in comments
Change-Id: I230414c703cf47d7ec727362c20f1814324a2447
2014-05-24 14:42:14 -05:00
He Yongli e790ac070e Remove extraneous vim configuration comments
Remove vim setting:
comment - # vim: tabstop=4 shiftwidth=4 softtabstop=4

at the top of source code files, except for files in
openstack/common.

Change-Id: I9a5c6b17c6ef7ecec601f4503dfc7b31fc72e90a
Close-bug: #1229324
2014-05-06 15:30:10 +08:00
Julie Pichon ed9faf84d1 Fix unicode error when assertMessageCount() fails
When assertMessageCount() fails, we display the list of messages that
were included in the response. However because the messages are lazily
translated by default, this would fail and show the following error
instead:

 TypeError: sequence item 0: expected string, __proxy__ found

Change-Id: I1d2ed97b66428e0ee1aac783c8370ab3ea665b29
Closes-Bug: #1315031
2014-05-01 16:00:52 +01:00
Doug Fish 01133b7ce2 Remove non dev dependency on mox
Change-Id: I49267ebbf11b1898ab14216046369ff4720dbd82
Closes-Bug: 1288245
2014-03-26 11:51:54 -05:00