Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits:
fe3c2416 by Ashrya Agrawal at 2019-03-31T06:27:52Z
Add unique constraint to mail_host
- - - - -
cade5cc2 by Abhilash Raj at 2019-03-31T06:27:52Z
Merge branch 'patch_1' into 'master'
Add unique constraint to mail_host
See merge request mailman/mailman!483
- - - - -
2 changed files:
- src/mailman/model/domain.py
- src/mailman/model/tests/test_domain.py
Changes:
=====================================
src/mailman/model/domain.py
=====================================
@@ -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',
secondary='domain_owner',
=====================================
src/mailman/model/tests/test_domain.py
=====================================
@@ -20,13 +20,16 @@
import unittest
from mailman.app.lifecycle 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):
['[email protected]', '[email protected]'])
+class TestDomain(unittest.TestCase):
+ layer = ConfigLayer
+
+ @dbconnection
+ def test_unique_mail_host(self, store):
+ domain = Domain('abc')
+ # Creates the first domain and commit it right away
+ with transaction():
+ store.add(domain)
+
+ # Now creating another Domain with same mail_host and committing it
+ with self.assertRaises(IntegrityError):
+ with transaction():
+ store.add(Domain('abc'))
+
+
class TestDomainLifecycleEvents(unittest.TestCase):
layer = ConfigLayer
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/0c79a9fc0047eb017a6993c6b3099d7bcfbc5c45...cade5cc26f4c410e649db761bed337fa2672fcfb
--
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/0c79a9fc0047eb017a6993c6b3099d7bcfbc5c45...cade5cc26f4c410e649db761bed337fa2672fcfb
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org