diff --git a/src/postorius/models.py b/src/postorius/models.py
index 2f002cb..3c7ae1d 100644
--- a/src/postorius/models.py
+++ b/src/postorius/models.py
@@ -15,7 +15,6 @@
#
# You should have received a copy of the GNU General Public License along with
# Postorius. If not, see .
-
import logging
from django.conf import settings
@@ -25,7 +24,7 @@
from django.dispatch import receiver
from django.http import Http404
from mailmanclient import Client, MailmanConnectionError
-from postorius import utils
+from postorius.utils import get_client
from urllib2 import HTTPError
@@ -49,13 +48,12 @@
"""
def __init__(self, resource_name, resource_name_plural, cls_name=None):
- self.client = utils.get_client()
self.resource_name = resource_name
self.resource_name_plural = resource_name_plural
def all(self):
try:
- return getattr(self.client, self.resource_name_plural)
+ return getattr(get_client(), self.resource_name_plural)
except AttributeError:
raise MailmanApiError
except MailmanConnectionError, e:
@@ -63,7 +61,7 @@
def get(self, **kwargs):
try:
- method = getattr(self.client, 'get_' + self.resource_name)
+ method = getattr(get_client(), 'get_' + self.resource_name)
return method(**kwargs)
except AttributeError, e:
raise MailmanApiError(e)
@@ -87,7 +85,7 @@
def create(self, **kwargs):
try:
- method = getattr(self.client, 'create_' + self.resource_name)
+ method = getattr(utils.get_client(), 'create_' + self.resource_name)
print kwargs
return method(**kwargs)
except AttributeError, e:
@@ -114,7 +112,7 @@
def all(self, only_public=False):
try:
- objects = getattr(self.client, self.resource_name_plural)
+ objects = getattr(get_client(), self.resource_name_plural)
except AttributeError:
raise MailmanApiError
except MailmanConnectionError, e:
diff --git a/src/postorius/tests/__init__.py b/src/postorius/tests/__init__.py
index de5f3dd..4c4c11a 100644
--- a/src/postorius/tests/__init__.py
+++ b/src/postorius/tests/__init__.py
@@ -25,5 +25,6 @@
"List members": ListMembersViewTest,
"List Owner Required": ListOwnerRequiredTest,
"Sync Postorius users and Mailman users": UserCreationSyncTest,
+ # "Page Tests": test_pages,
#"Doctest": tests,
}
diff --git a/src/postorius/tests/mailman_api_tests/__init__.py b/src/postorius/tests/mailman_api_tests/__init__.py
new file mode 100644
index 0000000..e92649a
--- /dev/null
+++ b/src/postorius/tests/mailman_api_tests/__init__.py
@@ -0,0 +1,14 @@
+from django.conf import settings
+
+from postorius.tests.mm_setup import setup_mm, teardown_mm, Testobject
+
+
+test_obj = Testobject()
+
+
+def setup_module():
+ setup_mm(test_obj)
+
+
+def teardown_module():
+ teardown_mm(test_obj)
diff --git a/src/postorius/tests/mailman_api_tests/test_list_index.py b/src/postorius/tests/mailman_api_tests/test_list_index.py
new file mode 100644
index 0000000..1c249cd
--- /dev/null
+++ b/src/postorius/tests/mailman_api_tests/test_list_index.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 by the Free Software Foundation, Inc.
+#
+# This file is part of Postorius.
+#
+# Postorius is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+# Postorius is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Postorius. If not, see .
+import logging
+
+from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.test.client import Client
+from django.test.utils import override_settings
+
+from postorius.tests.mm_setup import mm_client
+
+
+logger = logging.getLogger(__name__)
+
+
+def setup_module():
+ # Create a domain for all tests in this module.
+ mm_client.create_domain(
+ 'example.com',
+ contact_address='postmaster@example.com',
+ base_url='lists.example.com')
+
+
+def teardown_module():
+ # Clean up.
+ mm_client.delete_domain('example.com')
+
+
+@override_settings(
+ MAILMAN_API_URL='http://localhost:9001',
+ MAILMAN_USER='restadmin',
+ MAILMAN_PASS='restpass')
+class ListIndexPageTest(TestCase):
+ """Tests for the list index page."""
+
+ def setUp(self):
+ self.client = Client()
+ domain = mm_client.get_domain('example.com')
+ self.foo_list = domain.create_list('foo')
+
+ def tearDown(self):
+ self.foo_list.delete()
+
+ def test_list_index_contains_one_list(self):
+ # The list index page should contain the
+ response = self.client.get(reverse('list_index'))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.context['lists']), 1)
+ self.assertEqual(response.context['lists'][0].fqdn_listname,
+ 'foo@example.com')
diff --git a/src/postorius/tests/mailman_api_tests/test_list_members.py b/src/postorius/tests/mailman_api_tests/test_list_members.py
new file mode 100644
index 0000000..e1a659f
--- /dev/null
+++ b/src/postorius/tests/mailman_api_tests/test_list_members.py
@@ -0,0 +1,119 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 by the Free Software Foundation, Inc.
+#
+# This file is part of Postorius.
+#
+# Postorius is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+# Postorius is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Postorius. If not, see .
+import logging
+
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.test.client import Client
+from django.test.utils import override_settings
+
+from postorius.tests.mm_setup import mm_client
+
+
+logger = logging.getLogger(__name__)
+
+
+def setup_module():
+ # Create a domain for all tests in this module.
+ mm_client.create_domain(
+ 'example.com',
+ contact_address='postmaster@example.com',
+ base_url='lists.example.com')
+
+
+def teardown_module():
+ # Clean up.
+ mm_client.delete_domain('example.com')
+
+
+@override_settings(
+ MAILMAN_API_URL='http://localhost:9001',
+ MAILMAN_USER='restadmin',
+ MAILMAN_PASS='restpass')
+class ListMembersPageTest(TestCase):
+ """Tests for the list members page.
+
+ Tests permissions and creation of list owners and moderators.
+ """
+
+ def setUp(self):
+ self.client = Client()
+ domain = mm_client.get_domain('example.com')
+ self.foo_list = domain.create_list('foo')
+ self.user = User.objects.create_user('testuser', 'test@example.com',
+ 'testpass')
+ self.superuser = User.objects.create_superuser('testsu',
+ 'su@example.com',
+ 'testpass')
+ self.owner = User.objects.create_user('testowner', 'owner@example.com',
+ 'testpass')
+ self.moderator = User.objects.create_user('testmoderator',
+ 'moderator@example.com',
+ 'testpass')
+ self.foo_list.add_owner('owner@example.com')
+ self.foo_list.add_moderator('moderator@example.com')
+
+ def tearDown(self):
+ self.foo_list.delete()
+ self.user.delete()
+ self.superuser.delete()
+ self.owner.delete()
+ self.moderator.delete()
+
+ def test_page_not_accessible_if_not_logged_in(self):
+ response = self.client.get(reverse('list_members',
+ args=('foo@example.com', )))
+ self.assertEqual(response.status_code, 403)
+
+ def test_page_not_accessible_for_unprivileged_users(self):
+ self.client.login(username='testuser', password='testpass')
+ response = self.client.get(reverse('list_members',
+ args=('foo@example.com', )))
+ self.assertEqual(response.status_code, 403)
+
+ def test_page_not_accessible_for_moderator(self):
+ self.client.login(username='testmoderator', password='testpass')
+ response = self.client.get(reverse('list_members',
+ args=('foo@example.com', )))
+ self.assertEqual(response.status_code, 403)
+
+ def test_page_accessible_for_superuser(self):
+ self.client.login(username='testsu', password='testpass')
+ response = self.client.get(reverse('list_members',
+ args=('foo@example.com', )))
+ self.assertEqual(response.status_code, 200)
+
+ def test_page_accessible_for_owner(self):
+ self.client.login(username='testowner', password='testpass')
+ response = self.client.get(reverse('list_members',
+ args=('foo@example.com', )))
+ self.assertEqual(response.status_code, 200)
+
+ def test_add_owner(self):
+ self.client.login(username='testsu', password='testpass')
+ self.client.post(reverse('list_members',
+ args=('foo@example.com', )),
+ {'owner_email': 'newowner@example.com'})
+ self.assertTrue(u'newowner@example.com' in self.foo_list.owners)
+
+ def test_add_moderator(self):
+ self.client.login(username='testsu', password='testpass')
+ self.client.post(reverse('list_members',
+ args=('foo@example.com', )),
+ {'moderator_email': 'newmod@example.com'})
+ self.assertTrue(u'newmod@example.com' in self.foo_list.moderators)
diff --git a/src/postorius/tests/mailman_api_tests/test_list_new.py b/src/postorius/tests/mailman_api_tests/test_list_new.py
new file mode 100644
index 0000000..3de5c8d
--- /dev/null
+++ b/src/postorius/tests/mailman_api_tests/test_list_new.py
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 by the Free Software Foundation, Inc.
+#
+# This file is part of Postorius.
+#
+# Postorius is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+# Postorius is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Postorius. If not, see .
+import time
+import logging
+
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.test.client import Client
+from django.test.utils import override_settings
+
+from postorius.tests.mm_setup import mm_client
+
+
+logger = logging.getLogger(__name__)
+
+
+def setup_module():
+ # Create a domain for all tests in this module.
+ mm_client.create_domain(
+ 'example.com',
+ contact_address='postmaster@example.com',
+ base_url='lists.example.com')
+
+
+def teardown_module():
+ # Clean up.
+ mm_client.delete_domain('example.com')
+
+
+@override_settings(
+ MAILMAN_API_URL='http://localhost:9001',
+ MAILMAN_USER='restadmin',
+ MAILMAN_PASS='restpass')
+class ListCreationTest(TestCase):
+ """Tests for the new list page."""
+
+ def setUp(self):
+ self.client = Client()
+ self.user = User.objects.create_user('user', 'user@example.com', 'pwd')
+ self.superuser = User.objects.create_superuser('su', 'su@example.com',
+ 'pwd')
+
+ def tearDown(self):
+ self.user.delete()
+ self.superuser.delete()
+
+ def test_permission_denied(self):
+ self.client.login(username='user', password='pwd')
+ response = self.client.get(reverse('list_new'))
+ self.assertRedirects(
+ response,
+ '/postorius/accounts/login/?next=/postorius/lists/new/')
+
+ def test_page_accessible_to_su(self):
+ self.client.login(username='su', password='pwd')
+ response = self.client.get(reverse('list_new'))
+ self.assertEqual(response.status_code, 200)
+
+ def test_new_list_created(self):
+ self.client.login(username='su', password='pwd')
+ post_data = {'listname': 'a_new_list',
+ 'mail_host': 'example.com',
+ 'list_owner': 'owner@example.com',
+ 'advertised': 'True',
+ 'description': 'A new list.'}
+ self.client.post(reverse('list_new'), post_data)
+ a_new_list = mm_client.get_list('a_new_list@example.com')
+ self.assertEqual(a_new_list.fqdn_listname, u'a_new_list@example.com')
diff --git a/src/postorius/tests/mailman_api_tests/test_list_summary.py b/src/postorius/tests/mailman_api_tests/test_list_summary.py
new file mode 100644
index 0000000..60a9c7d
--- /dev/null
+++ b/src/postorius/tests/mailman_api_tests/test_list_summary.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 by the Free Software Foundation, Inc.
+#
+# This file is part of Postorius.
+#
+# Postorius is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+# Postorius is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Postorius. If not, see .
+import logging
+
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.test.client import Client
+from django.test.utils import override_settings
+
+from postorius.tests.mm_setup import mm_client
+
+
+logger = logging.getLogger(__name__)
+
+
+def setup_module():
+ # Create a domain for all tests in this module.
+ mm_client.create_domain(
+ 'example.com',
+ contact_address='postmaster@example.com',
+ base_url='lists.example.com')
+
+
+def teardown_module():
+ # Clean up.
+ mm_client.delete_domain('example.com')
+
+
+@override_settings(
+ MAILMAN_API_URL='http://localhost:9001',
+ MAILMAN_USER='restadmin',
+ MAILMAN_PASS='restpass')
+class ListSummaryPageTest(TestCase):
+ """Tests for the list summary page.
+
+ Tests accessiblity and existince of the submit form depending on
+ login status.
+ """
+
+ def setUp(self):
+ self.client = Client()
+ domain = mm_client.get_domain('example.com')
+ self.foo_list = domain.create_list('foo')
+
+ def tearDown(self):
+ self.foo_list.delete()
+
+ def test_list_summary_logged_out(self):
+ # Response must contain list obj but not the form.
+ response = self.client.get(reverse('list_summary',
+ args=('foo@example.com', )))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['list'].fqdn_listname,
+ 'foo@example.com')
+ self.assertTrue('
' in response.content)
+ self.assertTrue('
.
+import os
+import time
+import shutil
+import logging
+import tempfile
+import subprocess
+
+from django.conf import settings
+from mailmanclient import Client
+
+
+logger = logging.getLogger(__name__)
+
+
+mm_client = Client('%s/3.0' % settings.MAILMAN_TEST_API_URL,
+ settings.MAILMAN_TEST_USER,
+ settings.MAILMAN_TEST_PASS)
+
+
+class Testobject:
+ bindir = None
+ vardir = None
+ cfgfile = None
+
+
+def setup_mm(testobject):
+ bindir = testobject.bindir = settings.MAILMAN_TEST_BINDIR
+ if bindir is None:
+ raise RuntimeError("something's not quite right")
+ vardir = testobject.vardir = tempfile.mkdtemp()
+ cfgfile = testobject.cfgfile = os.path.join(vardir, 'client_test.cfg')
+ with open(cfgfile, 'w') as fp:
+ print >> fp, """\
+[mailman]
+layout: tmpdir
+[paths.tmpdir]
+var_dir: {vardir}
+log_dir: /tmp/mmclient/logs
+[runner.archive]
+start: no
+[runner.bounces]
+start: no
+[runner.command]
+start: no
+[runner.in]
+start: no
+[runner.lmtp]
+start: no
+[runner.news]
+start: no
+[runner.out]
+start: no
+[runner.pipeline]
+start: no
+[runner.retry]
+start: no
+[runner.virgin]
+start: no
+[runner.digest]
+start: no
+[webservice]
+port: 9001
+""".format(vardir=vardir)
+ mailman = os.path.join(bindir, 'mailman')
+ subprocess.call([mailman, '-C', cfgfile, 'start', '-q'])
+ time.sleep(3)
+ return testobject
+
+
+def teardown_mm(testobject):
+ bindir = testobject.bindir
+ cfgfile = testobject.cfgfile
+ vardir = testobject.vardir
+ mailman = os.path.join(bindir, 'mailman')
+ subprocess.call([mailman, '-C', cfgfile, 'stop', '-q'])
+ shutil.rmtree(vardir)
diff --git a/src/postorius/tests/setup.py b/src/postorius/tests/setup.py
deleted file mode 100644
index ed533f4..0000000
--- a/src/postorius/tests/setup.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 1998-2012 by the Free Software Foundation, Inc.
-#
-# This file is part of Postorius.
-#
-# Postorius is free software: you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option)
-# any later version.
-#
-# Postorius is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# Postorius. If not, see .
-
-import os
-import time
-import shutil
-import tempfile
-import subprocess
-from django.conf import settings
-
-
-class Testobject:
- bindir = None
- vardir = None
- cfgfile = None
-
-
-def setup_mm(testobject):
- os.environ['MAILMAN_TEST_BINDIR'] = settings.MAILMAN_TEST_BINDIR
- bindir = testobject.bindir = os.environ.get('MAILMAN_TEST_BINDIR')
- if bindir is None:
- raise RuntimeError("something's not quite right")
- vardir = testobject.vardir = tempfile.mkdtemp()
- cfgfile = testobject.cfgfile = os.path.join(vardir, 'client_test.cfg')
- with open(cfgfile, 'w') as fp:
- print >> fp, """\
-[mailman]
-layout: tmpdir
-[paths.tmpdir]
-var_dir: {vardir}
-log_dir: /tmp/mmclient/logs
-[runner.archive]
-start: no
-[runner.bounces]
-start: no
-[runner.command]
-start: no
-[runner.in]
-start: no
-[runner.lmtp]
-start: no
-[runner.news]
-start: no
-[runner.out]
-start: no
-[runner.pipeline]
-start: no
-[runner.retry]
-start: no
-[runner.virgin]
-start: no
-[runner.digest]
-start: no
-""".format(vardir=vardir)
- mailman = os.path.join(bindir, 'mailman')
- subprocess.call([mailman, '-C', cfgfile, 'start', '-q'])
- time.sleep(3)
- return testobject
-
-
-def teardown_mm(testobject):
- bindir = testobject.bindir
- cfgfile = testobject.cfgfile
- vardir = testobject.vardir
- mailman = os.path.join(bindir, 'mailman')
- subprocess.call([mailman, '-C', cfgfile, 'stop', '-q'])
- shutil.rmtree(vardir)
- time.sleep(3)
diff --git a/src/postorius/utils.py b/src/postorius/utils.py
index 587f6c4..a423e58 100644
--- a/src/postorius/utils.py
+++ b/src/postorius/utils.py
@@ -15,15 +15,17 @@
#
# You should have received a copy of the GNU General Public License along with
# Postorius. If not, see .
-
+import logging
from django.conf import settings
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
-
from mailmanclient import Client
+logger = logging.getLogger(__name__)
+
+
def get_domain_name(request):
"""Extracts a domain name from the request object.
"""
diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py
index 4c81b27..141d74e 100644
--- a/src/postorius/views/list.py
+++ b/src/postorius/views/list.py
@@ -15,8 +15,9 @@
#
# You should have received a copy of the GNU General Public License along with
# Postorius. If not, see .
+import logging
-
+from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import (login_required,
user_passes_test)
@@ -35,6 +36,9 @@
from postorius.views.generic import MailingListView
+logger = logging.getLogger(__name__)
+
+
class ListMembersView(MailingListView):
"""Display all members of a given list.
"""
@@ -193,6 +197,7 @@
messages.error(request, e)
return redirect('mass_subscribe', self.mailing_list.fqdn_listname)
+
def _get_choosable_domains(request):
try:
domains = Domain.objects.all()
@@ -204,6 +209,7 @@
domain.mail_host))
return choosable_domains
+
@login_required
@user_passes_test(lambda u: u.is_superuser)
def list_new(request, template='postorius/lists/new.html'):
@@ -263,6 +269,7 @@
only_public = False
try:
lists = List.objects.all(only_public=only_public)
+ logger.debug(lists)
except MailmanApiError:
return utils.render_api_error(request)
choosable_domains = _get_choosable_domains(request)