diff options
| -rw-r--r-- | ishtar_common/tests.py | 44 | 
1 files changed, 44 insertions, 0 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 34b25a6ec..a4014db18 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1566,6 +1566,50 @@ class AdminGenTypeTest(TestCase):              finally:                  f.close() +    def test_json_export(self): +        for model in self.gen_models: +            url = '/admin/{}/{}/'.format(self.module_name, +                                         model.__name__.lower()) +            q = model.objects +            if not q.count(): +                continue +            response = self.client.post( +                url, {'action': '_serialize_action', +                      '_selected_action': [str(o.pk) for o in q.all()]}) +            self.assertEqual( +                response.status_code, 200, +                msg="Can not export as JSON for {}.".format(model)) +            # json content already tested on full export + +    def test_json_import(self): +        for model in self.gen_models: +            q = model.objects +            nb = q.count() +            if not nb: +                continue +            base_url = '/admin/{}/{}/'.format(self.module_name, +                                              model.__name__.lower()) +            response = self.client.post( +                base_url, {'action': '_serialize_action', +                           '_selected_action': [str(o.pk) for o in q.all()]}) +            self.assertEqual( +                response.status_code, 200, +                msg="Can not export as CSV for {}.".format(model)) + +            for obj in q.all(): +                obj.delete() + +            url = base_url + 'import-from-json/' +            try: +                f = io.BytesIO(response.content) +                response = self.client.post(url, {'json_file': f, +                                                  'apply': True}) +                self.assertEqual(response.status_code, 302) +                self.assertRedirects(response, base_url) +                self.assertEqual(nb, model.objects.count()) +            finally: +                f.close() +      def test_importer_type_duplicate(self):          model = models.ImporterType          base_url = '/admin/{}/{}/'.format(self.module_name, | 
