Ejemplo n.º 1
0
def get_command_name(args):
    """
    Return name of command which is being run
    """

    # First argument would always be atlas or manage.py, i.e the calling interface
    if len(args) < 2:
        CommandError.print_to_err(
            f"Name of command missing. Valid commands are - {VALID_COMMANDS}")

    return args[1]
Ejemplo n.º 2
0
    def handle(self, **options):
        load_conf_type = options.pop("type")

        if load_conf_type == "artillery":
            self.artillery_pipeline(**options)
        else:
            raise CommandError("Invalid Load Testing Type. Valid types are: {}".format(self.VALID_CONVERTERS))
Ejemplo n.º 3
0
    def handle(self, **options):
        runner = options.pop("runner_type")

        if runner == "artillery":
            self.artillery_runner(**options)
        else:
            raise CommandError(
                f"Invalid Load Test Runner. Valid runners are: {self.VALID_RUNNERS}"
            )
Ejemplo n.º 4
0
    def execute(self):
        command_path = self.fetch_command()

        if not command_path:
            CommandError.print_to_err(
                f"Invalid command. Valid commands are - {VALID_COMMANDS}")

        parser = ArgumentParser(usage="%(prog)s subcommand [options] [args]",
                                add_help=False)
        parser.add_argument('--pythonpath')
        parser.add_argument('args', nargs='*')  # catch-all

        options = parser.parse_known_args(self.args[2:])[0]
        handle_default_options(options)

        command_class = self.load_command(command_path)

        return command_class.run_from_argv(self.args)
Ejemplo n.º 5
0
    def handle(self, **options):
        """
        :param options: (dict)
            - name: Name of Example Project to create
        """

        project_name = options.pop("name")
        self.validate_name(project_name)

        target = os.path.join(os.getcwd(), project_name)
        if os.path.exists(target):
            raise CommandError(
                "{} directory already exists! Please select another location".
                format(project_name))

        shutil.copytree(
            os.path.join(settings.BASE_DIR, "atlas",
                         settings.EXAMPLE_DIRECTORY, project_name), target)
Ejemplo n.º 6
0
    def handle(self, **options):
        """
        Operation Order is:
        1. Load Swagger
        2. Convert it into interfaces which are then used by sub-sequent operations instead of working on raw swagger
        3. Decide the order of operations in which APIs should be hit
        4. For each API, transform their swagger configuration to load test configuration
        5. Collate these conversions with scenarios if available
        6. Transform the final generated code snippet into working code/config, and write it to correct file
        """

        load_conf_type = options.pop("type")

        load_conf = CONVERTER_MAP.get(load_conf_type)

        if not load_conf:
            raise CommandError(
                f"Invalid Load Testing Type. Valid types are: {self.VALID_CONVERTERS}"
            )

        spec = open_api_reader.SpecsFile().file_load()
        open_api = open_api_models.OpenAPISpec(spec)
        open_api.get_interfaces()

        order = ordering.Ordering(spec, open_api.interfaces)
        sorted_interfaces = order.order()

        scenarios = settings.LOAD_TEST_SCENARIOS

        tasks = [
            load_conf[TASK](interface, spec) for interface in sorted_interfaces
        ]

        _task_set = load_conf[TASK_SET](tasks=tasks, scenarios=scenarios)

        config = load_conf[FILE_CONFIG](_task_set, spec)
        config.write_to_file()

        if load_conf_type == "artillery":
            js_converter = yaml_to_js.Converter()
            js_converter.convert()
Ejemplo n.º 7
0
    def handle(self, **options):
        project_name = options.pop("name")
        self.validate_name(project_name)

        # Check that the project_name cannot be imported.
        try:
            import_module(project_name)
        except ImportError:
            pass
        else:
            raise CommandError(
                f"{project_name} conflicts with the name of an existing Python module and "
                "cannot be used as a project name. Please try another name.")

        target = os.path.join(os.getcwd(), project_name)
        if os.path.exists(target):
            overwrite = input(
                f"{project_name} directory already exists! Overwrite (y/N) ")
            if overwrite.lower() == "y":
                print(f"Removing existing {project_name}")
                shutil.rmtree(target)
            else:
                print("Aborting!")
                return

        print(f"Creating {project_name}...")
        shutil.copytree(
            os.path.join(settings.BASE_DIR, "atlas",
                         settings.APP_TEMPLATE_DIRECTORY), target)

        print("\nProject successfully created\n")

        if options.get("auto_setup", "") == "artillery":
            setup_artillery(target)

        print(success_message)
Ejemplo n.º 8
0
 def validate_name(name):
     # If it's not a valid directory name.
     if not name.isidentifier():
         raise CommandError(
             f"{name} is not a valid project name. Please make sure the name is a valid identifier."
         )
Ejemplo n.º 9
0
 def validate_name(name):
     # If it's not a valid directory name.
     if name not in VALID_EXAMPLES:
         raise CommandError(
             f"{name} is not a valid example name. Valid examples are:  {', '.join(VALID_EXAMPLES)}"
         )