def post(self): file_json = request.json length_name = file_json.get('length_name', 5) extension = file_json.get('extension', '.txt') content = file_json.get('content', '') letter = file_json.get('letter', True) digit = file_json.get('digit', True) return file_service.create_file(length_name, extension, content, letter, digit), 201
def choose_action(args): """Choose action will use and what parameters are used Args: args (dict): All parameters for terminal """ if args.action == 'read_file': file_service.read_file(args.name) elif args.action == 'create_file': file_service.create_file(length_name=args.length, extension=args.extension, content=args.content, letter=bool(args.letters), digit=bool(args.digits)) elif args.action == 'delete_file': file_service.delete_file(args.name) elif args.action == 'get_metadata_file': file_service.get_metadata_file(args.name) else: file_service.evaluate_amount('(f-5)') logger.info('Try again! You choose wrong action')
def app(): while True: try: choice = show_options() if choice == '1': content = enter_content() create_file(content) elif choice == '2': filename = enter_filename() print(read_file(filename)) elif choice == '3': filename = enter_filename() delete_file(filename) elif choice == '4': filename = enter_filename() print(get_metadata(filename)) elif choice == '5': break else: raise InvalidOption except InvalidOption: print_option_error() except FileNotFoundError: print_location_error()
def create_file(): length_name = extension = content = '' letter = digit = True if request.method == 'POST': length_name = int(request.form.get('length', '')) extension = request.form.get('extension', '') content = request.form.get('content', '') letter = True if request.form.get('letter', '') else False digit = True if request.form.get('digit', '') else False file_name = file_service.create_file(length_name=length_name, extension=extension, content=content, letter=letter, digit=digit) flash(f'File: "{file_name}" was created successfully', 'success') logger.info(f'File: "{file_name}" was created successfully') return redirect(url_for('index')) return render_template('create_file.html')
#! /usr/bin/env python3 from file_service import create_file, read_file, delete_file, get_metadata from utils import * if __name__ == '__main__': flag = True while flag: try: choice = show_options() if choice == 1: content = enter_content() create_file(content) elif choice == 2: filename = enter_filename() read_file(filename) elif choice == 3: filename = enter_filename() delete_file(filename) elif choice == 4: filename = enter_filename() get_metadata(filename) elif choice == 5: flag = False else: raise InvalidOption except InvalidOption: print_option_error() continue except FileNotFoundError: print_location_error() continue
def test_get_meta_data1(client): file_name = file_service.create_file(*file_param.values()) resp = client.get(f'/get-meta-data/{file_name}') assert resp.status_code == http.HTTPStatus.FOUND
def test_update_file(client): file_name = file_service.create_file(*file_param.values()) resp = client.get(f'/update/{file_name}') assert resp.status_code == http.HTTPStatus.FOUND