# 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


class WhenWrongNumberOfPositionalArguments(BaseParseArgumentsTestCase):

    additional_mocks = ['arguments']

    def setup(self):
        BaseParseArgumentsTestCase.setup(self)
        self.parser.parse_args.return_value = (self.options, self.arguments)

        assert_raises(SystemExit, parse_arguments)

    def should_print_help(self):
        assert self.parser.calls('print_help')


####
##
## main
##
####

class DescribeParseArguments(DingusWhitelistTestCase):

    module = mod
    module_mocks = [
        'parse_arguments', '__import__', 'Connection', 'ensure_indexes']
    additional_mocks = ['options', 'module_name', 'endpoint']

    def run(self):

# 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



class WhenWrongNumberOfPositionalArguments(BaseParseArgumentsTestCase):

    additional_mocks = ['arguments']

    def setup(self):
        BaseParseArgumentsTestCase.setup(self)
        self.parser.parse_args.return_value = (self.options, self.arguments)

        assert_raises(SystemExit, parse_arguments)

    def should_print_help(self):
        assert self.parser.calls('print_help')


####
##
## main
##
####

class DescribeParseArguments(DingusWhitelistTestCase):

    module = mod
    module_mocks = [
        'parse_arguments', '__import__', 'Connection', 'ensure_indexes']
    additional_mocks = ['options', 'module_name', 'endpoint']

    def run(self):

        self.module.parse_arguments.return_value = (