[Mailman-checkins] [Git][mailman/mailman][coverage] Boost coverage.

2017-07-24 Thread Barry Warsaw via Mailman-checkins
Barry Warsaw pushed to branch coverage at mailman / Mailman Core


Commits:
8fbcf37a by Barry Warsaw at 2017-07-24T19:54:48-04:00
Boost coverage.

- - - - -


2 changed files:

- src/mailman/rest/listconf.py
- src/mailman/rest/preferences.py


Changes:

=
src/mailman/rest/listconf.py
=
--- a/src/mailman/rest/listconf.py
+++ b/src/mailman/rest/listconf.py
@@ -97,7 +97,7 @@ def pipeline_validator(pipeline_name):
 
 
 def password_bytes_validator(value):
-if value is None or isinstance(value, bytes):
+if value is None or isinstance(value, bytes):   # pragma: nobranch
 return value
 return config.password_context.encrypt(value).encode('utf-8')
 
@@ -196,7 +196,7 @@ def api_attributes(api):
 # attributes, although we map them to templates.  In API 3.1 and beyond,
 # only the template manager API can be used for these.
 attributes = ATTRIBUTES.copy()
-if api.version_info == (3, 0):
+if api.version_info == (3, 0):  # pragma: nobranch
 attributes.update({
 attribute: URIAttributeMapper(str)
 for attribute in TEMPLATE_ATTRIBUTES
@@ -243,7 +243,7 @@ class ListConfiguration:
 # handled by the template manager API.
 validators = VALIDATORS.copy()
 attributes = api_attributes(self.api)
-if self.api.version_info == (3, 0):
+if self.api.version_info == (3, 0): # pragma: nobranch
 validators.update({
 attribute: URIAttributeMapper(str)
 for attribute in TEMPLATE_ATTRIBUTES


=
src/mailman/rest/preferences.py
=
--- a/src/mailman/rest/preferences.py
+++ b/src/mailman/rest/preferences.py
@@ -69,9 +69,7 @@ class Preferences(ReadOnlyPreferences):
 """Preferences which can be changed."""
 
 def _patch_put(self, request, response, is_optional):
-if self._parent is None:
-not_found(response)
-return
+assert self._parent is not None
 kws = dict(
 acknowledge_posts=GetterSetter(as_boolean),
 hide_address=GetterSetter(as_boolean),



View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/8fbcf37a3d9837799f3bb18e5e4395caf60bf44f

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/8fbcf37a3d9837799f3bb18e5e4395caf60bf44f
You're receiving this email because of your account on gitlab.com.
___
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org



[Mailman-checkins] [Git][mailman/mailman][coverage] Boost coverage.

2017-07-24 Thread Barry Warsaw via Mailman-checkins
Barry Warsaw pushed to branch coverage at mailman / Mailman Core


Commits:
f9cfbb32 by Barry Warsaw at 2017-07-24T14:44:41-04:00
Boost coverage.

- - - - -


1 changed file:

- src/mailman/rest/tests/test_header_matches.py


Changes:

=
src/mailman/rest/tests/test_header_matches.py
=
--- a/src/mailman/rest/tests/test_header_matches.py
+++ b/src/mailman/rest/tests/test_header_matches.py
@@ -51,6 +51,17 @@ class TestHeaderMatches(unittest.TestCase):
 self.assertEqual(cm.exception.reason,
  'No header match at this position: 0')
 
+def test_patch_put_missing_header_match(self):
+with self.assertRaises(HTTPError) as cm:
+call_api('http://localhost:9001/3.0/lists/ant.example.com'
+ '/header-matches/0', dict(
+ header='From',
+ ),
+ method='PATCH')
+self.assertEqual(cm.exception.code, 404)
+self.assertEqual(cm.exception.reason,
+ 'No header match at this position: 0')
+
 def test_add_duplicate(self):
 header_matches = IHeaderMatchList(self._mlist)
 with transaction():
@@ -70,3 +81,30 @@ class TestHeaderMatches(unittest.TestCase):
 call_api('http://localhost:9001/3.0/lists/bee.example.com'
  '/header-matches/')
 self.assertEqual(cm.exception.code, 404)
+
+def test_header_match_post_bad_action(self):
+header_matches = IHeaderMatchList(self._mlist)
+with transaction():
+header_matches.append('header', 'pattern')
+with self.assertRaises(HTTPError) as cm:
+call_api('http://localhost:9001/3.0/lists/ant.example.com'
+ '/header-matches', {
+ 'action': 'donothing',
+})
+self.assertEqual(cm.exception.code, 400)
+self.assertEqual(cm.exception.reason,
+ 'Cannot convert parameters: action')
+
+def test_header_match_patch_bad_action(self):
+header_matches = IHeaderMatchList(self._mlist)
+with transaction():
+header_matches.append('header', 'pattern')
+with self.assertRaises(HTTPError) as cm:
+call_api('http://localhost:9001/3.0/lists/ant.example.com'
+ '/header-matches/0', {
+ 'action': 'donothing',
+},
+ method='PATCH')
+self.assertEqual(cm.exception.code, 400)
+self.assertEqual(cm.exception.reason,
+ 'Cannot convert parameters: action')



View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/f9cfbb32144d328aa5a662fb192153616f0cbbf7

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/f9cfbb32144d328aa5a662fb192153616f0cbbf7
You're receiving this email because of your account on gitlab.com.
___
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org



[Mailman-checkins] [Git][mailman/mailman][coverage] Boost coverage and modernize.

2017-07-23 Thread Barry Warsaw via Mailman-checkins
Barry Warsaw pushed to branch coverage at mailman / Mailman Core


Commits:
bf2897a6 by Barry Warsaw at 2017-07-23T08:42:25-05:00
Boost coverage and modernize.

- - - - -


3 changed files:

- src/mailman/rules/docs/suspicious.rst
- src/mailman/rules/suspicious.py
- src/mailman/rules/tests/test_suspicious.py


Changes:

=
src/mailman/rules/docs/suspicious.rst
=
--- a/src/mailman/rules/docs/suspicious.rst
+++ b/src/mailman/rules/docs/suspicious.rst
@@ -6,7 +6,7 @@ Suspicious headers are a way for Mailman to hold messages that 
match a
 particular regular expression.  This mostly historical feature is fairly
 confusing to users, and the list attribute that controls this is misnamed.
 
->>> mlist = create_list('_xt...@example.com')
+>>> mlist = create_list('a...@example.com')
 >>> rule = config.rules['suspicious-header']
 >>> print(rule.name)
 suspicious-header
@@ -16,9 +16,9 @@ Set the so-called suspicious header configuration variable.
 >>> mlist.bounce_matching_headers = 'From: .*person@(blah.)?example.com'
 >>> msg = message_from_string("""\
 ... From: aper...@example.com
-... To: _xt...@example.com
+... To: a...@example.com
 ... Subject: An implicit message
-... 
+...
 ... """)
 >>> rule.check(mlist, msg, {})
 True
@@ -28,9 +28,9 @@ This one comes from a ``.org`` address.
 
 >>> msg = message_from_string("""\
 ... From: aper...@example.org
-... To: _xt...@example.com
+... To: a...@example.com
 ... Subject: An implicit message
-... 
+...
 ... """)
 >>> rule.check(mlist, msg, {})
 False


=
src/mailman/rules/suspicious.py
=
--- a/src/mailman/rules/suspicious.py
+++ b/src/mailman/rules/suspicious.py
@@ -60,7 +60,7 @@ def _parse_matching_header_opt(mlist):
 # This didn't look like a header line.  BAW: should do a
 # better job of informing the list admin.
 log.error('bad bounce_matching_header line: %s\n%s',
-  mlist.display_name, line)
+  mlist.list_id, line)
 else:
 header = line[:i]
 value = line[i+1:].lstrip()
@@ -71,7 +71,7 @@ def _parse_matching_header_opt(mlist):
 # job of informing the list admin.
 log.error("""\
 bad regexp in bounce_matching_header line: %s
-\n%s (cause: %s)""", mlist.display_name, value, error)
+"%s" (cause: %s)""", mlist.list_id, value, error)
 else:
 all.append((header, cre, line))
 return all


=
src/mailman/rules/tests/test_suspicious.py
=
--- a/src/mailman/rules/tests/test_suspicious.py
+++ b/src/mailman/rules/tests/test_suspicious.py
@@ -24,17 +24,24 @@ from email.header import Header
 from mailman.app.lifecycle import create_list
 from mailman.email.message import Message
 from mailman.rules import suspicious
+from mailman.testing.helpers import (
+LogFileMark, specialized_message_from_string as mfs)
 from mailman.testing.layers import ConfigLayer
 
 
 class TestSuspicious(unittest.TestCase):
-"""Test the suspicious rule."""
-
 layer = ConfigLayer
+maxDiff = None
 
 def setUp(self):
-self._mlist = create_list('t...@example.com')
+self._mlist = create_list('a...@example.com')
 self._rule = suspicious.SuspiciousHeader()
+self._msg = mfs("""\
+From: aper...@example.com
+To: a...@example.com
+Subject: A message
+
+""")
 
 def test_header_instance(self):
 msg = Message()
@@ -42,3 +49,29 @@ class TestSuspicious(unittest.TestCase):
 self._mlist.bounce_matching_headers = 'from: s...@example.com'
 result = self._rule.check(self._mlist, msg, {})
 self.assertFalse(result)
+
+def test_bounce_matching_header_not_a_header(self):
+mark = LogFileMark('mailman.error')
+self._mlist.bounce_matching_headers = 'This is not a header'
+result = self._rule.check(self._mlist, self._msg, {})
+self.assertFalse(result)
+log_lines = mark.read().splitlines()
+self.assertEqual(
+log_lines[0][-48:],
+'bad bounce_matching_header line: ant.example.com')
+self.assertEqual(
+log_lines[1][-20:],
+'This is not a header')
+
+def test_bounce_matching_header_not_a_regexp(self):
+mark = LogFileMark('mailman.error')
+self._mlist.bounce_matching_headers = 'From: [a-z'
+result = self._rule.check(self._mlist, self._msg, {})
+self.assertFalse(result)
+log_lines = mark.read().splitlines()
+self.assertEqual(
+log_lines[0][-58:],
+'bad regexp in bounce_matching_header line: ant.example.com')
+self.assertEqual(
+log_lines[1][-56:],
+'"[a-z"