Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Tests for some call target attribute weirdness #598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion iommi/form__tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3447,12 +3447,14 @@ def test_initial_is_set_to_default_of_model():


def test_shoot_config_into_auto_dunder_field():
Form(
form = Form(
auto__model=FieldFromModelOneToOneTest,
# attr `foo_one_to_one__foo` creates a field named `foo_one_to_one_foo`. Note that the `__` is collapsed to one `_`!
auto__include=['foo_one_to_one__foo'],
fields__foo_one_to_one_foo__display_name='bar',
).bind(request=req('get'))
assert set(keys(form.fields)) == {'foo_one_to_one_foo'}
assert form.fields.foo_one_to_one_foo.display_name == 'foo'


@pytest.mark.django_db
Expand Down Expand Up @@ -3899,3 +3901,29 @@ def test_extra_is_create():

foo = Form.edit(auto__model=Foo).bind()
assert foo.extra.is_create is False


def test_call_target__attribute():
class FooForm(Form):
class Meta:
auto__model = Foo
auto__include = ['foo']
fields__foo__call_target__attribute = 'hardcoded' # this raises exception
# fields__foo__input__call_target__attribute = 'radio' # this doesn't work, stays as select2
fields__foo__parsed_data = 123

form = FooForm().bind(request=req('post', foo='456'))
assert form.fields.foo.value == 123


def test_shoot_config_into_related_field():
class FooForm(Form):
class Meta:
auto__model = Bar
auto__include = ['foo__foo']
fields__foo_foo__call_target__attribute = 'hardcoded' # this raises exception
fields__foo_foo__parsed_data = 123

form = FooForm().bind(request=req('post', foo='456'))
assert form.fields.foo_foo.iommi_shortcut_stack == ['hardcoded']
assert form.fields.foo_foo.value == 123
Loading