"Fossies" - the Fresh Open Source Software Archive

Member "monasca-api-4.0.0/monasca_api/tests/test_config_types.py" (13 May 2020, 1973 Bytes) of package /linux/misc/openstack/monasca-api-4.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 latest Fossies "Diffs" side-by-side code changes report for "test_config_types.py": 3.1.0_vs_4.0.0.

    1 # (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
    2 # Copyright 2017 FUJITSU LIMITED
    3 #
    4 # Licensed under the Apache License, Version 2.0 (the "License");
    5 # you may not use this file except in compliance with the License.
    6 # You may obtain 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,
   12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   13 # implied.
   14 # See the License for the specific language governing permissions and
   15 # limitations under the License.
   16 
   17 
   18 from monasca_api.conf import types
   19 from monasca_api.tests import base
   20 
   21 
   22 class TestHostAddressPortType(base.BaseTestCase):
   23     def setUp(self):
   24         super(TestHostAddressPortType, self).setUp()
   25         self.types = types.HostAddressPortType()
   26 
   27     def test_ip_address(self):
   28         self.assertEqual('127.0.0.1:2121', self.types('127.0.0.1:2121'))
   29 
   30     def test_hostname(self):
   31         self.assertEqual('localhost:2121', self.types('localhost:2121'))
   32 
   33     def test_ipv6_address(self):
   34         self.assertEqual('2001:db8:85a3::8a2e:370:2121',
   35                          self.types('[2001:db8:85a3::8a2e:370]:2121'))
   36 
   37     def test_ipv6_hostname(self):
   38         self.assertEqual('::1:2121', self.types('[::1]:2121'))
   39 
   40     # failure scenario
   41     def test_missing_port(self):
   42         self.assertRaises(ValueError, self.types, '127.0.0.1')
   43 
   44     def test_missing_address(self):
   45         self.assertRaises(ValueError, self.types, ':123')
   46 
   47     def test_incorrect_ip(self):
   48         self.assertRaises(ValueError, self.types, '127.surprise.0.1:2121')
   49 
   50     def test_incorrect_ipv6(self):
   51         self.assertRaises(ValueError, self.types, '[2001:db8:8a2e:370]:2121')
   52 
   53     def test_incorrect_port(self):
   54         self.assertRaises(ValueError, self.types, '127.0.0.1:65536')
   55         self.assertRaises(ValueError, self.types, '127.0.0.1:sample')