Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
stuart-bradley committed Nov 9, 2020
1 parent 5737e23 commit d08f51d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drf_react_template/schema_form_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
SCHEMA_OVERRIDE_KEY = 'schema:override'
UI_SCHEMA_OVERRIDE_KEY = 'uiSchema:override'
COLUMN_PROCESSOR_OVERRIDE_KEY = 'column:override'
OVERRIDE_KEYS = {
SCHEMA_OVERRIDE_KEY,
UI_SCHEMA_OVERRIDE_KEY,
COLUMN_PROCESSOR_OVERRIDE_KEY,
}

DEPENDENCY_SIMPLE_KEY = 'schema:dependencies:simple'
DEPENDENCY_CONDITIONAL_KEY = 'schema:dependencies:conditional'
DEPENDENCY_DYNAMIC_KEY = 'schema:dependencies:dynamic'
Expand All @@ -24,10 +30,9 @@
DEPENDENCY_DYNAMIC_KEY,
DEPENDENCY_OVERRIDE_KEY,
}

STYLE_KEYS_TO_IGNORE = {
SCHEMA_OVERRIDE_KEY,
UI_SCHEMA_OVERRIDE_KEY,
COLUMN_PROCESSOR_OVERRIDE_KEY,
*OVERRIDE_KEYS,
*DEPENDENCY_KEYS,
}

Expand Down Expand Up @@ -381,7 +386,9 @@ def _get_ui_field_properties(
result['ui:widget'] = widget
if help_text:
result['ui:help'] = help_text
result.update(field.style)
result.update(
{k: v for k, v in field.style.items() if k not in STYLE_KEYS_TO_IGNORE}
)
return result

def _get_all_ui_properties(self) -> Dict[str, Any]:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_schema_form_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ class SchemaSimpleUnidirectionalDependencySerializer(ChoiceSerializer):
).get_schema()
assert 'votes' not in result['required']
assert 'votes' in result['dependencies']['choice_text']
ui_result = UiSchemaProcessor(
SchemaSimpleUnidirectionalDependencySerializer(), {}
).get_ui_schema()
assert DEPENDENCY_SIMPLE_KEY not in ui_result['votes']


def test_choice_schema_simple_bidirectional_dependency():
Expand All @@ -282,6 +286,11 @@ class SchemaSimpleBidirectionalDependencySerializer(ChoiceSerializer):
assert 'choice_text' not in result['required']
assert 'votes' in result['dependencies']['choice_text']
assert 'choice_text' in result['dependencies']['votes']
ui_result = UiSchemaProcessor(
SchemaSimpleBidirectionalDependencySerializer(), {}
).get_ui_schema()
assert DEPENDENCY_SIMPLE_KEY not in ui_result['votes']
assert DEPENDENCY_SIMPLE_KEY not in ui_result['choice_text']


def test_choice_schema_conditional_dependency(choice_conditional_dependency_votes):
Expand All @@ -296,6 +305,10 @@ class SchemaConditionalDependencySerializer(ChoiceSerializer):
assert result['dependencies'] == {
'choice_text': choice_conditional_dependency_votes
}
ui_result = UiSchemaProcessor(
SchemaConditionalDependencySerializer(), {}
).get_ui_schema()
assert DEPENDENCY_CONDITIONAL_KEY not in ui_result['choice_text']


def test_choice_schema_dynamic_dependency(choice_dynamic_dependency_votes):
Expand All @@ -308,6 +321,10 @@ class SchemaDynamicDependencySerializer(ChoiceSerializer):

result = SchemaProcessor(SchemaDynamicDependencySerializer(), {}).get_schema()
assert result['dependencies'] == choice_dynamic_dependency_votes
ui_result = UiSchemaProcessor(
SchemaDynamicDependencySerializer(), {}
).get_ui_schema()
assert DEPENDENCY_DYNAMIC_KEY not in ui_result['choice_text']


def test_choice_schema_dynamic_dependency_non_enum_field():
Expand Down

0 comments on commit d08f51d

Please sign in to comment.