Skip to content

Commit

Permalink
Fix: raise ValueError when manipulating an empty form
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Aug 13, 2024
1 parent 3b8444e commit 92822c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bddrest/authoring/given.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def when(self, *args, record=True, **kwargs):
# Checking for dictionary manipulators if any
for k, v in kwargs.items():
if isinstance(v, Manipulator):
basevalue = getattr(self.base_call, k)
if basevalue is None:
raise ValueError(f'{k} argument is not given yet')
clone = getattr(self.base_call, k).copy()
v.apply(clone)
kwargs[k] = clone
Expand Down
14 changes: 14 additions & 0 deletions tests/test_form_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def test_append_form_field():
email='user@example.com'
)

call = dict(
title='test add form field',
url='/apiv1/devices/name: SM-12345678/id: 1',
verb='POST',
)
with Given(wsgi_application, **call):
with pytest.raises(ValueError):
when('Appending a field to an empty form',
form=Append('email', 'foo@bar.baz'))


def test_remove_from_fields():
call = dict(
Expand All @@ -63,6 +73,10 @@ def test_remove_from_fields():
when('Removing fields', form=Remove('email', 'phone'))
assert response.json == dict(activationCode='746727')

with pytest.raises(ValueError):
when('Removing a field from an empty form',
json=Remove('email', 'phone'))

with pytest.raises(ValueError):
Remove('a').apply(['b', 'c'])

Expand Down

0 comments on commit 92822c2

Please sign in to comment.