Increase coverage.

see #832
This commit is contained in:
Antoine Nguyen
2016-03-02 16:15:09 +01:00
parent b6f1282c7e
commit f2d5dd229f
4 changed files with 20 additions and 6 deletions
+2 -3
View File
@@ -290,9 +290,8 @@ class Mailbox(AdminObject):
newaddress = self.user.username
if newaddress is not None:
local_part, domname = split_mailbox(newaddress)
try:
domain = Domain.objects.get(name=domname)
except Domain.DoesNotExist:
domain = Domain.objects.filter(name=domname).first()
if domain is None:
raise lib_exceptions.NotFound(_("Domain does not exist"))
if not user.can_access(domain):
raise lib_exceptions.PermDeniedException
+1 -1
View File
@@ -146,7 +146,7 @@ class CreateAccountSerializer(AccountSerializer):
if mailbox_data:
creator = self.context["request"].user
if instance.mailbox:
# FIXME: compat, to remove.
# FIXME: compat, to remove ASAP.
mailbox_data["email"] = mailbox_data["full_address"]
instance.mailbox.update_from_dict(creator, mailbox_data)
else:
+1 -2
View File
@@ -44,8 +44,7 @@ class AccountTestCase(ModoTestCase):
alias__internal=True).exists()
)
values.update({
"username": "pouet@test.com", "email": "pouet@test.com"})
values.update({"username": "pouet@test.com"})
self.ajax_post(
reverse("admin:account_change", args=[account.id]), values
)
+16
View File
@@ -211,6 +211,22 @@ class AccountAPITestCase(ModoAPITestCase):
account.refresh_from_db()
self.assertEqual(account.email, account.mailbox.full_address)
def test_update_account_wrong_address(self):
"""Try to update an account."""
account = core_models.User.objects.get(username="user@test.com")
url = reverse("external_api:account-detail", args=[account.pk])
data = {
"username": "fromapi@test3.com",
"role": account.role,
"password": "Toto1234",
"mailbox": {
"full_address": "fromapi@test3.com",
"quota": account.mailbox.quota
}
}
response = self.client.put(url, data, format="json")
self.assertEqual(response.status_code, 404)
def test_delete_account(self):
"""Try to delete an account."""
account = core_models.User.objects.get(username="user@test.com")