Commit cade5cc2 authored by Abhilash Raj's avatar Abhilash Raj

Merge branch 'patch_1' into 'master'

Add unique constraint to mail_host

See merge request !483
parents 0c79a9fc fe3c2416
Pipeline #54427009 passed with stages
in 15 minutes and 5 seconds
......@@ -43,7 +43,7 @@ class Domain(Model):
id = Column(Integer, primary_key=True)
mail_host = Column(SAUnicode)
mail_host = Column(SAUnicode, unique=True)
description = Column(SAUnicode)
owners = relationship('User',
......@@ -20,13 +20,16 @@
import unittest
from import create_list
from mailman.database.transaction import dbconnection, transaction
from mailman.interfaces.domain import (
DomainCreatedEvent, DomainCreatingEvent, DomainDeletedEvent,
DomainDeletingEvent, IDomainManager)
from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.usermanager import IUserManager
from mailman.model.domain import Domain
from mailman.testing.helpers import event_subscribers
from mailman.testing.layers import ConfigLayer
from sqlalchemy.exc import IntegrityError
from zope.component import getUtility
......@@ -175,6 +178,22 @@ class TestDomainManager(unittest.TestCase):
['', ''])
class TestDomain(unittest.TestCase):
layer = ConfigLayer
def test_unique_mail_host(self, store):
domain = Domain('abc')
# Creates the first domain and commit it right away
with transaction():
# Now creating another Domain with same mail_host and committing it
with self.assertRaises(IntegrityError):
with transaction():
class TestDomainLifecycleEvents(unittest.TestCase):
layer = ConfigLayer
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment