# Path: freezer_api/cmd/manage.py
# CONF = cfg.CONF
# LOG = log.getLogger(__name__)
# DEFAULT_INDEX = 'freezer'
# DEFAULT_REPLICAS = 0
#     DB_INIT = [
#         cfg.SubCommandOpt('db',
#                           dest='db',
#                           title='DB Options',
#                           handler=add_db_opts
#                           )
#     ]
# def add_db_opts(subparser):
# def parse_config():
# def main():


import sys
import unittest
from unittest import mock
from oslo_config import cfg
from freezer_api.cmd import manage as freezer_manage




CONF = cfg.CONF


class TestFreezerApiCmd(unittest.TestCase):
    """Unit test cases for python modules under freezer/cmd."""
    def setUp(self):
        super(TestFreezerApiCmd, self).setUp()

    def tearDown(self):
        super(TestFreezerApiCmd, self).tearDown()
        CONF.reset()
        CONF.unregister_opt(cfg.StrOpt('db'))

    @mock.patch("freezer_api.db.manager.get_db_driver")
    def test_db_sync(self, mock_get_db_driver):
        db_driver = mock_get_db_driver("elasticsearch", backend="")
        db_driver.db_sync.return_value = mock.MagicMock()
        sys.argv = ["freezer-manage", "db", "sync"]
        freezer_manage.main()
        self.assertTrue(db_driver.db_sync.called)

    @mock.patch("freezer_api.db.manager.get_db_driver")
    def test_db_update(self, mock_get_db_driver):
        db_driver = mock_get_db_driver("elasticsearch", backend="")
        db_driver.db_sync.return_value = mock.MagicMock()
        sys.argv = ["freezer-manage", "db", "update"]

# Path: freezer_api/cmd/manage.py
# CONF = cfg.CONF
# LOG = log.getLogger(__name__)
# DEFAULT_INDEX = 'freezer'
# DEFAULT_REPLICAS = 0
#     DB_INIT = [
#         cfg.SubCommandOpt('db',
#                           dest='db',
#                           title='DB Options',
#                           handler=add_db_opts
#                           )
#     ]
# def add_db_opts(subparser):
# def parse_config():
# def main():


# Path: freezer_api/tests/unit/cmd/test_cmd.py
import sys
import unittest
from unittest import mock
from oslo_config import cfg
from freezer_api.cmd import manage as freezer_manage





CONF = cfg.CONF


class TestFreezerApiCmd(unittest.TestCase):
    """Unit test cases for python modules under freezer/cmd."""
    def setUp(self):
        super(TestFreezerApiCmd, self).setUp()

    def tearDown(self):
        super(TestFreezerApiCmd, self).tearDown()
        CONF.reset()
        CONF.unregister_opt(cfg.StrOpt('db'))

    @mock.patch("freezer_api.db.manager.get_db_driver")
    def test_db_sync(self, mock_get_db_driver):
        db_driver = mock_get_db_driver("elasticsearch", backend="")
        db_driver.db_sync.return_value = mock.MagicMock()
        sys.argv = ["freezer-manage", "db", "sync"]
        freezer_manage.main()
        self.assertTrue(db_driver.db_sync.called)

    @mock.patch("freezer_api.db.manager.get_db_driver")
    def test_db_update(self, mock_get_db_driver):
        db_driver = mock_get_db_driver("elasticsearch", backend="")
        db_driver.db_sync.return_value = mock.MagicMock()
        sys.argv = ["freezer-manage", "db", "update"]

        freezer_manage.main()