"Fossies" - the Fresh Open Source Software Archive

Member "monasca-events-api-2.0.0/monasca_events_api/tests/unit/test_body_validation.py" (14 Oct 2020, 2340 Bytes) of package /linux/misc/openstack/monasca-events-api-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_body_validation.py": 0.2.0_vs_0.3.0.

    1 # Copyright 2017 FUJITSU LIMITED
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 from falcon.errors import HTTPUnprocessableEntity
   16 
   17 from monasca_events_api.app.controller.v1.body_validation import validate_body
   18 from monasca_events_api.tests.unit import base
   19 
   20 
   21 class TestBodyValidation(base.BaseTestCase):
   22 
   23     def test_missing_events_filed(self):
   24         body = {'timestamp': '2012-10-29T13:42:11Z+0200'}
   25         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   26 
   27     def test_missing_timestamp_field(self):
   28         body = {'events': [{'event': {'payload': 'test'}}]}
   29         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   30 
   31     def test_empty_events_as_list(self):
   32         body = {'events': [], 'timestamp': u'2012-10-29T13:42:11Z+0200'}
   33         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   34 
   35     def test_empty_events_as_dict(self):
   36         body = {'events': {}, 'timestamp': u'2012-10-29T13:42:11Z+0200'}
   37         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   38 
   39     def test_empty_body(self):
   40         body = {}
   41         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   42 
   43     def test_incorrect_timestamp_type(self):
   44         body = {'events': [], 'timestamp': 9000}
   45         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   46 
   47     def test_incorrect_events_type(self):
   48         body = {'events': 'over9000', 'timestamp': '2012-10-29T13:42:11Z+0200'}
   49         self.assertRaises(HTTPUnprocessableEntity, validate_body, body)
   50 
   51     def test_correct_body(self):
   52         body = [{'events': [{'event': {'payload': 'test'}}],
   53                  'timestamp': u'2012-10-29T13:42:11Z+0200'},
   54                 {'events': {'event': {'payload': 'test'}},
   55                  'timestamp': u'2012-10-29T13:42:11Z+0200'}]
   56         for b in body:
   57             validate_body(b)