def get_specification_template(
         self) -> Optional[Dict[str, Union[int, str]]]:
     factory = get_admin_factory()
     if self._feature_type is None:
         self._feature_type = factory.feature_type_storage.get_default_feature_type(
         ).name
     parser = factory.context.project_settings.user_spec_template_mapping.get(
         self._feature_type)
     return _make_dict_from_model(parser)
 def _make_file_path(cls, file_path: str) -> str:
     feature_suffix = get_admin_factory().context.file_settings.feature_suffix
     if file_path.rstrip().endswith(feature_suffix):
         file_path = file_path.removesuffix(feature_suffix)
     if not cls._file_path_pattern.match(file_path):
         raise ValidationError(
             f"Incorrect format of file path specification: '{file_path}'! "
             f"Supported pattern: {cls._file_path_pattern.pattern}, for example 'my_folder / my_filename(.feature)'."
             " At least 8 characters long."
         )
     path = Path(file_path.replace(" ", "")).with_suffix(feature_suffix).as_posix()
     logger.debug("Processed feature file path: '%s'", path)
     return path
Exemple #3
0
 def _run_emulation(emulation_id: int) -> werkzeug.Response:
     factory = get_admin_factory()
     emulation_run = factory.emulation_storage.create_emulation_run(
         emulation_id=emulation_id, initiated_by=current_user.login)
     if not factory.redis_producer.add_task(
             EmulationTask(data=EmulationData(
                 emulation_run_id=emulation_run.id))):
         flask.flash(
             "Problems with Redis service! EmulationTask has not been sent.",
             category="error")
         return flask.redirect(
             flask.url_for("emulation.edit_view", id=emulation_id))
     return flask.redirect(
         flask.url_for("emulationrun.details_view", id=emulation_run.id))
 def _validate_json(model: db.TestUser) -> None:
     if not isinstance(model.specification, dict):
         raise ValidationError(
             "Could not convert specified data into correct JSON!")
     parser = get_admin_factory(
     ).context.project_settings.user_spec_template_mapping.get(
         model.feature_type.name)
     if parser is not None:
         try:
             parser.parse_obj(model.specification)
         except ValueError:
             raise ValidationError(
                 f"Could not convert specified data into {parser.__name__} model!"
             )
 def _run_test(data: Dict[str, Any], rendered: werkzeug.Response) -> werkzeug.Response:
     scenario_id = data.get(f"{_SCENARIO_PREFIX}-id")
     scenario_text = data.get(f"{_SCENARIO_PREFIX}-text")
     if not scenario_id or not scenario_text:
         flask.flash("Scenario information not requested.", category="error")
         return rendered
     factory = get_admin_factory()
     scenario = factory.scenario_storage.get_scenario(int(scenario_id))
     if scenario is None:
         flask.flash("Scenario does not exist, so could not run test.", category="error")
         return rendered
     test_run_id = factory.test_run_storage.create_test_run(scenario_id=scenario.id, executed_by=current_user.login)
     if not factory.context.admin_settings.consumer_based:
         factory.threadpool.apply_async(get_test_execution_factory().test_executor.execute_test, args=(test_run_id,))
     if factory.context.admin_settings.consumer_based and not factory.redis_producer.add_task(
         TestRunTask(data=TestRunData(test_run_id=test_run_id))
     ):
         flask.flash("Problems with Redis service! TestRunTask has not been sent.", category="error")
         return rendered
     logger.debug("Redirect to TestRun details view with test_run_id='%s'...", test_run_id)
     return flask.redirect(flask.url_for("testrun.details_view", id=test_run_id))
Exemple #6
0
 def description_link(self) -> Optional[str]:
     return get_admin_factory(
     ).context.emulation_settings.emulation_desc_link
 def feature_suffix(self) -> str:
     return get_admin_factory().context.file_settings.feature_suffix
 def browse_url(self) -> Optional[str]:
     browse_url_value = get_admin_factory().context.project_settings.browse_url
     if browse_url_value is not None:
         return browse_url_value.human_repr()
     return None
 def get_bdd_steps(self) -> Dict[str, Dict[str, List[str]]]:
     factory = get_admin_factory()
     return {
         feature_type: factory.step_collector.get_steps(feature_type)
         for feature_type in factory.feature_extractor.feature_types
     }
Exemple #10
0
def _run_admin(port: int, debug: bool) -> None:
    DataBaseSettings().setup_db()
    LoggingSettings().setup_logging()
    overhave_app(get_admin_factory()).run(host="localhost",
                                          port=port,
                                          debug=debug)