Skip to content

Commit

Permalink
edit method errors out on invalid field name
Browse files Browse the repository at this point in the history
refs #169
  • Loading branch information
guruofgentoo committed Mar 4, 2022
1 parent 639bcb8 commit 98ad0b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions keg_elements/db/mixins.py
Expand Up @@ -189,6 +189,7 @@ def delete_cascaded(cls):

@might_commit
@might_flush
@kwargs_match_entity
@classmethod
def edit(cls, oid=None, **kwargs):
"""Edit an object in session with the kwargs, and optionally flush or commit.
Expand Down
9 changes: 9 additions & 0 deletions keg_elements/tests/test_db_mixins.py
Expand Up @@ -219,6 +219,15 @@ def test_check_kwargs_in_testing_create(self):

ents.Thing.testing_create(foo=1, bar=2, _baz=3, name='b', _check_kwargs=False)

def test_check_kwargs_in_edit(self):
thing = ents.Thing.testing_create(name='a')
with pytest.raises(AssertionError) as excinfo:
ents.Thing.edit(thing.id, fieldshouldnotexist='foo')
assert str(excinfo.value) == \
'Unknown column or relationship names in kwargs: [\'fieldshouldnotexist\']'

ents.Thing.edit(thing.id, fieldshouldnotexist='foo', _check_kwargs=False)

def test_testing_create_flush_and_commit(self):
obj = ents.Thing.testing_create(_flush=False, _commit=False)
assert sa.inspect(obj).pending
Expand Down
1 change: 1 addition & 0 deletions keg_elements/tests/test_forms/test_form.py
Expand Up @@ -1019,6 +1019,7 @@ def test_coerce_formdata(self):
class TestRelationshipFieldGenerator:
def setup(self):
ents.Thing.delete_cascaded()
db.session.expunge_all()

def create_form(self, **kwargs):
class RelatedThingForm(ModelForm):
Expand Down

0 comments on commit 98ad0b0

Please sign in to comment.