summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVu Cong Tuan <tuanvc@vn.fujitsu.com>2017-11-07 13:42:36 +0700
committerVu Cong Tuan <tuanvc@vn.fujitsu.com>2017-11-07 14:52:35 +0700
commit8b6260e10f7cfbd204fc9bef9345f332160b1b08 (patch)
tree85a77e899ca47c009897345c9c144e1631022087
parente13f529621c90eec7716053942a904c3190ba59c (diff)
Use assertRegex instead of assertRegexpMatches1.12.0
In Python3, assertRegexpMatches & assertNotRegexpMatches are deprecated in favor of assertRegex and assertNotRegex Change-Id: I52b84fd49bed43902f0a57983710c0fb08649b12
Notes
Notes (review): Code-Review+1: Adrian Czarnecki <adrian.czarnecki@ts.fujitsu.com> Code-Review+2: Joe Keen <joe.keen@hpe.com> Workflow+1: Joe Keen <joe.keen@hpe.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 06 Dec 2017 06:19:11 +0000 Reviewed-on: https://review.openstack.org/518246 Project: openstack/monasca-notification Branch: refs/heads/master
-rw-r--r--tests/test_email_notification.py60
-rw-r--r--tests/test_notification_processor.py10
-rw-r--r--tests/test_pagerduty_notification.py10
-rw-r--r--tests/test_webhook_notification.py14
4 files changed, 46 insertions, 48 deletions
diff --git a/tests/test_email_notification.py b/tests/test_email_notification.py
index c5b1342..6833693 100644
--- a/tests/test_email_notification.py
+++ b/tests/test_email_notification.py
@@ -161,18 +161,17 @@ class TestEmail(base.PluginTestCase):
161 161
162 email = _parse_email(self.trap.pop(0)) 162 email = _parse_email(self.trap.pop(0))
163 163
164 self.assertRegexpMatches(email['from'], 'hpcs.mon@hp.com') 164 self.assertRegex(email['from'], 'hpcs.mon@hp.com')
165 self.assertRegexpMatches(email['to'], 'me@here.com') 165 self.assertRegex(email['to'], 'me@here.com')
166 self.assertRegexpMatches(email['raw'], 'Content-Type: text/plain') 166 self.assertRegex(email['raw'], 'Content-Type: text/plain')
167 self.assertRegexpMatches(email['raw'], 167 self.assertRegex(email['raw'], 'Content-Transfer-Encoding: base64')
168 'Content-Transfer-Encoding: base64') 168 self.assertRegex(email['subject'],
169 self.assertRegexpMatches(email['subject'], 169 'ALARM LOW "test Alarm .*" for Host: foo1.*')
170 'ALARM LOW "test Alarm .*" for Host: foo1.*') 170 self.assertRegex(email['body'], 'Alarm .test Alarm.')
171 self.assertRegexpMatches(email['body'], 'Alarm .test Alarm.') 171 self.assertRegex(email['body'], 'On host .foo1.')
172 self.assertRegexpMatches(email['body'], 'On host .foo1.') 172 self.assertRegex(email['body'], UNICODE_CHAR)
173 self.assertRegexpMatches(email['body'], UNICODE_CHAR) 173 self.assertRegex(email['body'], 'Link: some-link')
174 self.assertRegexpMatches(email['body'], 'Link: some-link') 174 self.assertRegex(email['body'], 'Lifecycle state: OPEN')
175 self.assertRegexpMatches(email['body'], 'Lifecycle state: OPEN')
176 175
177 return_value = self.trap.pop(0) 176 return_value = self.trap.pop(0)
178 self.assertTrue(return_value) 177 self.assertTrue(return_value)
@@ -191,16 +190,15 @@ class TestEmail(base.PluginTestCase):
191 190
192 email = _parse_email(self.trap.pop(0)) 191 email = _parse_email(self.trap.pop(0))
193 192
194 self.assertRegexpMatches(email['from'], 'hpcs.mon@hp.com') 193 self.assertRegex(email['from'], 'hpcs.mon@hp.com')
195 self.assertRegexpMatches(email['to'], 'me@here.com') 194 self.assertRegex(email['to'], 'me@here.com')
196 self.assertRegexpMatches(email['raw'], 'Content-Type: text/plain') 195 self.assertRegex(email['raw'], 'Content-Type: text/plain')
197 self.assertRegexpMatches(email['raw'], 196 self.assertRegex(email['raw'], 'Content-Transfer-Encoding: base64')
198 'Content-Transfer-Encoding: base64') 197 self.assertRegex(email['subject'],
199 self.assertRegexpMatches(email['subject'], 198 'ALARM LOW .test Alarm.* Target: some_where')
200 'ALARM LOW .test Alarm.* Target: some_where') 199 self.assertRegex(email['body'], "Alarm .test Alarm.")
201 self.assertRegexpMatches(email['body'], "Alarm .test Alarm.") 200 self.assertRegex(email['body'], "On host .foo1.")
202 self.assertRegexpMatches(email['body'], "On host .foo1.") 201 self.assertRegex(email['body'], UNICODE_CHAR)
203 self.assertRegexpMatches(email['body'], UNICODE_CHAR)
204 202
205 return_value = self.trap.pop(0) 203 return_value = self.trap.pop(0)
206 self.assertTrue(return_value) 204 self.assertTrue(return_value)
@@ -219,15 +217,15 @@ class TestEmail(base.PluginTestCase):
219 217
220 email = _parse_email(self.trap.pop(0)) 218 email = _parse_email(self.trap.pop(0))
221 219
222 self.assertRegexpMatches(email['from'], "From: hpcs.mon@hp.com") 220 self.assertRegex(email['from'], "From: hpcs.mon@hp.com")
223 self.assertRegexpMatches(email['to'], "To: me@here.com") 221 self.assertRegex(email['to'], "To: me@here.com")
224 self.assertRegexpMatches(email['raw'], "Content-Type: text/plain") 222 self.assertRegex(email['raw'], "Content-Type: text/plain")
225 self.assertRegexpMatches(email['subject'], "Subject: ALARM LOW .test Alarm.") 223 self.assertRegex(email['subject'], "Subject: ALARM LOW .test Alarm.")
226 self.assertRegexpMatches(email['body'], "Alarm .test Alarm.") 224 self.assertRegex(email['body'], "Alarm .test Alarm.")
227 self.assertRegexpMatches(email['body'], "foo1") 225 self.assertRegex(email['body'], "foo1")
228 self.assertRegexpMatches(email['body'], "foo2") 226 self.assertRegex(email['body'], "foo2")
229 self.assertRegexpMatches(email['body'], "bar1") 227 self.assertRegex(email['body'], "bar1")
230 self.assertRegexpMatches(email['body'], "bar2") 228 self.assertRegex(email['body'], "bar2")
231 229
232 return_value = self.trap.pop(0) 230 return_value = self.trap.pop(0)
233 self.assertTrue(return_value) 231 self.assertTrue(return_value)
diff --git a/tests/test_notification_processor.py b/tests/test_notification_processor.py
index 605a949..92fd009 100644
--- a/tests/test_notification_processor.py
+++ b/tests/test_notification_processor.py
@@ -126,8 +126,8 @@ class TestNotificationProcessor(base.BaseTestCase):
126 126
127 for msg in self.trap: 127 for msg in self.trap:
128 if "From: hpcs.mon@hp.com" in msg: 128 if "From: hpcs.mon@hp.com" in msg:
129 self.assertRegexpMatches(msg, "From: hpcs.mon@hp.com") 129 self.assertRegex(msg, "From: hpcs.mon@hp.com")
130 self.assertRegexpMatches(msg, "To: me@here.com") 130 self.assertRegex(msg, "To: me@here.com")
131 self.assertRegexpMatches(msg, "Content-Type: text/plain") 131 self.assertRegex(msg, "Content-Type: text/plain")
132 self.assertRegexpMatches(msg, "Alarm .test Alarm.") 132 self.assertRegex(msg, "Alarm .test Alarm.")
133 self.assertRegexpMatches(msg, "On host .foo1.") 133 self.assertRegex(msg, "On host .foo1.")
diff --git a/tests/test_pagerduty_notification.py b/tests/test_pagerduty_notification.py
index cd1f126..987e3fb 100644
--- a/tests/test_pagerduty_notification.py
+++ b/tests/test_pagerduty_notification.py
@@ -134,9 +134,9 @@ class TestPagerduty(base.PluginTestCase):
134 self.assertEqual(details['message'], 'I am alarming!') 134 self.assertEqual(details['message'], 'I am alarming!')
135 135
136 def pagerduty_http_error(self, log_msg, http_response): 136 def pagerduty_http_error(self, log_msg, http_response):
137 self.assertRegexpMatches(log_msg, "Error with pagerduty request.") 137 self.assertRegex(log_msg, "Error with pagerduty request.")
138 self.assertRegexpMatches(log_msg, "key=<ABCDEF>") 138 self.assertRegex(log_msg, "key=<ABCDEF>")
139 self.assertRegexpMatches(log_msg, "response=%s" % http_response) 139 self.assertRegex(log_msg, "response=%s" % http_response)
140 140
141 @mock.patch('monasca_notification.plugins.pagerduty_notifier.requests') 141 @mock.patch('monasca_notification.plugins.pagerduty_notifier.requests')
142 def notify(self, http_func, mock_requests): 142 def notify(self, http_func, mock_requests):
@@ -277,8 +277,8 @@ class TestPagerduty(base.PluginTestCase):
277 277
278 results = self.trap.get(timeout=1) 278 results = self.trap.get(timeout=1)
279 279
280 self.assertRegexpMatches(results, "Exception on pagerduty request") 280 self.assertRegex(results, "Exception on pagerduty request")
281 self.assertRegexpMatches(results, "key=<ABCDEF>") 281 self.assertRegex(results, "key=<ABCDEF>")
282 282
283 return_value = self.trap.get() 283 return_value = self.trap.get()
284 self.assertFalse(return_value) 284 self.assertFalse(return_value)
diff --git a/tests/test_webhook_notification.py b/tests/test_webhook_notification.py
index f9effc7..cd386d1 100644
--- a/tests/test_webhook_notification.py
+++ b/tests/test_webhook_notification.py
@@ -128,11 +128,11 @@ class TestWebhook(base.PluginTestCase):
128 128
129 error = self.trap.get() 129 error = self.trap.get()
130 130
131 self.assertNotRegexpMatches(error, "alarm_id.: .test Alarm") 131 self.assertNotRegex(error, "alarm_id.: .test Alarm")
132 self.assertNotRegexpMatches(error, "content-type.: .application/json") 132 self.assertNotRegex(error, "content-type.: .application/json")
133 133
134 self.assertRegexpMatches(error, "HTTP code 404") 134 self.assertRegex(error, "HTTP code 404")
135 self.assertRegexpMatches(error, "post on URL http://mock:3333/") 135 self.assertRegex(error, "post on URL http://mock:3333/")
136 136
137 return_value = self.trap.get() 137 return_value = self.trap.get()
138 self.assertFalse(return_value) 138 self.assertFalse(return_value)
@@ -150,10 +150,10 @@ class TestWebhook(base.PluginTestCase):
150 150
151 result = self.trap.get() 151 result = self.trap.get()
152 152
153 self.assertNotRegexpMatches(result, "alarm_id.: .test Alarm") 153 self.assertNotRegex(result, "alarm_id.: .test Alarm")
154 self.assertNotRegexpMatches(result, "content-type.: .application/json") 154 self.assertNotRegex(result, "content-type.: .application/json")
155 155
156 self.assertRegexpMatches(result, "Error trying to post on URL http://mock:3333/") 156 self.assertRegex(result, "Error trying to post on URL http://mock:3333/")
157 157
158 return_value = self.trap.get() 158 return_value = self.trap.get()
159 self.assertFalse(return_value) 159 self.assertFalse(return_value)