"Fossies" - the Fresh Open Source Software Archive

Member "magnum-8.1.0/magnum/tests/unit/objects/test_fields.py" (1 Oct 2019, 6135 Bytes) of package /linux/misc/openstack/magnum-8.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 last Fossies "Diffs" side-by-side code changes report for "test_fields.py": 7.1.0_vs_8.0.0.

    1 # Copyright 2015 IBM Corp.
    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 oslo_versionedobjects.tests import test_fields
   16 
   17 from magnum.objects import fields
   18 
   19 
   20 class TestClusterStatus(test_fields.TestField):
   21     def setUp(self):
   22         super(TestClusterStatus, self).setUp()
   23         self.field = fields.ClusterStatusField()
   24         self.coerce_good_values = [('CREATE_IN_PROGRESS',
   25                                     'CREATE_IN_PROGRESS'),
   26                                    ('CREATE_FAILED', 'CREATE_FAILED'),
   27                                    ('CREATE_COMPLETE', 'CREATE_COMPLETE'),
   28                                    ('UPDATE_IN_PROGRESS',
   29                                     'UPDATE_IN_PROGRESS'),
   30                                    ('UPDATE_FAILED', 'UPDATE_FAILED'),
   31                                    ('UPDATE_COMPLETE', 'UPDATE_COMPLETE'),
   32                                    ('DELETE_IN_PROGRESS',
   33                                     'DELETE_IN_PROGRESS'),
   34                                    ('DELETE_FAILED', 'DELETE_FAILED'),
   35                                    ('RESUME_COMPLETE', 'RESUME_COMPLETE'),
   36                                    ('RESTORE_COMPLETE', 'RESTORE_COMPLETE'),
   37                                    ('ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'),
   38                                    ('SNAPSHOT_COMPLETE', 'SNAPSHOT_COMPLETE'),
   39                                    ('CHECK_COMPLETE', 'CHECK_COMPLETE'),
   40                                    ('ADOPT_COMPLETE', 'ADOPT_COMPLETE')]
   41         self.coerce_bad_values = ['DELETE_STOPPED']
   42         self.to_primitive_values = self.coerce_good_values[0:1]
   43         self.from_primitive_values = self.coerce_good_values[0:1]
   44 
   45     def test_stringify(self):
   46         self.assertEqual("'UPDATE_FAILED'",
   47                          self.field.stringify('UPDATE_FAILED'))
   48 
   49     def test_stringify_invalid(self):
   50         self.assertRaises(ValueError, self.field.stringify, 'DELETE_STOPPED')
   51 
   52 
   53 class TestClusterHealthStatus(test_fields.TestField):
   54     def setUp(self):
   55         super(TestClusterHealthStatus, self).setUp()
   56         self.field = fields.ClusterHealthStatusField()
   57         self.coerce_good_values = [('HEALTHY', 'HEALTHY'),
   58                                    ('UNHEALTHY', 'UNHEALTHY')]
   59         self.coerce_bad_values = ['FAKE']
   60 
   61         self.to_primitive_values = self.coerce_good_values[0:1]
   62         self.from_primitive_values = self.coerce_good_values[0:1]
   63 
   64     def test_stringify(self):
   65         self.assertEqual("'UNHEALTHY'",
   66                          self.field.stringify('UNHEALTHY'))
   67 
   68     def test_stringify_invalid(self):
   69         self.assertRaises(ValueError, self.field.stringify, 'FAKE')
   70 
   71 
   72 class TestContainerStatus(test_fields.TestField):
   73     def setUp(self):
   74         super(TestContainerStatus, self).setUp()
   75         self.field = fields.ContainerStatusField()
   76         self.coerce_good_values = [('Error', 'Error'), ('Running', 'Running'),
   77                                    ('Stopped', 'Stopped'),
   78                                    ('Paused', 'Paused'),
   79                                    ('Unknown', 'Unknown'), ]
   80         self.coerce_bad_values = ['DELETED']
   81 
   82         self.to_primitive_values = self.coerce_good_values[0:1]
   83         self.from_primitive_values = self.coerce_good_values[0:1]
   84 
   85     def test_stringify(self):
   86         self.assertEqual("'Stopped'",
   87                          self.field.stringify('Stopped'))
   88 
   89     def test_stringify_invalid(self):
   90         self.assertRaises(ValueError, self.field.stringify, 'DELETED')
   91 
   92 
   93 class TestClusterType(test_fields.TestField):
   94     def setUp(self):
   95         super(TestClusterType, self).setUp()
   96         self.field = fields.ClusterTypeField()
   97         self.coerce_good_values = [('kubernetes', 'kubernetes'),
   98                                    ('swarm', 'swarm'),
   99                                    ('mesos', 'mesos'), ]
  100         self.coerce_bad_values = ['invalid']
  101 
  102         self.to_primitive_values = self.coerce_good_values[0:1]
  103         self.from_primitive_values = self.coerce_good_values[0:1]
  104 
  105     def test_stringify(self):
  106         self.assertEqual("'kubernetes'",
  107                          self.field.stringify('kubernetes'))
  108 
  109     def test_stringify_invalid(self):
  110         self.assertRaises(ValueError, self.field.stringify, 'invalid')
  111 
  112 
  113 class TestMagnumServiceBinary(test_fields.TestField):
  114     def setUp(self):
  115         super(TestMagnumServiceBinary, self).setUp()
  116         self.field = fields.MagnumServiceBinaryField()
  117         self.coerce_good_values = [('magnum-conductor', 'magnum-conductor')]
  118         self.coerce_bad_values = ['invalid']
  119 
  120         self.to_primitive_values = self.coerce_good_values[0:1]
  121         self.from_primitive_values = self.coerce_good_values[0:1]
  122 
  123     def test_stringify(self):
  124         self.assertEqual("'magnum-conductor'",
  125                          self.field.stringify('magnum-conductor'))
  126 
  127     def test_stringify_invalid(self):
  128         self.assertRaises(ValueError, self.field.stringify, 'invalid')
  129 
  130 
  131 class TestServerType(test_fields.TestField):
  132     def setUp(self):
  133         super(TestServerType, self).setUp()
  134         self.field = fields.ServerTypeField()
  135         self.coerce_good_values = [('vm', 'vm'),
  136                                    ('bm', 'bm'), ]
  137         self.coerce_bad_values = ['invalid']
  138 
  139         self.to_primitive_values = self.coerce_good_values[0:1]
  140         self.from_primitive_values = self.coerce_good_values[0:1]
  141 
  142     def test_stringify(self):
  143         self.assertEqual("'vm'",
  144                          self.field.stringify('vm'))
  145 
  146     def test_stringify_invalid(self):
  147         self.assertRaises(ValueError, self.field.stringify, 'invalid')