def main(unused_argv): sample_data = {} tests = GroupRegressionTestsByRenderer() for renderer, test_classes in tests.items(): for test_class in sorted(test_classes, key=lambda cls: cls.__name__): if flags.FLAGS.tests and test_class.__name__ not in flags.FLAGS.tests: continue test_instance = test_class() # Recreate a new data store each time. startup.TestInit() try: test_instance.setUp() test_instance.Run() sample_data.setdefault(renderer, []).extend(test_instance.checks) finally: try: test_instance.tearDown() except Exception: # pylint: disable=broad-except pass encoded_sample_data = json.dumps(sample_data, indent=2, sort_keys=True, separators=(",", ": ")) print encoded_sample_data
def main(_): """Run the main test harness.""" # For testing we use the test config file. flags.FLAGS.config = config_lib.CONFIG["Test.config"] # We are running a test so let the config system know that. config_lib.CONFIG.AddContext("Test Context", "Context applied when we run tests.") # This is a standalone program and might need to use the config # file. startup.TestInit() # Start up a server in another thread trd = DjangoThread() trd.start() try: user_ns = dict() user_ns.update(globals()) user_ns.update(locals()) # Wait in the shell so selenium IDE can be used. ipshell.IPShell(argv=[], user_ns=user_ns) finally: # Kill the server thread trd.Stop()
def main(_): """Run the main test harness.""" startup.TestInit() # Start up a server in another thread trd = DjangoThread(config_lib.CONFIG["AdminUI.port"]) trd.StartAndWaitUntilServing() user_ns = dict() user_ns.update(globals()) user_ns.update(locals()) # Wait in the shell so selenium IDE can be used. ipshell.IPShell(argv=[], user_ns=user_ns)
def setUpClass(cls): # pylint: disable=invalid-name if cls.api_version not in [1, 2]: raise ValueError("api_version may be 1 or 2 only") if not HttpApiRegressionTestMixinBase._connector: port = portpicker.PickUnusedPort() logging.info("Picked free AdminUI port %d.", port) startup.TestInit() # Force creation of new APIAuthorizationManager. api_auth_manager.APIACLInit.InitApiAuthManager() trd = django_lib.DjangoThread(port) trd.StartAndWaitUntilServing() endpoint = ("http://localhost:%s" % port) HttpApiRegressionTestMixinBase._connector = http_connector.HttpConnector( api_endpoint=endpoint)
def main(argv): """Sets up all the component in their own threads.""" # For testing we use the test config file. flags.FLAGS.config = config_lib.CONFIG["Test.config"] config_lib.CONFIG.AddContext( "Demo Context", "The demo runs all functions in a single process using the " "in memory data store.") startup.TestInit() # pylint: disable=unused-import,unused-variable,g-import-not-at-top from grr.gui import gui_plugins # pylint: enable=unused-import,unused-variable,g-import-not-at-top # This is the worker thread. worker_thread = threading.Thread(target=worker.main, args=[argv], name="Worker") worker_thread.daemon = True worker_thread.start() # This is the enroller thread. enroller_thread = threading.Thread(target=enroller.main, args=[argv], name="Enroller") enroller_thread.daemon = True enroller_thread.start() # This is the http server Frontend that clients communicate with. http_thread = threading.Thread(target=http_server.main, args=[argv], name="HTTP Server") http_thread.daemon = True http_thread.start() client_thread = threading.Thread(target=client.main, args=[argv], name="Client") client_thread.daemon = True client_thread.start() # The UI is running in the main thread. runtests.main(argv)
def main(unused_argv): sample_data = {} tests = GroupRegressionTestsByHandler() for handler, test_classes in tests.items(): for test_class in sorted(test_classes, key=lambda cls: cls.__name__): if flags.FLAGS.tests and test_class.__name__ not in flags.FLAGS.tests: continue if flags.FLAGS.api_version == 2 and test_class.skip_v2_tests: continue test_instance = test_class() # Recreate a new data store each time. startup.TestInit() try: test_instance.setUp() if flags.FLAGS.api_version == 1: test_instance.use_api_v2 = False elif flags.FLAGS.api_version == 2: test_instance.use_api_v2 = True else: raise ValueError("API version can only be 1 or 2.") test_instance.Run() sample_data.setdefault(handler.__name__, []).extend(test_instance.checks) finally: try: test_instance.tearDown() except Exception: # pylint: disable=broad-except pass encoded_sample_data = json.dumps( sample_data, indent=2, sort_keys=True, separators=(",", ": "), cls=http_api.JSONEncoderWithRDFPrimitivesSupport) print encoded_sample_data
def Generate(self): """Prints generated 'golden' output to the stdout.""" sample_data = {} tests = self._GroupRegressionTestsByHandler() for handler, test_classes in tests.items(): for test_class in sorted(test_classes, key=lambda cls: cls.__name__): if flags.FLAGS.tests and test_class.__name__ not in flags.FLAGS.tests: continue if getattr(test_class, "connection_type", "") != self.connection_type: continue startup.TestInit() test_class.setUpClass() loaded = self.loader.loadTestsFromTestCase(test_class) for t in loaded: try: t.setUp() t.Run() sample_data.setdefault(handler.__name__, []).extend(t.checks) finally: try: t.tearDown() except Exception as e: # pylint: disable=broad-except logging.exception(e) json_sample_data = json.dumps(sample_data, indent=2, sort_keys=True, separators=(",", ": ")) print json_sample_data
def setUp(self): # pylint: disable=invalid-name """Set up test method.""" super(ApiRegressionTest, self).setUp() if not self.__class__.api_method: raise ValueError("%s.api_method has to be set." % self.__class__.__name__) if not self.__class__.handler: raise ValueError("%s.handler has to be set." % self.__class__.__name__) self.checks = [] self.syscalls_stubber = utils.MultiStubber( (socket, "gethostname", lambda: "test.host"), (os, "getpid", lambda: 42)) self.syscalls_stubber.Start() self.token.username = "******" startup.TestInit() # Force creation of new APIAuthorizationManager. api_auth_manager.APIACLInit.InitApiAuthManager()