diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-12-17 23:30:23 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:23 +0100 | 
| commit | be7c6e13365e2d28bbaace64cbbaaa78e713d9f9 (patch) | |
| tree | 405e660c5c41906de02b3d9a0cb2be639890e47d | |
| parent | 0835e730631093daea66f7f874b6c6690133bf30 (diff) | |
| download | Ishtar-be7c6e13365e2d28bbaace64cbbaaa78e713d9f9.tar.bz2 Ishtar-be7c6e13365e2d28bbaace64cbbaaa78e713d9f9.zip | |
Tests: fix qrcode path test
| -rw-r--r-- | archaeological_finds/tests.py | 6 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 10 | ||||
| -rw-r--r-- | ishtar_common/tests.py | 41 | 
3 files changed, 46 insertions, 11 deletions
| diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index c5d860cad..548a74e7b 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -343,7 +343,11 @@ class FindWizardModificationTest(WizardTest, FindInit, TestCase):      ]      def pre_wizard(self): -        find, __ = self.get_default_find() +        profile, created = IshtarSiteProfile.objects.get_or_create( +            slug='default', active=True) +        profile.warehouse = False +        profile.save() +        find, __ = self.get_default_find(force=True)          self.find = find          find.label = "base-hop"          find.check_date = "2020-07-01" diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 706bad836..3e172fc88 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1750,7 +1750,7 @@ class LockTest(TestCase, OperationInitTest):          self.operation.save()      def test_wizard_lock(self): -        cls_wiz = OperationWizardModifTest +        cls_wiz = OperationWizardModifTest()          url = reverse(cls_wiz.url_name)          # first wizard step          step = 'selec-operation_modification' @@ -1795,7 +1795,7 @@ class CustomFormTest(TestCase, OperationInitTest):          c = Client()          c.login(username=self.username, password=self.password) -        cls_wiz = OperationWizardModifTest +        cls_wiz = OperationWizardModifTest()          url = reverse(cls_wiz.url_name)          # first wizard step          step = 'selec-operation_modification' @@ -1861,7 +1861,7 @@ class CustomFormTest(TestCase, OperationInitTest):          c = Client()          c.login(username=self.username, password=self.password) -        cls_wiz = OperationWizardModifTest +        cls_wiz = OperationWizardModifTest()          url = reverse(cls_wiz.url_name)          # first wizard step          step = 'selec-operation_modification' @@ -1904,7 +1904,7 @@ class CustomFormTest(TestCase, OperationInitTest):          c = Client()          c.login(username=self.username, password=self.password) -        cls_wiz = OperationWizardModifTest +        cls_wiz = OperationWizardModifTest()          url = reverse(cls_wiz.url_name)          # first wizard step          step = 'selec-operation_modification' @@ -3174,7 +3174,7 @@ class GenerateQRCode(OperationInitTest, TestCase):          self.assertIsNotNone(self.operation.qrcode.name)          self.assertTrue(              self.operation.qrcode.name.startswith( -                "operation/2010/OP2010-1/qrcode" +                "operation/2010/OA1/qrcode"              )          ) 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 = [] | 
