Browse Source

Use assertRegex instead of assertRegexpMatches

In Python3, assertRegexpMatches & assertNotRegexpMatches
are deprecated in favor of assertRegex and assertNotRegex

Change-Id: I52b84fd49bed43902f0a57983710c0fb08649b12
Vu Cong Tuan 1 year ago
parent
commit
8b6260e10f

+ 29
- 31
tests/test_email_notification.py View File

@@ -161,18 +161,17 @@ class TestEmail(base.PluginTestCase):
161 161
 
162 162
         email = _parse_email(self.trap.pop(0))
163 163
 
164
-        self.assertRegexpMatches(email['from'], 'hpcs.mon@hp.com')
165
-        self.assertRegexpMatches(email['to'], 'me@here.com')
166
-        self.assertRegexpMatches(email['raw'], 'Content-Type: text/plain')
167
-        self.assertRegexpMatches(email['raw'],
168
-                                 'Content-Transfer-Encoding: base64')
169
-        self.assertRegexpMatches(email['subject'],
170
-                                 'ALARM LOW "test Alarm .*" for Host: foo1.*')
171
-        self.assertRegexpMatches(email['body'], 'Alarm .test Alarm.')
172
-        self.assertRegexpMatches(email['body'], 'On host .foo1.')
173
-        self.assertRegexpMatches(email['body'], UNICODE_CHAR)
174
-        self.assertRegexpMatches(email['body'], 'Link: some-link')
175
-        self.assertRegexpMatches(email['body'], 'Lifecycle state: OPEN')
164
+        self.assertRegex(email['from'], 'hpcs.mon@hp.com')
165
+        self.assertRegex(email['to'], 'me@here.com')
166
+        self.assertRegex(email['raw'], 'Content-Type: text/plain')
167
+        self.assertRegex(email['raw'], 'Content-Transfer-Encoding: base64')
168
+        self.assertRegex(email['subject'],
169
+                         'ALARM LOW "test Alarm .*" for Host: foo1.*')
170
+        self.assertRegex(email['body'], 'Alarm .test Alarm.')
171
+        self.assertRegex(email['body'], 'On host .foo1.')
172
+        self.assertRegex(email['body'], UNICODE_CHAR)
173
+        self.assertRegex(email['body'], 'Link: some-link')
174
+        self.assertRegex(email['body'], 'Lifecycle state: OPEN')
176 175
 
177 176
         return_value = self.trap.pop(0)
178 177
         self.assertTrue(return_value)
@@ -191,16 +190,15 @@ class TestEmail(base.PluginTestCase):
191 190
 
192 191
         email = _parse_email(self.trap.pop(0))
193 192
 
194
-        self.assertRegexpMatches(email['from'], 'hpcs.mon@hp.com')
195
-        self.assertRegexpMatches(email['to'], 'me@here.com')
196
-        self.assertRegexpMatches(email['raw'], 'Content-Type: text/plain')
197
-        self.assertRegexpMatches(email['raw'],
198
-                                 'Content-Transfer-Encoding: base64')
199
-        self.assertRegexpMatches(email['subject'],
200
-                                 'ALARM LOW .test Alarm.* Target: some_where')
201
-        self.assertRegexpMatches(email['body'], "Alarm .test Alarm.")
202
-        self.assertRegexpMatches(email['body'], "On host .foo1.")
203
-        self.assertRegexpMatches(email['body'], UNICODE_CHAR)
193
+        self.assertRegex(email['from'], 'hpcs.mon@hp.com')
194
+        self.assertRegex(email['to'], 'me@here.com')
195
+        self.assertRegex(email['raw'], 'Content-Type: text/plain')
196
+        self.assertRegex(email['raw'], 'Content-Transfer-Encoding: base64')
197
+        self.assertRegex(email['subject'],
198
+                         'ALARM LOW .test Alarm.* Target: some_where')
199
+        self.assertRegex(email['body'], "Alarm .test Alarm.")
200
+        self.assertRegex(email['body'], "On host .foo1.")
201
+        self.assertRegex(email['body'], UNICODE_CHAR)
204 202
 
205 203
         return_value = self.trap.pop(0)
206 204
         self.assertTrue(return_value)
@@ -219,15 +217,15 @@ class TestEmail(base.PluginTestCase):
219 217
 
220 218
         email = _parse_email(self.trap.pop(0))
221 219
 
