Beispiel #1
0
 def relative_path(cls, val, path_must_exist):
     '''
     returns an absolute path that is resolved relative to the file being loaded
     '''
     if not isinstance(val, six.types.StringTypes):
         raise error.AssertionException(
             "Expected pathname for setting %s in config file %s" %
             (cls.key_path, cls.filename))
     if cls.dirpath and not os.path.isabs(val):
         val = os.path.abspath(os.path.join(cls.dirpath, val))
     if path_must_exist and not os.path.isfile(val):
         raise error.AssertionException(
             'In setting %s in config file %s: No such file %s' %
             (cls.key_path, cls.filename, val))
     return val
Beispiel #2
0
    def load_from_yaml(cls, filename, template_keys):
        '''
        loads a yaml file, processes the loaded dict given the specified template keys. Essentially the same as the
        ConfigFileLoader in the UserSync app.
        :param filename: the file to load yaml from
        :param template_keys: a dict whose keys are "template_keys" such as /key1/key2/key3 and whose values are tuples:
            (path_must_exist, is_path, default_val) which are options on the value of the key whose values are path
            expanded: must the path exist, can it be a list of paths that contains sub-dictionaries whose values are
            paths, and does the key have a default value so that must be added to the dictionary if there is not already
            a value found.
        '''
        cls.filepath = os.path.abspath(filename)
        cls.filename = os.path.split(cls.filepath)[1]
        cls.dirpath = os.path.dirname(cls.filepath)

        if not os.path.isfile(cls.filepath):
            raise error.AssertionException('No such configuration file: %s' %
                                           (cls.filepath))

        with open(filename, 'r', 1) as input_file:
            yml = yaml.load(input_file)
            if yml is None:
                yml = {}

        for template_key, options in template_keys.iteritems():
            cls.key_path = template_key
            keys = template_key.split('/')
            cls.process_path_key(yml, keys, 1, *options)
        return yml
Beispiel #3
0
    def __init__(self, config_filename, app_config):
        '''
        Sets up a user sync test set, given a path to the test set's configuration file. This basically maps
        configuration settings from the configuration file and options constructed from the command line arguments to
        test set and server configuration dictionary objects. Also, the user sync path is examined to determine if
        the user-sync tool can be invoked directly, or needs to be invoked through python, and sets up the
        test set configuration accordingly.
        :type config_filename: str
        '''
        self.logger = logging.getLogger('test-suite')

        config_filename = os.path.abspath(config_filename)
        test_suite_config = config.ConfigFileLoader.load_from_yaml(
            config_filename, TEST_SUITE_TEMPLATE_KEYS)
        self.test_suite_path = test_suite_path = os.path.dirname(
            config_filename)

        user_sync_common_args = test_suite_config['user_sync'][
            'common_arguments'] if 'common_arguments' in test_suite_config[
                'user_sync'] else None
        if IS_NT_PLATFORM:
            user_sync_path = test_suite_config['user_sync'][
                'user_sync_path_win']
            user_sync_common_args = user_sync_path if not user_sync_common_args else "\"%s\" %s" % (
                user_sync_path, user_sync_common_args)
            user_sync_path = "python"
        else:
            user_sync_path = test_suite_config['user_sync']['user_sync_path']

        self.test_suite_config = app_config
        self.test_suite_config.update({
            'user_sync_path':
            user_sync_path,
            'user_sync_common_args':
            user_sync_common_args,
            'users_request_matcher':
            test_suite_config['umapi']['users_request_matcher'],
            'actions_request_matcher':
            test_suite_config['umapi']['actions_request_matcher']
        })

        self.test_server_config = {
            'live_mode': app_config['live_mode'],
            'proxy_host': test_suite_config['umapi']['proxy_host'],
            'destination_host': test_suite_config['umapi']['destination_host']
        }

        test_group_name = self.test_suite_config['test_group_name']
        if test_group_name:
            if not os.path.isdir(os.path.join(test_suite_path,
                                              test_group_name)):
                raise error.AssertionException('test group "%s" not found.' %
                                               (test_group_name))
            self.test_group_names = [test_group_name]
        else:
            self.test_group_names = [
                f for f in os.listdir(test_suite_path) if os.path.isfile(
                    os.path.join(test_suite_path, f,
                                 TEST_GROUP_CONFIG_FILENAME))
            ]
Beispiel #4
0
    def __init__(self, test_group_path, test_suite_config, test_server_config):
        '''
        Manages a test group, which is basically a directory in the same path as the suite configuration file.
        :type config_filename: str
        '''
        test_group_config = config.ConfigFileLoader.load_from_yaml(
            os.path.join(test_group_path, TEST_GROUP_CONFIG_FILENAME),
            TEST_GROUP_TEMPLATE_KEYS)

        self.logger = logging.getLogger('test-group')
        self.test_group_disabled = test_group_config['disabled']
        self.test_group_path = test_group_path
        self.test_suite_config = test_suite_config
        self.test_server_config = test_server_config

        test_name = self.test_suite_config['test_name']
        if test_name:
            if not (os.path.isfile(
                    os.path.join(test_group_path, test_name,
                                 TEST_CONFIG_FILENAME))):
                raise error.AssertionException(
                    'test-config.yml not found for test %s.' % (test_name))
            self.test_names = [test_name]
        else:
            self.test_names = [
                f for f in os.listdir(test_group_path) if os.path.isfile(
                    os.path.join(test_group_path, f, TEST_CONFIG_FILENAME))
            ]
Beispiel #5
0
    def _copy_dir(self,srcpath,dstpath):
        '''
        Duplicates the specified directory into the destination folder.
        :type filename: str
        '''
        if not os.path.isdir(srcpath):
            raise error.AssertionException("specified path is not a folder")

        shutil.copytree(srcpath,dstpath)
Beispiel #6
0
def read_lines(filename):
    if not os.path.isfile(filename):
        raise error.AssertionException('File "%s" not found.' % (filename))
    with open(filename, 'r') as file:
        return file.read().splitlines()