"Fossies" - the Fresh Open Source Software Archive

Member "monasca-api-3.1.0/monasca_api/tests/test_versions.py" (27 Sep 2019, 2659 Bytes) of package /linux/misc/openstack/monasca-api-3.1.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 latest Fossies "Diffs" side-by-side code changes report for "test_versions.py": 3.0.0_vs_3.1.0.

    1 # Copyright 2015 Hewlett-Packard
    2 # Copyright 2017 Fujitsu LIMITED
    3 #
    4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 # not use this file except in compliance with the License. You may obtain
    6 # a copy of the License at
    7 #
    8 # http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 # Unless required by applicable law or agreed to in writing, software
   11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 # License for the specific language governing permissions and limitations
   14 # under the License.
   15 
   16 import datetime
   17 
   18 import falcon
   19 
   20 from monasca_api.tests import base
   21 from monasca_api.v2.reference import versions
   22 
   23 
   24 class TestVersions(base.BaseApiTestCase):
   25 
   26     def setUp(self):
   27         super(TestVersions, self).setUp()
   28         self.app.add_route('/', versions.Versions())
   29         self.app.add_route('/{version_id}', versions.Versions())
   30 
   31     def test_list_versions(self):
   32         result = self.simulate_request(path='/')
   33         self.assertEqual(result.status, falcon.HTTP_200)
   34         response = result.json
   35         self.assertIsInstance(response, dict)
   36         self.assertEqual(set(['links', 'elements']),
   37                          set(response))
   38         links = response['links']
   39         self.assertIsInstance(links, list)
   40         link = links[0]
   41         self.assertEqual(set(['rel', 'href']),
   42                          set(link))
   43         self.assertEqual(link['rel'], u'self')
   44         self.assertTrue(link['href'].endswith('/'))
   45 
   46     def test_valid_version_id(self):
   47         result = self.simulate_request(path='/v2.0')
   48         self.assertEqual(result.status, falcon.HTTP_200)
   49         response = result.json
   50         self.assertIsInstance(response, dict)
   51         version = response
   52         self.assertEqual(set(['id', 'links', 'status', 'updated']),
   53                          set(version))
   54         self.assertEqual(version['id'], u'v2.0')
   55         self.assertEqual(version['status'], u'CURRENT')
   56         date_object = datetime.datetime.strptime(version['updated'],
   57                                                  "%Y-%m-%dT%H:%M:%S.%fZ")
   58         self.assertIsInstance(date_object, datetime.datetime)
   59         links = response['links']
   60         self.assertIsInstance(links, list)
   61         link = links[0]
   62         self.assertEqual(set(['rel', 'href']),
   63                          set(link))
   64         self.assertEqual(link['rel'], u'self')
   65         self.assertTrue(link['href'].endswith('/v2.0'))
   66 
   67     def test_invalid_version_id(self):
   68         result = self.simulate_request(path='/v1.0')
   69         self.assertEqual(result.status, '422 Unprocessable Entity')