Ticket #19905: 19905-1.diff

File 19905-1.diff, 5.2 KB (added by Claude Paroz, 11 years ago)

Fixing test warnings

  • django/contrib/formtools/tests/wizard/namedwizardtests/forms.py

    diff --git a/django/contrib/formtools/tests/wizard/namedwizardtests/forms.py b/django/contrib/formtools/tests/wizard/namedwizardtests/forms.py
    index fa9071d..9352ae9 100644
    a b class ContactWizard(NamedUrlWizardView):  
    5050
    5151
    5252class SessionContactWizard(ContactWizard):
    53     storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'
     53    storage_name = 'django.contrib.formtools.tests.wizard.storage.WrappedSessionStorage'
    5454
    5555
    5656class CookieContactWizard(ContactWizard):
    57     storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'
     57    storage_name = 'django.contrib.formtools.tests.wizard.storage.WrappedCookieStorage'
  • django/contrib/formtools/tests/wizard/namedwizardtests/tests.py

    diff --git a/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py b/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
    index b6125db..7a595fa 100644
    a b from django.contrib.auth.tests.utils import skipIfCustomUser  
    99
    1010from django.contrib.formtools.wizard.views import (NamedUrlSessionWizardView,
    1111                                                   NamedUrlCookieWizardView)
     12from django.contrib.formtools.tests.wizard.storage import TrackingFilesMixin
    1213from django.contrib.formtools.tests.wizard.test_forms import get_request, Step1, Step2
    1314
    1415
    class NamedWizardTests(object):  
    1920        self.testuser, created = User.objects.get_or_create(username='testuser1')
    2021        self.wizard_step_data[0]['form1-user'] = self.testuser.pk
    2122
     23    def tearDown(self):
     24        for uploaded_file in TrackingFilesMixin.open_files:
     25            uploaded_file.close()
     26        TrackingFilesMixin.open_files = []
     27
    2228    def test_initial_call(self):
    2329        response = self.client.get(reverse('%s_start' % self.wizard_urlname))
    2430        self.assertEqual(response.status_code, 302)
  • django/contrib/formtools/tests/wizard/storage.py

    diff --git a/django/contrib/formtools/tests/wizard/storage.py b/django/contrib/formtools/tests/wizard/storage.py
    index c54ed9a..d157b95 100644
    a b from django.http import HttpRequest  
    55from django.conf import settings
    66
    77from django.contrib.auth.models import User
     8from django.contrib.formtools.wizard.storage.cookie import CookieStorage
     9from django.contrib.formtools.wizard.storage.session import SessionStorage
    810
    911
    1012def get_request():
    class TestStorage(object):  
    8587        storage.extra_data['test'] = True
    8688
    8789        self.assertTrue('test' in storage.extra_data)
     90
     91
     92class TrackingFilesMixin(object):
     93    """
     94    Keep track of open UploadedFiles to be able to properly close them to
     95    silence ResourceWarning on Python 3.
     96    """
     97    open_files = []
     98    def get_step_files(self, step):
     99        files = super(TrackingFilesMixin, self).get_step_files(step)
     100        if files is not None:
     101            self.open_files.extend(list(files.values()))
     102        return files
     103
     104
     105class WrappedCookieStorage(TrackingFilesMixin, CookieStorage):
     106    pass
     107
     108
     109class WrappedSessionStorage(TrackingFilesMixin, SessionStorage):
     110    pass
  • django/contrib/formtools/tests/wizard/wizardtests/forms.py

    diff --git a/django/contrib/formtools/tests/wizard/wizardtests/forms.py b/django/contrib/formtools/tests/wizard/wizardtests/forms.py
    index 5e4617c..d922d4c 100644
    a b UserFormSet = modelformset_factory(User, form=UserForm)  
    6565
    6666
    6767class SessionContactWizard(ContactWizard):
    68     storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'
     68    storage_name = 'django.contrib.formtools.tests.wizard.storage.WrappedSessionStorage'
    6969
    7070
    7171class CookieContactWizard(ContactWizard):
    72     storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'
     72    storage_name = 'django.contrib.formtools.tests.wizard.storage.WrappedCookieStorage'
  • django/contrib/formtools/tests/wizard/wizardtests/tests.py

    diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py
    index 22c5b2b..f64d424 100644
    a b from django.contrib.auth.tests.utils import skipIfCustomUser  
    1111from django.contrib.formtools.wizard.views import CookieWizardView
    1212from django.utils._os import upath
    1313from django.contrib.formtools.tests.models import Poet, Poem
     14from django.contrib.formtools.tests.wizard.storage import TrackingFilesMixin
    1415
    1516
    1617class UserForm(forms.ModelForm):
    class WizardTests(object):  
    3031        self.testuser, created = User.objects.get_or_create(username='testuser1')
    3132        self.wizard_step_data[0]['form1-user'] = self.testuser.pk
    3233
     34    def tearDown(self):
     35        for uploaded_file in TrackingFilesMixin.open_files:
     36            uploaded_file.close()
     37        TrackingFilesMixin.open_files = []
     38
    3339    def test_initial_call(self):
    3440        response = self.client.get(self.wizard_url)
    3541        wizard = response.context['wizard']
Back to Top