def test_should_render_backup_rules_matched(self): self.assertTrue(DefaultWriter().render_backup_rules_matched( state='included', rules=backup_rules.flatten_matched(state='included', rules=mock_data.BACKUP_RULES))) self.assertTrue(DefaultWriter().render_backup_rules_matched( state='excluded', rules=backup_rules.flatten_matched(state='excluded', rules=mock_data.BACKUP_RULES)))
def test_should_render_matched_rules_as_table(self): header_size = 3 # header border (x2) + header footer_size = 3 # footer border (x2) + footer table = render_matched_rules_as_table( state='included', rules=flatten_matched(state='included', rules=mock_data.BACKUP_RULES) ) self.assertEqual(len(table.split('\n')), header_size + len(mock_data.BACKUP_RULES['included']) + footer_size) table = render_matched_rules_as_table( state='excluded', rules=flatten_matched(state='excluded', rules=mock_data.BACKUP_RULES) ) self.assertEqual(len(table.split('\n')), header_size + len(mock_data.BACKUP_RULES['excluded']) + footer_size)
def show_rules(ctx, state): """Show configured backup rules.""" spec = backup_rules.get_spec_unmatched() if state == 'unmatched' else backup_rules.get_spec_matched() fields = spec['fields'] default_sorting = spec['sorting'] default_sorting = Sorting(field=default_sorting['field'], ordering=default_sorting['ordering']) filtering = ctx.obj.filtering sorting = ctx.obj.sorting rules = ctx.obj.api.backup_rules() if state == 'unmatched': rules = backup_rules.flatten_unmatched(rules) rules = filtering.apply(rules, fields) if filtering else rules rules = (sorting or default_sorting).apply(rules, fields) click.echo(ctx.obj.rendering.render_backup_rules_unmatched(rules)) else: rules = backup_rules.flatten_matched(state, rules) rules = filtering.apply(rules, fields) if filtering else rules rules = (sorting or default_sorting).apply(rules, fields) click.echo(ctx.obj.rendering.render_backup_rules_matched(state, rules))
def test_should_flatten_matched_and_excluded_backup_rules(self): for rule in flatten_matched(state='excluded', rules=mock_data.BACKUP_RULES): for key in self.expected_matched_keys: self.assertIn(key, rule) self.assertFalse(isinstance(rule[key], dict), 'for key [{}]'.format(key)) self.assertFalse(isinstance(rule[key], list), 'for key [{}]'.format(key))