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

test: Add update custom form test #7065

Merged
merged 1 commit into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app/models/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def get_set_field_name(target: CustomForms) -> str:


@listens_for(CustomForms, 'before_insert')
@listens_for(CustomForms, 'before_update')
def generate_name(mapper, connect, target: CustomForms) -> None:
get_set_field_name(target)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ def test_override_custom_form_name(db):
assert custom_custom_form.name == 'Portable Number'


def test_edit_custom_form(db):
event = EventFactoryBasic()
overridden_custom_form = CustomForms(
event=event,
field_identifier='shippingAddress',
name='Home Address',
form='attendee',
type='text',
)
db.session.commit()

assert overridden_custom_form.name == 'Shipping Address'

overridden_custom_form.name = 'Daddy Address'
db.session.commit()

assert overridden_custom_form.name == 'Shipping Address'


def test_assigning_old_form_name(db):
event = EventFactoryBasic()
speaker_custom_form = CustomForms(
Expand All @@ -54,25 +73,25 @@ def test_assigning_old_form_name(db):
event=event, field_identifier='longAbstract', form='session', type='text'
)
none_custom_form = CustomForms(
event=event, field_identifier='showNumber', form='attendee', type='text'
event=event, field_identifier='showNumber', name='Show Number', form='attendee', type='text'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (100 > 90 characters)

)
db.session.commit()

assert speaker_custom_form.name == 'Speaking Experience'
assert none_custom_form.name is None
assert none_custom_form.name == 'Show Number'

db.session.execute('update custom_forms set name = null')
db.session.execute("update custom_forms set name = 'None'")
db.session.commit()

db.session.refresh(speaker_custom_form)
db.session.refresh(attendee_custom_form)
db.session.refresh(session_custom_form)
db.session.refresh(none_custom_form)

assert speaker_custom_form.name is None
assert attendee_custom_form.name is None
assert session_custom_form.name is None
assert none_custom_form.name is None
assert speaker_custom_form.name == 'None'
assert attendee_custom_form.name == 'None'
assert session_custom_form.name == 'None'
assert none_custom_form.name == 'None'

assign_field_names(db.session)

Expand All @@ -84,4 +103,5 @@ def test_assigning_old_form_name(db):
assert speaker_custom_form.name == 'Speaking Experience'
assert attendee_custom_form.name == 'Tax Business Info'
assert session_custom_form.name == 'Long Abstract'
assert none_custom_form.name is None
# cannot restore custom form field name
assert none_custom_form.name == 'None'