'This is a rewrite of windmill.management.commands.test_windmill
that uses nose instead of functest.'

def handle(self, *args, **options):

    from windmill.bin import admin_lib
    from windmill.conf import global_settings
    import nose
    self.setup_test_db()
    server_container = ServerContainer()
    server_container.start_test_server()
    LOG.info(('Server    running    on    %d' % server_container.server_thread.port))
    self.start_helper_servers()
    global_settings.TEST_URL = ('http://127.0.0.1:%d' % server_container.server_thread.port)
    global_settings.START_FIREFOX = True
    admin_lib.configure_global_settings(logging_on=False)
    windmill_obj = admin_lib.setup()
    nose_args = self.find_modules()
    LOG.info(('Testing    modules:    ' + repr(nose_args)))
    if ('--' in sys.argv):
        nose_args.extend(sys.argv[(sys.argv.index('--') + 1):])
    res = nose.run(argv=nose_args)
    self.stop_helper_servers()
    server_container.stop_test_server()
    admin_lib.teardown(windmill_obj)
    time.sleep(0.25)
    if res:
        sys.exit(0)
    else:
        sys.exit(1)
