Commit 2272a26f authored by dmitry.mashoshin's avatar dmitry.mashoshin
Browse files

Merge branch 'andrey/pop_model' into 'master'

Add pop method to models to remove fields data

See merge request !46
parents b013f881 2d0d8518
......@@ -228,3 +228,6 @@ class Model(metaclass=ModelMeta):
def get(self, key, default=None):
return getattr(self, key, default)
def pop(self, key, default=None):
return self.__data.pop(key, default)
......@@ -811,3 +811,27 @@ def test_import_data_errors_nested_case():
assert e == {"c": "Unknown field"}
def test_pop_field_data_from_model():
class A(Model):
a = StringType()
b = StringType()
obj = A({'a': 'test_a', 'b': 'test_b'})
obj.pop('a')
primitive_obj = obj.to_primitive()
assert obj.a is None
assert 'a' not in primitive_obj
def test_pop_incorrect_field_data_from_model():
class A(Model):
a = StringType()
b = StringType()
obj = A({'a': 'test_a', 'b': 'test_b'})
obj.pop('c')
primitive_obj = obj.to_primitive()
assert obj.a == 'test_a'
assert 'a' in primitive_obj
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment