Increase coverage.

This commit is contained in:
Antoine Nguyen
2016-11-23 16:42:14 +01:00
parent 5eb0f57c75
commit e0d9e8061c
4 changed files with 29 additions and 3 deletions
+8
View File
@@ -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
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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)
+18
View File
@@ -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