def test_update_config(self): write_config(ORIGINAL_CONFIG) server = ShorthandServer(server_config_path) # Test a valid update update = { 'log_level': 'WARNING', 'frontend': { 'view_history_limit': 500, 'map_tileserver_url': 'https://{s}.site.com/{z}/{x}/{y}.png' } } server.update_config(update) updated_config = server.get_config() assert updated_config['log_level'] == update['log_level'] assert updated_config['frontend'] == update['frontend'] # Test an invalid update bad_update = { 'log_level': 'INVALID' } with pytest.raises(ValueError) as e: server.update_config(bad_update) assert str(e.value) assert updated_config['log_level'] == update['log_level'] assert updated_config['frontend'] == update['frontend']
def show_calendar(): server = ShorthandServer(current_app.config['config_path']) all_directories = ['ALL'] + server.get_subdirs() default_directory = server.get_config().get('default_directory') return render_template('calendar.j2', all_directories=all_directories, default_directory=default_directory, static_content=static_content)
def test_reload_config(self): write_config(ORIGINAL_CONFIG) server = ShorthandServer(server_config_path) # Make a small but valid change to the config, # and ensure it is reflected after reloading new_config = copy.deepcopy(ORIGINAL_CONFIG) new_config['log_level'] = 'warning' write_config(new_config) server.reload_config() assert server.get_config() == clean_and_validate_config(new_config) # Make an invalid change to the config bad_config = copy.deepcopy(new_config) bad_config['log_level'] = 'foobar' write_config(bad_config) with pytest.raises(ValueError) as e: server.reload_config() assert 'Invalid log level' in str(e.value) # Ensure the config is not actually updated assert server.get_config() == clean_and_validate_config(new_config)
def show_glossary(): server = ShorthandServer(current_app.config['config_path']) all_directories = ['ALL'] + server.get_subdirs() default_directory = server.get_config().get('default_directory') tags = server.get_tags() current_app.logger.info('Showing the Definitions search page') return render_template('glossary.j2', all_directories=all_directories, default_directory=default_directory, tags=tags, static_content=static_content)
def show_home_page(): server = ShorthandServer(current_app.config['config_path']) default_directory = server.get_config().get('default_directory') todos = server.get_todos(todo_status='incomplete', directory_filter=default_directory) questions = server.get_questions(question_status='unanswered', directory_filter=default_directory) summary = server.get_calendar() events = [] colors = { 'section': 'black', 'incomplete_todo': 'red', 'completed_todo': 'blue', 'skipped_todo': 'grey', 'question': 'purple', 'answer': 'green', } for year, year_data in summary.items(): for month, month_data in year_data.items(): for day, day_data in month_data.items(): for event in day_data: formatted_event = { 'title': event['event'], 'start': f'{year}-{month}-{day}', 'url': f'/render?path={event["file_path"]}' f'#line-number-{event["line_number"]}', 'type': event['type'] } if formatted_event['type'] in colors.keys(): formatted_event['color'] = colors[ formatted_event['type']] events.append(formatted_event) return render_template('home.j2', num_todos=len(todos), num_questions=len(questions), events=json.dumps(events), static_content=static_content)
def get_server_config(): server = ShorthandServer(current_app.config['config_path']) current_app.logger.info('Returning config') return json.dumps(server.get_config())
def test_get_config(self): write_config(ORIGINAL_CONFIG) server = ShorthandServer(server_config_path) assert server.get_config() == clean_and_validate_config(ORIGINAL_CONFIG)