diff options
Diffstat (limited to 'ishtar_common/tests.py')
| -rw-r--r-- | ishtar_common/tests.py | 41 | 
1 files changed, 36 insertions, 5 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 145b3b144..c92872612 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -26,8 +26,11 @@ import json  import os  import shutil  import tempfile +from time import time  import zipfile  from io import StringIO +from unittest.runner import TextTestRunner, TextTestResult +  from django.apps import apps @@ -407,12 +410,41 @@ class WizardTestFormData(object):              test(test_object, final_step_response) +class TimedTextTestResult(TextTestResult): + +    def __init__(self, *args, **kwargs): +        super(TimedTextTestResult, self).__init__(*args, **kwargs) +        self.clocks = {} + +    def startTest(self, test): +        self.clocks[test] = time() +        super(TextTestResult, self).startTest(test) +        if self.showAll: +            self.stream.write(self.getDescription(test)) +            self.stream.write(" ... ") +            self.stream.flush() + +    def addSuccess(self, test): +        super(TextTestResult, self).addSuccess(test) +        if self.showAll: +            self.stream.writeln("OK (%.6fs)" % (time() - self.clocks[test])) +        elif self.dots: +            self.stream.write('.') +            self.stream.flush() + + +class TimedTextTestRunner(TextTestRunner): +    resultclass = TimedTextTestResult + +  class ManagedModelTestRunner(DiscoverRunner):      """      Test runner that automatically makes all unmanaged models in your Django      project managed for the duration of the test run, so that one doesn't need      to execute the SQL manually to create them.      """ +    test_runner = TimedTextTestRunner +      def setup_test_environment(self, *args, **kwargs):          from django.apps import apps          self.unmanaged_models = [m for m in apps.get_models() @@ -467,14 +499,13 @@ class WizardTest(object):              raise ValidationError("Errors: {} on {} - dataset {}.".format(                  " ".join(errors), current_step, data_idx + 1)) -    @classmethod -    def wizard_post(cls, client, url, current_step, form_data=None, +    def wizard_post(self, client, url, current_step, form_data=None,                      follow=True, extra_data=None):          if not url: -            url = reverse(cls.url_name) +            url = reverse(self.url_name)          data = { -            '{}{}-current_step'.format(cls.url_name, -                                       cls.wizard_name): [current_step], +            '{}{}-current_step'.format(self.url_name, +                                       self.wizard_name): [current_step],          }          if not form_data:              form_data = [] | 
