def test_get_parsed_configs(): directory = '/etc/vsftpd' file_names = ['vsftpd.conf', 'foo.conf'] listdir = MockListDir(directory, file_names) fileops = MockFileOperations() fileops.files[os.path.join(directory, file_names[0])] = 'anonymous_enable=YES\n' \ 'ca_certs_file=/foo/bar\n' fileops.files[os.path.join(directory, file_names[1])] = 'anonymous_enable=NO\n' parsed_configs = list( library._get_parsed_configs(read_func=fileops.read, listdir=listdir.listdir)) assert not listdir.error assert len(fileops.files_read) == 2 assert os.path.join(directory, file_names[0]) in fileops.files_read assert os.path.join(directory, file_names[1]) in fileops.files_read assert len(parsed_configs) == 2 if parsed_configs[0][0] != os.path.join(directory, file_names[0]): parsed_configs.reverse() assert (os.path.join(directory, file_names[0]), { 'anonymous_enable': True, 'ca_certs_file': '/foo/bar' }) in parsed_configs assert (os.path.join(directory, file_names[1]), { 'anonymous_enable': False }) in parsed_configs
def test_get_parsed_configs_inaccessible_dir(): listdir = MockListDir(to_raise=make_OSError(errno.EACCES)) fileops = MockFileOperations() parsed_configs = library._get_parsed_configs(read_func=fileops.read, listdir=listdir.listdir) assert fileops.read_called == 0 assert len(parsed_configs) == 0
def test_get_parsed_configs_nonexistent_dir(): listdir = MockListDir(to_raise=make_OSError(errno.ENOENT)) fileops = MockFileOperations() parsed_configs = library._get_parsed_configs(read_func=fileops.read, listdir=listdir.listdir) assert fileops.read_called == 0 assert not parsed_configs
def test_get_parsed_configs_empty_dir(): directory = '/etc/vsftpd' listdir = MockListDir(directory, []) fileops = MockFileOperations() parsed_configs = library._get_parsed_configs(read_func=fileops.read, listdir=listdir.listdir) assert not listdir.error assert fileops.read_called == 0 assert len(parsed_configs) == 0