diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-05 12:53:54 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:22:54 +0200 | 
| commit | 18a8ee8b490dee843fa6c72c710a74e9ae7afab2 (patch) | |
| tree | 2f6ed8b47622f0a32fa6a511654b71286dda5d05 /ishtar_common | |
| parent | 0e30743556cdf9b6f8268cb8e24b24abf76a2e2b (diff) | |
| download | Ishtar-18a8ee8b490dee843fa6c72c710a74e9ae7afab2.tar.bz2 Ishtar-18a8ee8b490dee843fa6c72c710a74e9ae7afab2.zip  | |
QA: fix bad QA indexing - tests
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/models.py | 6 | ||||
| -rw-r--r-- | ishtar_common/tests.py | 45 | ||||
| -rw-r--r-- | ishtar_common/views.py | 4 | 
3 files changed, 53 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 1c841a984..d8cc862f6 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2403,6 +2403,12 @@ class MainItem(ShortMenuItem):                          action.target or ""])          return qas +    @classmethod +    def get_quick_action_by_url(cls, url): +        for action in cls.QUICK_ACTIONS: +            if action.url == url: +                return action +  class LightHistorizedItem(BaseHistorizedItem):      history_date = models.DateTimeField(default=datetime.datetime.now) diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 0f00322fe..b056359ec 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -29,7 +29,7 @@ from io import StringIO  from django.apps import apps  from django.conf import settings -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Permission  from django.contrib.contenttypes.models import ContentType  from django.core.cache import cache  from django.core.exceptions import ValidationError @@ -1902,3 +1902,46 @@ class CleanMedia(TestCase):              found = try_fix_file(name, make_copy=False)              self.assertEqual(found, expected) + + +class PersonQATest(TestCase): +    model = models.Person + +    def setUp(self): +        self.username, self.password, self.user = create_superuser() +        self.user.user_permissions.add(Permission.objects.get( +            codename='change_person')) +        self.title_1 = models.TitleType.objects.create(label="T1", txt_idx="t1") +        self.title_2 = models.TitleType.objects.create(label="T2", txt_idx="t2") +        self.person_1 = models.Person.objects.create(title=self.title_1) +        self.person_2 = models.Person.objects.create(title=self.title_1) + +    def test_bulk_update(self): +        c = Client() +        pks = u"{}-{}".format(self.person_1.pk, self.person_2.pk) +        response = c.get(reverse('person-qa-bulk-update', args=[pks])) +        self.assertRedirects(response, '/') + +        c = Client() +        c.login(username=self.username, password=self.password) +        response = c.get(reverse('person-qa-bulk-update', args=[pks])) +        self.assertEqual(response.status_code, 200) + +        self.assertNotEqual(self.person_1.title, self.title_2) +        self.assertNotEqual(self.person_2.title, self.title_2) + +        response = c.post( +            reverse('person-qa-bulk-update-confirm', args=[pks]), +            {'qa_title': self.title_2.pk} +        ) +        if response.status_code != 200: +            self.assertRedirects(response, '/success/') +        self.assertEqual( +            models.Person.objects.get(pk=self.person_1.pk).title, +            self.title_2 +        ) +        self.assertEqual( +            models.Person.objects.get(pk=self.person_2.pk).title, +            self.title_2 +        ) + diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 98c538c66..bb68f6044 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -2059,13 +2059,15 @@ class AlertList(JSONResponseMixin, LoginRequiredMixin,  class QAItemForm(IshtarMixin, LoginRequiredMixin, FormView):      template_name = 'ishtar/forms/qa_form.html'      model = None +    base_url = None      form_class = None      page_name = u""      success_url = "/success/"      modal_size = None  # large, small or None (medium)      def get_quick_action(self): -        raise NotImplementedError() +        # if not listed in QUICK_ACTIONS overload this method +        return self.model.get_quick_action_by_url(self.base_url)      def dispatch(self, request, *args, **kwargs):          assert self.model  | 
