From 9c7912238dd3367d6a97b454a375390a0c548e3d Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Fri, 8 Sep 2023 14:22:49 -0400 Subject: [PATCH] Fix test failures with Django 4.x The wsgi.input environment variable is expected to be a stream instead of a string. Closes-Bug: #2034952 Change-Id: I72e88dcf07c90051ddf1c9030a2466501482de5d --- .../tests/dashboards/admin/share_types/test_forms.py | 9 +++++++-- manila_ui/tests/dashboards/admin/shares/test_forms.py | 6 +++++- .../dashboards/project/share_snapshots/test_tables.py | 6 +++++- manila_ui/tests/dashboards/project/shares/tests.py | 6 +++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/manila_ui/tests/dashboards/admin/share_types/test_forms.py b/manila_ui/tests/dashboards/admin/share_types/test_forms.py index 93a5d609..01b31f5c 100644 --- a/manila_ui/tests/dashboards/admin/share_types/test_forms.py +++ b/manila_ui/tests/dashboards/admin/share_types/test_forms.py @@ -13,8 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from io import BytesIO + import ddt from django.core.handlers import wsgi +from django.core.handlers.wsgi import LimitedStream from django import forms as django_forms from horizon import forms as horizon_forms from unittest import mock @@ -28,7 +31,8 @@ class ManilaDashboardsAdminSharesUpdateShareTypeFormTests(base.APITestCase): def setUp(self): super(self.__class__, self).setUp() - FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': 'fake_input'} + stream = LimitedStream(BytesIO(b"test"), 2) + FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': stream} self.request = wsgi.WSGIRequest(FAKE_ENVIRON) def _get_form(self, initial): @@ -202,7 +206,8 @@ class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase): def setUp(self): super(self.__class__, self).setUp() - FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': 'fake_input'} + stream = LimitedStream(BytesIO(b"test"), 2) + FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': stream} self.request = wsgi.WSGIRequest(FAKE_ENVIRON) def _get_form(self, **kwargs): diff --git a/manila_ui/tests/dashboards/admin/shares/test_forms.py b/manila_ui/tests/dashboards/admin/shares/test_forms.py index a965f6f3..8fb66487 100644 --- a/manila_ui/tests/dashboards/admin/shares/test_forms.py +++ b/manila_ui/tests/dashboards/admin/shares/test_forms.py @@ -13,7 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +from io import BytesIO + from django.core.handlers import wsgi +from django.core.handlers.wsgi import LimitedStream from unittest import mock from manila_ui.api import manila as api @@ -25,7 +28,8 @@ class ManilaDashboardsAdminMigrationFormTests(base.APITestCase): def setUp(self): super(self.__class__, self).setUp() - FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': 'fake_input'} + stream = LimitedStream(BytesIO(b"test"), 2) + FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': stream} self.request = wsgi.WSGIRequest(FAKE_ENVIRON) def _get_initial(self): diff --git a/manila_ui/tests/dashboards/project/share_snapshots/test_tables.py b/manila_ui/tests/dashboards/project/share_snapshots/test_tables.py index c6757daa..c54563a9 100644 --- a/manila_ui/tests/dashboards/project/share_snapshots/test_tables.py +++ b/manila_ui/tests/dashboards/project/share_snapshots/test_tables.py @@ -13,8 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from io import BytesIO + import ddt from django.core.handlers import wsgi +from django.core.handlers.wsgi import LimitedStream from unittest import mock from manila_ui.api import manila as api_manila @@ -28,7 +31,8 @@ class CreateSnapshotTests(base.APITestCase): def setUp(self): super(self.__class__, self).setUp() - FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': 'fake_input'} + stream = LimitedStream(BytesIO(b"test"), 2) + FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': stream} self.request = wsgi.WSGIRequest(FAKE_ENVIRON) self.create_snapshot = tables.CreateShareSnapshot() diff --git a/manila_ui/tests/dashboards/project/shares/tests.py b/manila_ui/tests/dashboards/project/shares/tests.py index b86619ca..87298d34 100644 --- a/manila_ui/tests/dashboards/project/shares/tests.py +++ b/manila_ui/tests/dashboards/project/shares/tests.py @@ -12,8 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from io import BytesIO + import ddt from django.core.handlers import wsgi +from django.core.handlers.wsgi import LimitedStream from django.urls import reverse from horizon import messages as horizon_messages from openstack_dashboard.api import neutron @@ -51,7 +54,8 @@ class ShareViewTests(test.APITestCase): self.mock_object( neutron, "is_service_enabled", mock.Mock(return_value=[True])) self.mock_object(horizon_messages, "success") - FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': 'fake_input'} + stream = LimitedStream(BytesIO(b"test"), 2) + FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': stream} self.request = wsgi.WSGIRequest(FAKE_ENVIRON) self.mock_object( api_manila, "tenant_absolute_limits",