"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "monasca_api/tests/test_validation.py" between
monasca-api-3.1.0.tar.gz and monasca-api-4.0.0.tar.gz

About: OpenStack Monasca API is a RESTful API server that is designed with a layered architecture and supports Monitoring as a Service (MONaaS).
The "Ussuri" series (latest release).

test_validation.py  (monasca-api-3.1.0):test_validation.py  (monasca-api-4.0.0)
skipping to change at line 18 skipping to change at line 18
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import falcon import falcon
import mock from unittest import mock
from monasca_api.tests import base from monasca_api.tests import base
import monasca_api.v2.common.exceptions as common_exceptions import monasca_api.v2.common.exceptions as common_exceptions
import monasca_api.v2.common.schemas.alarm_definition_request_body_schema as sch emas_alarm_defs import monasca_api.v2.common.schemas.alarm_definition_request_body_schema as sch emas_alarm_defs
import monasca_api.v2.common.schemas.exceptions as schemas_exceptions import monasca_api.v2.common.schemas.exceptions as schemas_exceptions
import monasca_api.v2.common.schemas.notifications_request_body_schema as schema s_notifications import monasca_api.v2.common.schemas.notifications_request_body_schema as schema s_notifications
import monasca_api.v2.common.validation as validation import monasca_api.v2.common.validation as validation
import monasca_api.v2.reference.helpers as helpers import monasca_api.v2.reference.helpers as helpers
def mock_req_can(authorised_rule): def mock_req_can(authorised_rule):
skipping to change at line 101 skipping to change at line 101
def test_valid_timestamps(self): def test_valid_timestamps(self):
start_time = '2015-01-01T00:00:00Z' start_time = '2015-01-01T00:00:00Z'
end_time = '2015-01-01T00:00:01Z' end_time = '2015-01-01T00:00:01Z'
start_timestamp = helpers._convert_time_string(start_time) start_timestamp = helpers._convert_time_string(start_time)
end_timestamp = helpers._convert_time_string(end_time) end_timestamp = helpers._convert_time_string(end_time)
try: try:
helpers.validate_start_end_timestamps(start_timestamp, helpers.validate_start_end_timestamps(start_timestamp,
end_timestamp) end_timestamp)
except: except Exception:
self.fail("shouldn't happen") self.fail("shouldn't happen")
def test_same_timestamps(self): def test_same_timestamps(self):
start_time = '2015-01-01T00:00:00Z' start_time = '2015-01-01T00:00:00Z'
end_time = start_time end_time = start_time
start_timestamp = helpers._convert_time_string(start_time) start_timestamp = helpers._convert_time_string(start_time)
end_timestamp = helpers._convert_time_string(end_time) end_timestamp = helpers._convert_time_string(end_time)
self.assertRaises( self.assertRaises(
falcon.HTTPBadRequest, falcon.HTTPBadRequest,
skipping to change at line 171 skipping to change at line 171
except schemas_exceptions.ValidationException: except schemas_exceptions.ValidationException:
self.fail("shouldn't happen") self.fail("shouldn't happen")
def test_validation_exception_for_invalid_email_address(self): def test_validation_exception_for_invalid_email_address(self):
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"} notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"}
ex = self.assertRaises(schemas_exceptions.ValidationException, ex = self.assertRaises(schemas_exceptions.ValidationException,
schemas_notifications.parse_and_validate, schemas_notifications.parse_and_validate,
notification, valid_periods) notification, valid_periods)
self.assertEqual("Address name@ is not of correct format", str(ex)) self.assertEqual("Address name@ is not of correct format", str(ex))
def test_validation_exception_for_invalid_period_for_email(self): def test_validation_for_email_non_zero_period(self):
notification = { notification = {
"name": "MyEmail", "name": "MyEmail",
"type": "EMAIL", "type": "EMAIL",
"address": "name@domain.com", "address": "name@domain.com",
"period": "60"} "period": "60"}
ex = self.assertRaises(schemas_exceptions.ValidationException, try:
schemas_notifications.parse_and_validate, schemas_notifications.parse_and_validate(notification, valid_periods
notification, valid_periods) )
self.assertEqual("Period can only be set with webhooks", str(ex)) except schemas_exceptions.ValidationException:
self.fail("shouldn't happen")
def test_validation_for_webhook(self): def test_validation_for_webhook(self):
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http ://somedomain.com"} notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http ://somedomain.com"}
try: try:
schemas_notifications.parse_and_validate(notification, valid_periods ) schemas_notifications.parse_and_validate(notification, valid_periods )
except schemas_exceptions.ValidationException: except schemas_exceptions.ValidationException:
self.fail("shouldn't happen") self.fail("shouldn't happen")
def test_validation_for_webhook_non_zero_period(self): def test_validation_for_webhook_non_zero_period(self):
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http ://somedomain.com", notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http ://somedomain.com",
skipping to change at line 224 skipping to change at line 224
schemas_notifications.parse_and_validate, schemas_notifications.parse_and_validate,
notification, valid_periods) notification, valid_periods)
self.assertEqual("Address ftp://somedomain.com scheme is not in ['http', 'https']", str(ex)) self.assertEqual("Address ftp://somedomain.com scheme is not in ['http', 'https']", str(ex))
def test_validation_exception_for_webhook_invalid_period(self): def test_validation_exception_for_webhook_invalid_period(self):
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//so medomain.com", notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//so medomain.com",
"period": "10"} "period": "10"}
ex = self.assertRaises(schemas_exceptions.ValidationException, ex = self.assertRaises(schemas_exceptions.ValidationException,
schemas_notifications.parse_and_validate, schemas_notifications.parse_and_validate,
notification, valid_periods) notification, valid_periods)
self.assertEqual("10 is not a valid period, not in [0, 60]", str(ex)) self.assertEqual("10 is not in the configured list of valid periods: [0, 60]", str(ex))
def test_validation_for_pagerduty(self): def test_validation_for_pagerduty(self):
notification = {"name": "MyPagerduty", "type": "PAGERDUTY", notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
"address": "nzH2LVRdMzun11HNC2oD"} "address": "nzH2LVRdMzun11HNC2oD"}
try: try:
schemas_notifications.parse_and_validate(notification, valid_periods ) schemas_notifications.parse_and_validate(notification, valid_periods )
except schemas_exceptions.ValidationException: except schemas_exceptions.ValidationException:
self.fail("shouldn't happen") self.fail("shouldn't happen")
def test_validation_exception_for_invalid_period_for_pagerduty(self): def test_validation_for_pagerduty_non_zero_period(self):
notification = {"name": "MyPagerduty", "type": "PAGERDUTY", notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
"address": "nzH2LVRdMzun11HNC2oD", "period": 60} "address": "nzH2LVRdMzun11HNC2oD", "period": 60}
ex = self.assertRaises(schemas_exceptions.ValidationException, try:
schemas_notifications.parse_and_validate, schemas_notifications.parse_and_validate(notification, valid_periods
notification, valid_periods) )
self.assertEqual("Period can only be set with webhooks", str(ex)) except schemas_exceptions.ValidationException:
self.fail("shouldn't happen")
def test_validation_for_max_name_address(self): def test_validation_for_max_name_address(self):
name = "A" * 250 name = "A" * 250
self.assertEqual(250, len(name)) self.assertEqual(250, len(name))
address = "http://" + "A" * 502 + ".io" address = "http://" + "A" * 502 + ".io"
self.assertEqual(512, len(address)) self.assertEqual(512, len(address))
notification = {"name": name, "type": "WEBHOOK", "address": address} notification = {"name": name, "type": "WEBHOOK", "address": address}
try: try:
schemas_notifications.parse_and_validate(notification, valid_periods ) schemas_notifications.parse_and_validate(notification, valid_periods )
except schemas_exceptions.ValidationException: except schemas_exceptions.ValidationException:
 End of changes. 7 change blocks. 
13 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)