Exemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        form_layout_file = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), 'form_layout.yml')
        if not os.path.exists(form_layout_file):
            raise NotFound(f'"form_layout.yml" is not found for {self.__class__.__name__}')

        form_layout = read_yaml(form_layout_file)
        return Response(form_layout[self.storage_type])
Exemplo n.º 2
0
 def list(self, request, *args, **kwargs):
     annotation_templates_dir = find_dir('annotation_templates')
     configs = []
     for config_file in pathlib.Path(annotation_templates_dir).glob('**/*.yml'):
         config = read_yaml(config_file)
         configs.append(config)
     template_groups_file = find_file(os.path.join('annotation_templates', 'groups.txt'))
     with open(template_groups_file) as f:
         groups = f.read().splitlines()
     logger.debug(f'{len(configs)} templates found.')
     return Response({'templates': configs, 'groups': groups})
Exemplo n.º 3
0
def load_test_suite_from_file(test_suite_file):
    """Load test suites from file in YAML format:
    - test_1:
        - /first/step/url:
            method: GET
            query_string: {"a": "b"}
            data: {"json": "payload"}
            status_code: 200
            response: {"json": "response"}
        - /second/step/url:
    - test_2:
    """
    assert test_suite_file.endswith('.yml'), 'Test suite file should be in YAML format'
    if not os.path.exists(test_suite_file):
        # try to load from local test_suites directory
        test_suites_dir = os.path.join(os.path.dirname(__file__), 'test_suites')
        assert os.path.exists(test_suites_dir)
        return read_yaml(os.path.join(test_suites_dir, test_suite_file))
    else:
        return read_yaml(test_suite_file)
Exemplo n.º 4
0
 def list(self, request, *args, **kwargs):
     annotation_templates_dir = find_dir('annotation_templates')
     configs = []
     for config_file in pathlib.Path(annotation_templates_dir).glob('**/*.yml'):
         config = read_yaml(config_file)
         if config.get('image', '').startswith('/static') and settings.HOSTNAME:
             # if hostname set manually, create full image urls
             config['image'] = settings.HOSTNAME + config['image']
         configs.append(config)
     template_groups_file = find_file(os.path.join('annotation_templates', 'groups.txt'))
     with open(template_groups_file, encoding='utf-8') as f:
         groups = f.read().splitlines()
     logger.debug(f'{len(configs)} templates found.')
     return Response({'templates': configs, 'groups': groups})