From e0d9e8061c4acabfc40a053eda664b0b1e24de42 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 23 Nov 2016 16:42:14 +0100 Subject: [PATCH] Increase coverage. --- modoboa/admin/tests/test_import_.py | 8 ++++++++ modoboa/relaydomains/handlers.py | 4 ++-- modoboa/relaydomains/models.py | 2 +- modoboa/relaydomains/tests.py | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/modoboa/admin/tests/test_import_.py b/modoboa/admin/tests/test_import_.py index 4fe2adf88..24b50733d 100644 --- a/modoboa/admin/tests/test_import_.py +++ b/modoboa/admin/tests/test_import_.py @@ -21,6 +21,10 @@ class ImportTestCase(ModoTestCase): factories.populate_database() def test_domains_import(self): + response = self.client.get(reverse("admin:domain_import")) + self.assertEqual(response.status_code, 200) + self.assertIn("Provide a CSV", response.content) + f = ContentFile(b"""domain; domain1.com; 100; True domain; domain2.com; 200; False domainalias; domalias1.com; domain1.com; True @@ -56,6 +60,10 @@ domainalias;test.alias;test.com;True self.assertIn('Object already exists: domainalias', resp.content) def test_identities_import(self): + response = self.client.get(reverse("admin:identity_import")) + self.assertEqual(response.status_code, 200) + self.assertIn("Provide a CSV", response.content) + f = ContentFile(b""" account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; 0 account; truc@test.com; toto; René; Truc; True; DomainAdmins; truc@test.com; 5; test.com diff --git a/modoboa/relaydomains/handlers.py b/modoboa/relaydomains/handlers.py index 533b047dc..a9bd873c0 100644 --- a/modoboa/relaydomains/handlers.py +++ b/modoboa/relaydomains/handlers.py @@ -161,5 +161,5 @@ def get_tags_for_domain(sender, domain, **kwargs): def get_import_func(sender, objtype, **kwargs): """Return function used to import objtype.""" if objtype == "relaydomain": - return [lib.import_relaydomain] - return [] + return lib.import_relaydomain + return None diff --git a/modoboa/relaydomains/models.py b/modoboa/relaydomains/models.py index b10b8eaf0..b72f17829 100644 --- a/modoboa/relaydomains/models.py +++ b/modoboa/relaydomains/models.py @@ -113,7 +113,7 @@ class RelayDomain(admin_models.AdminObject): if len(row) != 6: raise BadRequest(_("Invalid line")) self.domain = admin_models.Domain( - name=row[1].strip(), type="relaydomain", + name=row[1].strip(), type="relaydomain", quota=0, enabled=(row[4].strip() in ["True", "1", "yes", "y"]) ) self.domain.save(creator=user) diff --git a/modoboa/relaydomains/tests.py b/modoboa/relaydomains/tests.py index 695e62a6c..ed17a2db1 100644 --- a/modoboa/relaydomains/tests.py +++ b/modoboa/relaydomains/tests.py @@ -1,5 +1,6 @@ """modoboa-admin-relaydomains unit tests.""" +from django.core.files.base import ContentFile from django.core.urlresolvers import reverse from django.test import TestCase @@ -226,6 +227,23 @@ class RelayDomainsTestCase(ModoTestCase, Operations): address="alias2@relaydomain.tld").exists()) +class ImportTestCase(ModoTestCase): + """Test import.""" + + def test_webui_import(self): + """Check if import from webui works.""" + f = ContentFile("relaydomain;relay.com;127.0.0.1;relay;True;True", + name="domains.csv") + self.client.post( + reverse("admin:domain_import"), { + "sourcefile": f + } + ) + self.assertTrue( + admin_models.Domain.objects.filter( + name="relay.com", type="relaydomain").exists()) + + class LimitsTestCase(ModoTestCase, Operations): @classmethod