# Path: scalymongo/manage/ensure_indexes.py
# def ensure_indexes(connection, options):
#     for model in connection.models:
#         model.ensure_indexes(background=options.background)
# 
# def main():
#     options, module_name, endpoint = parse_arguments()
# 
#     # Import the models so that they get registered with Connection.
#     __import__(module_name)
# 
#     connection = Connection(endpoint)
#     ensure_indexes(connection, options)
# 
# def parse_arguments():
#     """Parse and validate the arguments.
# 
#     This returns a tuple like ``(options, module_name, endpoint)``.
# 
#     """
#     parser = OptionParser()
#     parser.usage = '%prog [options] MODULE ENDPOINT'
#     parser.add_option(
#         '--background', action='store_true',
#         help='create indexes as a non-blocking operation [default]',
#     )
#     parser.add_option(
#         '--no-background', action='store_false', dest='background',
#         help='disable background index creation',
#     )
#     parser.set_defaults(background=True)
# 
#     options, arguments = parser.parse_args()
# 
#     if len(arguments) != 2:
#         parser.print_help()
#         exit(1)
# 
#     module_name, endpoint = arguments
#     return options, module_name, endpoint


from deterministic_dingus import DingusWhitelistTestCase, Dingus
from nose.tools import assert_raises, assert_equals
from scalymongo.manage.ensure_indexes import (
    ensure_indexes,
    main,
    parse_arguments,
)
import scalymongo.manage.ensure_indexes as mod
        self.module.parse_arguments.return_value = (
            self.options, self.module_name, self.endpoint)

        main()

    def should_import_module(self):
        assert self.module.__import__.calls('()', self.module_name)

    def should_make_Connection(self):
        assert self.module.Connection.calls('()', self.endpoint)

    def should_ensure_indexes(self):
        assert self.module.ensure_indexes.calls(
            '()', self.module.Connection(), self.options)


####
##
## ensure_indexes
##
####

class DescribeEnsureIndexes(DingusWhitelistTestCase):

    module = mod
    additional_mocks = ['connection', 'options', 'model_a', 'model_b']

    def run(self):
        self.connection.models = [self.model_a, self.model_b]


# Path: scalymongo/manage/ensure_indexes.py
# def ensure_indexes(connection, options):
#     for model in connection.models:
#         model.ensure_indexes(background=options.background)
# 
# def main():
#     options, module_name, endpoint = parse_arguments()
# 
#     # Import the models so that they get registered with Connection.
#     __import__(module_name)
# 
#     connection = Connection(endpoint)
#     ensure_indexes(connection, options)
# 
# def parse_arguments():
#     """Parse and validate the arguments.
# 
#     This returns a tuple like ``(options, module_name, endpoint)``.
# 
#     """
#     parser = OptionParser()
#     parser.usage = '%prog [options] MODULE ENDPOINT'
#     parser.add_option(
#         '--background', action='store_true',
#         help='create indexes as a non-blocking operation [default]',
#     )
#     parser.add_option(
#         '--no-background', action='store_false', dest='background',
#         help='disable background index creation',
#     )
#     parser.set_defaults(background=True)
# 
#     options, arguments = parser.parse_args()
# 
#     if len(arguments) != 2:
#         parser.print_help()
#         exit(1)
# 
#     module_name, endpoint = arguments
#     return options, module_name, endpoint


# Path: tests/unit/manage/test_ensure_indexes.py
from deterministic_dingus import DingusWhitelistTestCase, Dingus
from nose.tools import assert_raises, assert_equals
from scalymongo.manage.ensure_indexes import (
    ensure_indexes,
    main,
    parse_arguments,
)
import scalymongo.manage.ensure_indexes as mod

        self.module.parse_arguments.return_value = (
            self.options, self.module_name, self.endpoint)

        main()

    def should_import_module(self):
        assert self.module.__import__.calls('()', self.module_name)

    def should_make_Connection(self):
        assert self.module.Connection.calls('()', self.endpoint)

    def should_ensure_indexes(self):
        assert self.module.ensure_indexes.calls(
            '()', self.module.Connection(), self.options)


####
##
## ensure_indexes
##
####

class DescribeEnsureIndexes(DingusWhitelistTestCase):

    module = mod
    additional_mocks = ['connection', 'options', 'model_a', 'model_b']

    def run(self):
        self.connection.models = [self.model_a, self.model_b]


        ensure_indexes(self.connection, self.options)