"Fossies" - the Fresh Open Source Software Archive

Member "masakari-9.0.0/masakari/tests/unit/test_masakari_manage.py" (13 May 2020, 3157 Bytes) of package /linux/misc/openstack/masakari-9.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_masakari_manage.py": 8.0.0_vs_9.0.0.

    1 # Copyright 2017 NTT DATA
    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 import sys
   16 from unittest import mock
   17 
   18 from masakari.cmd import manage
   19 from masakari import context
   20 from masakari.db import api as db_api
   21 from masakari import test
   22 
   23 
   24 class DBCommandsTestCase(test.TestCase):
   25 
   26     def setUp(self):
   27         super(DBCommandsTestCase, self).setUp()
   28         self.commands = manage.DbCommands()
   29         self.context = context.get_admin_context()
   30         sys.argv = ['masakari-manage']
   31 
   32     @mock.patch.object(db_api, 'purge_deleted_rows')
   33     @mock.patch.object(context, 'get_admin_context')
   34     def test_purge_command(self, mock_context, mock_db_purge):
   35         mock_context.return_value = self.context
   36         self.commands.purge(0, 100)
   37         mock_db_purge.assert_called_once_with(self.context, 0, 100)
   38 
   39     def test_purge_negative_age_in_days(self):
   40         ex = self.assertRaises(SystemExit, self.commands.purge, -1, 100)
   41         self.assertEqual("Must supply a non-negative value for age.", ex.code)
   42 
   43     def test_purge_invalid_age_in_days(self):
   44         ex = self.assertRaises(SystemExit, self.commands.purge, "test", 100)
   45         self.assertEqual("Invalid value for age, test", ex.code)
   46 
   47     def test_purge_command_exceeded_age_in_days(self):
   48         ex = self.assertRaises(SystemExit, self.commands.purge, 1000000, 50)
   49         self.assertEqual("Maximal age is count of days since epoch.", ex.code)
   50 
   51     def test_purge_invalid_max_rows(self):
   52         ex = self.assertRaises(SystemExit, self.commands.purge, 0, 0)
   53         self.assertEqual("Must supply value greater than 0 for max_rows.",
   54                          ex.code)
   55 
   56     def test_purge_negative_max_rows(self):
   57         ex = self.assertRaises(SystemExit, self.commands.purge, 0, -5)
   58         self.assertEqual("Invalid input received: max_rows must be >= -1",
   59                          ex.code)
   60 
   61     @mock.patch.object(db_api, 'purge_deleted_rows')
   62     @mock.patch.object(context, 'get_admin_context')
   63     def test_purge_max_rows(self, mock_context, mock_db_purge):
   64         mock_context.return_value = self.context
   65         value = (2 ** 31) - 1
   66         self.commands.purge(age_in_days=1, max_rows=value)
   67         mock_db_purge.assert_called_once_with(self.context, 1, value)
   68 
   69     def test_purge_command_exceeded_maximum_rows(self):
   70         # value(2 ** 31) is greater than max_rows(2147483647) by 1.
   71         value = 2 ** 31
   72         ex = self.assertRaises(SystemExit, self.commands.purge, age_in_days=1,
   73                                max_rows=value)
   74         expected = "Invalid input received: max_rows must be <= 2147483647"
   75         self.assertEqual(expected, ex.code)