mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Tests: remove useless Client instance.
This commit is contained in:
@@ -92,14 +92,14 @@ class AccountTestCase(ModoTestCase):
|
||||
self._set_quota("user@test.com", 0)
|
||||
|
||||
def test_set_nul_quota_as_domainadmin(self):
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
self.assertTrue(
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
)
|
||||
self._set_quota("user@test.com", 0, 400)
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
self.assertTrue(
|
||||
self.clt.login(username="admin@test2.com", password="toto")
|
||||
self.client.login(username="admin@test2.com", password="toto")
|
||||
)
|
||||
self._set_quota("user@test2.com", 0)
|
||||
|
||||
@@ -142,7 +142,7 @@ class PermissionsTestCase(ModoTestCase):
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
|
||||
def test_domain_admins(self):
|
||||
self.ajax_post(
|
||||
@@ -177,9 +177,9 @@ class PermissionsTestCase(ModoTestCase):
|
||||
username="user@test.com").is_superuser, False)
|
||||
|
||||
def test_self_modif(self):
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
self.assertTrue(
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
)
|
||||
admin = User.objects.get(username="admin@test.com")
|
||||
values = dict(
|
||||
@@ -204,14 +204,14 @@ class PermissionsTestCase(ModoTestCase):
|
||||
self.assertEqual(admin.group, "DomainAdmins")
|
||||
|
||||
def test_domadmin_access(self):
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
self.assertEqual(
|
||||
self.clt.login(username="admin@test.com", password="toto"),
|
||||
self.client.login(username="admin@test.com", password="toto"),
|
||||
True)
|
||||
response = self.clt.get(reverse("admin:domain_list"))
|
||||
response = self.client.get(reverse("admin:domain_list"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.clt.get(
|
||||
response = self.client.get(
|
||||
reverse("admin:account_change", args=[self.user.id]),
|
||||
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertNotEqual(response["Content-Type"], "application/json")
|
||||
@@ -234,8 +234,8 @@ class PermissionsTestCase(ModoTestCase):
|
||||
values
|
||||
)
|
||||
account = User.objects.get(username="superadmin2@test.com")
|
||||
self.clt.logout()
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.logout()
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
self.ajax_post(
|
||||
reverse("admin:account_delete", args=[account.id]), {}, 403
|
||||
)
|
||||
|
||||
@@ -141,7 +141,7 @@ class DomainTestCase(ModoTestCase):
|
||||
|
||||
def test_domain_flat_list(self):
|
||||
"""Test the 'domain_flat_list' view."""
|
||||
response = self.clt.get(reverse("admin:domain_flat_list"))
|
||||
response = self.client.get(reverse("admin:domain_flat_list"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
content = json.loads(response.content)
|
||||
self.assertIn("test.com", content)
|
||||
|
||||
@@ -18,11 +18,11 @@ class ExportTestCase(ModoTestCase):
|
||||
factories.populate_database()
|
||||
|
||||
def __export_identities(self, idtfilter="", grpfilter=""):
|
||||
self.clt.get(
|
||||
self.client.get(
|
||||
reverse("admin:_identity_list") +
|
||||
"?grpfilter=%s&idtfilter=%s" % (grpfilter, idtfilter)
|
||||
)
|
||||
return self.clt.post(
|
||||
return self.client.post(
|
||||
reverse("admin:identity_export"),
|
||||
{"filename": "test.csv"}
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ class ImportTestCase(ModoTestCase):
|
||||
domain; domain2.com; 200; False
|
||||
domainalias; domalias1.com; domain1.com; True
|
||||
""", name="domains.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:domain_import"), {
|
||||
"sourcefile": f
|
||||
}
|
||||
@@ -45,7 +45,7 @@ domainalias; domalias1.com; domain1.com; True
|
||||
f = ContentFile(b"""domain;test.alias;10;True
|
||||
domainalias;test.alias;test.com;True
|
||||
""", name="domains.csv")
|
||||
resp = self.clt.post(
|
||||
resp = self.client.post(
|
||||
reverse("admin:domain_import"), {
|
||||
"sourcefile": f
|
||||
}
|
||||
@@ -61,7 +61,7 @@ forward; alias2@test.com; True; user1+ext@test.com
|
||||
forward; fwd1@test.com; True; user@extdomain.com
|
||||
dlist; dlist@test.com; True; user1@test.com; user@extdomain.com
|
||||
""", name="identities.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -79,7 +79,7 @@ dlist; dlist@test.com; True; user1@test.com; user@extdomain.com
|
||||
self.assertTrue(admin.is_owner(mb1))
|
||||
self.assertEqual(mb1.full_address, "user1@test.com")
|
||||
self.assertTrue(
|
||||
self.clt.login(username="user1@test.com", password="toto")
|
||||
self.client.login(username="user1@test.com", password="toto")
|
||||
)
|
||||
|
||||
da = User.objects.get(username="truc@test.com")
|
||||
@@ -127,7 +127,7 @@ dlist; dlist@test.com; True; user1@test.com; user@extdomain.com
|
||||
f = ContentFile(b"""
|
||||
account; user1@nonlocal.com; toto; User; One; True; SimpleUsers; user1@nonlocal.com; 0
|
||||
""", name="identities.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -138,7 +138,7 @@ account; user1@nonlocal.com; toto; User; One; True; SimpleUsers; user1@nonlocal.
|
||||
f = ContentFile(b"""
|
||||
account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; ; test.com
|
||||
""", name="identities.csv")
|
||||
resp = self.clt.post(
|
||||
resp = self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -146,12 +146,12 @@ account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; ; t
|
||||
|
||||
def test_import_domain_by_domainadmin(self):
|
||||
"""Check if a domain admin is not allowed to import a domain."""
|
||||
self.clt.logout()
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.logout()
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
f = ContentFile(b"""
|
||||
domain; domain2.com; 200; False
|
||||
""", name="identities.csv")
|
||||
resp = self.clt.post(
|
||||
resp = self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -159,7 +159,7 @@ domain; domain2.com; 200; False
|
||||
f = ContentFile(b"""
|
||||
domainalias; domalias1.com; test.com; True
|
||||
""", name="identities.csv")
|
||||
resp = self.clt.post(
|
||||
resp = self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -167,12 +167,12 @@ domainalias; domalias1.com; test.com; True
|
||||
"You are not allowed to import domain aliases", resp.content)
|
||||
|
||||
def test_import_quota_too_big(self):
|
||||
self.clt.logout()
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.logout()
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
f = ContentFile(b"""
|
||||
account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; 20
|
||||
""", name="identities.csv")
|
||||
resp = self.clt.post(
|
||||
resp = self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -182,7 +182,7 @@ account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; 20
|
||||
f = ContentFile(b"""
|
||||
account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com
|
||||
""", name="identities.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True}
|
||||
)
|
||||
@@ -197,7 +197,7 @@ account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com
|
||||
account; admin@test.com; toto; Admin; ; True; DomainAdmins; admin@test.com; 0; test.com
|
||||
account; truc@test.com; toto; René; Truc; True; DomainAdmins; truc@test.com; 0; test.com
|
||||
""", name="identities.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True,
|
||||
"continue_if_exists": True}
|
||||
@@ -211,14 +211,14 @@ account; truc@test.com; toto; René; Truc; True; DomainAdmins; truc@test.com; 0;
|
||||
|
||||
Expected result: no
|
||||
"""
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
self.assertTrue(
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
)
|
||||
f = ContentFile(b"""
|
||||
account; sa@test.com; toto; Super; Admin; True; SuperAdmins; superadmin@test.com; 50
|
||||
""", name="identities.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True,
|
||||
"continue_if_exists": True}
|
||||
@@ -230,7 +230,7 @@ account; sa@test.com; toto; Super; Admin; True; SuperAdmins; superadmin@test.com
|
||||
f = ContentFile(b"""
|
||||
alias;user.alias@test.com;True;user@test.com;;;;;;;;;;;;;;;;
|
||||
""", name="identities.csv")
|
||||
self.clt.post(
|
||||
self.client.post(
|
||||
reverse("admin:identity_import"),
|
||||
{"sourcefile": f, "crypt_password": True,
|
||||
"continue_if_exists": True}
|
||||
|
||||
@@ -14,8 +14,8 @@ class ForwardTestCase(ModoTestCase):
|
||||
populate_database()
|
||||
|
||||
def test_forward_permissions(self):
|
||||
self.clt.logout()
|
||||
self.clt.login(username='user@test.com', password='toto')
|
||||
self.client.logout()
|
||||
self.client.login(username='user@test.com', password='toto')
|
||||
self.ajax_post(
|
||||
reverse('user_forward'),
|
||||
{'dest': 'user@extdomain.com', 'keepcopies': True}
|
||||
|
||||
+12
-12
@@ -21,17 +21,17 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
|
||||
def test_authentication(self):
|
||||
"""Validate simple case."""
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
data = {"username": "user@test.com", "password": "toto"}
|
||||
response = self.clt.post(reverse("core:login"), data)
|
||||
response = self.client.post(reverse("core:login"), data)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertTrue(response.url.endswith(reverse("core:user_index")))
|
||||
|
||||
response = self.clt.post(reverse("core:logout"), {})
|
||||
response = self.client.post(reverse("core:logout"), {})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
data = {"username": "admin", "password": "password"}
|
||||
response = self.clt.post(reverse("core:login"), data)
|
||||
response = self.client.post(reverse("core:login"), data)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertTrue(response.url.endswith(reverse("admin:domain_list")))
|
||||
|
||||
@@ -56,13 +56,13 @@ class ProfileTestCase(ModoTestCase):
|
||||
self.ajax_post(reverse("core:user_profile"),
|
||||
{"language": "en", "oldpassword": "password",
|
||||
"newpassword": "12345Toi", "confirmation": "12345Toi"})
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
|
||||
self.assertEqual(
|
||||
self.clt.login(username="admin", password="12345Toi"), True
|
||||
self.client.login(username="admin", password="12345Toi"), True
|
||||
)
|
||||
self.assertEqual(
|
||||
self.clt.login(username="user@test.com", password="toto"), True
|
||||
self.client.login(username="user@test.com", password="toto"), True
|
||||
)
|
||||
|
||||
self.ajax_post(
|
||||
@@ -77,9 +77,9 @@ class ProfileTestCase(ModoTestCase):
|
||||
{"language": "en", "oldpassword": "toto",
|
||||
"newpassword": "Toto1234", "confirmation": "Toto1234"}
|
||||
)
|
||||
self.clt.logout()
|
||||
self.client.logout()
|
||||
self.assertTrue(
|
||||
self.clt.login(username="user@test.com", password="Toto1234")
|
||||
self.client.login(username="user@test.com", password="Toto1234")
|
||||
)
|
||||
|
||||
|
||||
@@ -99,9 +99,9 @@ class APIAccessFormTestCase(ModoTestCase):
|
||||
"""Check access restrictions."""
|
||||
url = reverse("core:user_api_access")
|
||||
self.ajax_get(url)
|
||||
self.clt.logout()
|
||||
self.clt.login(username="user@test.com", password="toto")
|
||||
response = self.clt.get(url, HTTP_X_REQUESTED_WITH="XMLHttpRequest")
|
||||
self.client.logout()
|
||||
self.client.login(username="user@test.com", password="toto")
|
||||
response = self.client.get(url, HTTP_X_REQUESTED_WITH="XMLHttpRequest")
|
||||
self.assertEqual(response.status_code, 278)
|
||||
|
||||
def test_form(self):
|
||||
|
||||
@@ -6,7 +6,6 @@ import json
|
||||
from django import forms
|
||||
from django.core import management
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.test import APITestCase
|
||||
@@ -25,14 +24,13 @@ class ModoTestCase(TestCase):
|
||||
management.call_command("load_initial_data")
|
||||
|
||||
def setUp(self, username="admin", password="password"):
|
||||
self.clt = Client()
|
||||
self.assertEqual(
|
||||
self.clt.login(username=username, password=password), True)
|
||||
self.client.login(username=username, password=password), True)
|
||||
|
||||
def ajax_request(self, method, url, params=None, status=200):
|
||||
if params is None:
|
||||
params = {}
|
||||
response = getattr(self.clt, method)(
|
||||
response = getattr(self.client, method)(
|
||||
url, params, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, status)
|
||||
return json.loads(response.content)
|
||||
|
||||
+12
-12
@@ -32,8 +32,8 @@ class PermissionsTestCase(ModoTestCase):
|
||||
)
|
||||
self.ajax_post(reverse("admin:account_add"), values)
|
||||
account = User.objects.get(username="reseller@test.com")
|
||||
self.clt.logout()
|
||||
self.clt.login(username="admin@test.com", password="toto")
|
||||
self.client.logout()
|
||||
self.client.login(username="admin@test.com", password="toto")
|
||||
resp = self.ajax_post(
|
||||
reverse("admin:account_delete", args=[account.id]),
|
||||
{}, status=403
|
||||
@@ -125,8 +125,8 @@ class DomainAdminTestCase(ResourceTestCase):
|
||||
def setUp(self):
|
||||
"""Test initialization."""
|
||||
super(DomainAdminTestCase, self).setUp()
|
||||
self.clt.logout()
|
||||
self.clt.login(username='admin@test.com', password='toto')
|
||||
self.client.logout()
|
||||
self.client.login(username='admin@test.com', password='toto')
|
||||
|
||||
def test_mailboxes_limit(self):
|
||||
self._create_account('tester1@test.com')
|
||||
@@ -184,8 +184,8 @@ class ResellerTestCase(ResourceTestCase):
|
||||
def setUp(self):
|
||||
"""Test initialization."""
|
||||
super(ResellerTestCase, self).setUp()
|
||||
self.clt.logout()
|
||||
self.clt.login(username='reseller', password='toto')
|
||||
self.client.logout()
|
||||
self.client.login(username='reseller', password='toto')
|
||||
|
||||
def test_domains_limit(self):
|
||||
self._create_domain('domain1.tld')
|
||||
@@ -287,8 +287,8 @@ class ResellerTestCase(ResourceTestCase):
|
||||
def test_sadmin_removes_ownership(self):
|
||||
self._create_domain('domain.tld', withtpl=True)
|
||||
dom = Domain.objects.get(name="domain.tld")
|
||||
self.clt.logout()
|
||||
self.clt.login(username='admin', password='password')
|
||||
self.client.logout()
|
||||
self.client.login(username='admin', password='password')
|
||||
self.ajax_get(
|
||||
"{0}?domid={1}&daid={2}".format(
|
||||
reverse('admin:permission_remove'),
|
||||
@@ -342,13 +342,13 @@ class ResellerTestCase(ResourceTestCase):
|
||||
values
|
||||
)
|
||||
dom.add_admin(user)
|
||||
self.clt.logout()
|
||||
self.clt.login(username='admin1@domain.tld', password='Toto1234')
|
||||
self.client.logout()
|
||||
self.client.login(username='admin1@domain.tld', password='Toto1234')
|
||||
self._create_account('user1@domain.tld')
|
||||
self._create_alias('alias1@domain.tld', 'user1@domain.tld')
|
||||
self._create_alias('alias2@domain.tld', 'user1@domain.tld')
|
||||
self.clt.logout()
|
||||
self.clt.login(username='reseller', password='toto')
|
||||
self.client.logout()
|
||||
self.client.login(username='reseller', password='toto')
|
||||
# Delete the admin -> resources should go back to the
|
||||
# reseller's pool
|
||||
self.ajax_post(
|
||||
|
||||
@@ -244,8 +244,8 @@ class LimitsTestCase(ModoTestCase, Operations):
|
||||
def setUp(self):
|
||||
"""Initialize test."""
|
||||
super(LimitsTestCase, self).setUp()
|
||||
self.clt.logout()
|
||||
self.clt.login(username='reseller', password='toto')
|
||||
self.client.logout()
|
||||
self.client.login(username='reseller', password='toto')
|
||||
|
||||
def test_relay_domains_limit(self):
|
||||
self._create_relay_domain('relaydomain1.tld')
|
||||
|
||||
Reference in New Issue
Block a user