Add unit tests.

see #832
This commit is contained in:
Antoine Nguyen
2016-03-02 17:15:47 +01:00
parent 62c16d1293
commit 882c137d60
3 changed files with 23 additions and 2 deletions
+2 -2
View File
@@ -235,8 +235,8 @@ class Mailbox(AdminObject):
self.quota = 0
elif int(value) > self.domain.quota and not override_rules:
raise lib_exceptions.BadRequest(
_("Quota is greater than the allowed domain's limit (%dM)"
% self.domain.quota)
_("Quota is greater than the allowed domain's limit (%dM)")
% self.domain.quota
)
else:
self.quota = value
+3
View File
@@ -113,6 +113,9 @@ class CreateAccountSerializer(AccountSerializer):
address, domain_name = email_utils.split_mailbox(full_address)
domain = get_object_or_404(
admin_models.Domain, name=domain_name)
if not creator.can_access(domain):
raise serializers.ValidationError({
"domain": _("Permission denied.")})
mb = admin_models.Mailbox(
user=account, address=address, domain=domain, **data)
mb.set_quota(
+18
View File
@@ -183,6 +183,24 @@ class AccountAPITestCase(ModoAPITestCase):
errors = json.loads(response.content)
self.assertIn("password", errors)
def test_create_account_as_domadmin(self):
"""As DomainAdmin, try to create a new account."""
self.client.credentials(
HTTP_AUTHORIZATION='Token ' + self.da_token.key)
data = copy.deepcopy(self.ACCOUNT_DATA)
data["mailbox"]["quota"] = 20
url = reverse("external_api:account-list")
response = self.client.post(url, data, format="json")
self.assertEqual(response.status_code, 400)
data["username"] = "fromapi@test2.com"
data["mailbox"].update({"full_address": "fromapi@test2.com",
"quota": 10})
url = reverse("external_api:account-list")
response = self.client.post(url, data, format="json")
self.assertEqual(response.status_code, 400)
errors = json.loads(response.content)
self.assertIn("domain", errors)
def test_create_account_bad_master_user(self):
"""Try to create a new account."""
data = copy.deepcopy(self.ACCOUNT_DATA)