222
-        self.assertRegexpMatches(email['from'], "From: hpcs.mon@hp.com")
223
-        self.assertRegexpMatches(email['to'], "To: me@here.com")
224
-        self.assertRegexpMatches(email['raw'], "Content-Type: text/plain")
225
-        self.assertRegexpMatches(email['subject'], "Subject: ALARM LOW .test Alarm.")
226
-        self.assertRegexpMatches(email['body'], "Alarm .test Alarm.")
227
-        self.assertRegexpMatches(email['body'], "foo1")
228
-        self.assertRegexpMatches(email['body'], "foo2")
229
-        self.assertRegexpMatches(email['body'], "bar1")
230
-        self.assertRegexpMatches(email['body'], "bar2")
220
+        self.assertRegex(email['from'], "From: hpcs.mon@hp.com")
221
+        self.assertRegex(email['to'], "To: me@here.com")
222
+        self.assertRegex(email['raw'], "Content-Type: text/plain")
223
+        self.assertRegex(email['subject'], "Subject: ALARM LOW .test Alarm.")
224
+        self.assertRegex(email['body'], "Alarm .test Alarm.")
225
+        self.assertRegex(email['body'], "foo1")
226
+        self.assertRegex(email['body'], "foo2")
227
+        self.assertRegex(email['body'], "bar1")
228
+        self.assertRegex(email['body'], "bar2")
231 229
 
232 230
         return_value = self.trap.pop(0)
233 231
         self.assertTrue(return_value)

+ 5
- 5
tests/test_notification_processor.py View File

@@ -126,8 +126,8 @@ class TestNotificationProcessor(base.BaseTestCase):
126 126
 
127 127
         for msg in self.trap:
128 128
             if "From: hpcs.mon@hp.com" in msg:
129
-                self.assertRegexpMatches(msg, "From: hpcs.mon@hp.com")
130
-                self.assertRegexpMatches(msg, "To: me@here.com")
131
-                self.assertRegexpMatches(msg, "Content-Type: text/plain")
132
-                self.assertRegexpMatches(msg, "Alarm .test Alarm.")
133
-                self.assertRegexpMatches(msg, "On host .foo1.")
129
+                self.assertRegex(msg, "From: hpcs.mon@hp.com")
130
+                self.assertRegex(msg, "To: me@here.com")
131
+                self.assertRegex(msg, "Content-Type: text/plain")
132
+                self.assertRegex(msg, "Alarm .test Alarm.")
133
+                self.assertRegex(msg, "On host .foo1.")

+ 5
- 5
tests/test_pagerduty_notification.py View File

@@ -134,9 +134,9 @@ class TestPagerduty(base.PluginTestCase):
134 134
         self.assertEqual(details['message'], 'I am alarming!')
135 135
 
136 136
     def pagerduty_http_error(self, log_msg, http_response):
137
-        self.assertRegexpMatches(log_msg, "Error with pagerduty request.")
138
-        self.assertRegexpMatches(log_msg, "key=<ABCDEF>")
139
-        self.assertRegexpMatches(log_msg, "response=%s" % http_response)
137
+        self.assertRegex(log_msg, "Error with pagerduty request.")
138
+        self.assertRegex(log_msg, "key=<ABCDEF>")
139
+        self.assertRegex(log_msg, "response=%s" % http_response)
140 140
 
141 141
     @mock.patch('monasca_notification.plugins.pagerduty_notifier.requests')
142 142
     def notify(self, http_func, mock_requests):
@@ -277,8 +277,8 @@ class TestPagerduty(base.PluginTestCase):
277 277
 
278 278
         results = self.trap.get(timeout=1)
279 279
 
280
-        self.assertRegexpMatches(results, "Exception on pagerduty request")
281
-        self.assertRegexpMatches(results, "key=<ABCDEF>")
280
+        self.assertRegex(results, "Exception on pagerduty request")
281
+        self.assertRegex(results, "key=<ABCDEF>")
282 282
 
283 283
         return_value = self.trap.get()
284 284
         self.assertFalse(return_value)

+ 7
- 7
tests/test_webhook_notification.py View File

@@ -128,11 +128,11 @@ class TestWebhook(base.PluginTestCase):
128 128
 
129 129
         error = self.trap.get()
130 130
 
131
-        self.assertNotRegexpMatches(error, "alarm_id.: .test Alarm")
132
-        self.assertNotRegexpMatches(error, "content-type.: .application/json")
131
+        self.assertNotRegex(error, "alarm_id.: .test Alarm")
132
+        self.assertNotRegex(error, "content-type.: .application/json")
133 133
 
134
-        self.assertRegexpMatches(error, "HTTP code 404")
135
-        self.assertRegexpMatches(error, "post on URL http://mock:3333/")
134
+        self.assertRegex(error, "HTTP code 404")
135
+        self.assertRegex(error, "post on URL http://mock:3333/")
136 136
 
137 137
         return_value = self.trap.get()
138 138
         self.assertFalse(return_value)
@@ -150,10 +150,10 @@ class TestWebhook(base.PluginTestCase):
150 150
 
151 151
         result = self.trap.get()
152 152
 
153
-        self.assertNotRegexpMatches(result, "alarm_id.: .test Alarm")
154
-        self.assertNotRegexpMatches(result, "content-type.: .application/json")
153
+        self.assertNotRegex(result, "alarm_id.: .test Alarm")
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 158
         return_value = self.trap.get()
159 159
         self.assertFalse(return_value)

Loading…
Cancel
Save