Skip to content

Commit

Permalink
replace testing_create with fake, for brevity
Browse files Browse the repository at this point in the history
refs #165
  • Loading branch information
guruofgentoo committed Dec 7, 2022
1 parent decd030 commit 747d208
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 154 deletions.
3 changes: 2 additions & 1 deletion docs/source/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ KegElements provides model mixins with helpful default columns and methods::
__tablename__ = 'things'

# id, created_utc, updated_utc provided via mixin
# tests can use Thing.testing_create to get an instance with random data
# tests can use Thing.fake() to get an instance with random data

name = db.Column(db.Unicode(50), nullable=False)
color = db.Column(db.Unicode)
Expand Down Expand Up @@ -121,6 +121,7 @@ breaking changes. This list should provide information on needed app changes.
- 0.8.0
- ``pytest`` removed support for nose-style methods, so base test classes (e.g. ``EntityBase``)
now use ``setup_method`` instead of ``setup``
- MethodsMixin's ``testing_create`` renamed to ``fake`` for brevity
- Bootstrap 4 "horizontal" form templates had been broken and were displaying forms in the
vertical style instead. This has been resolved, which means forms will change to showing with
horizontal layout. If this is not desired, you will need to override the form templates/macros.
Expand Down
8 changes: 4 additions & 4 deletions keg_elements/db/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def pairs(cls, key_field, value_field, order_by=(), query=None,

@kwargs_match_entity
@classmethod
def testing_create(cls, **kwargs):
def fake(cls, **kwargs):
"""Create an object for testing with default data appropriate for the field type
* Will automatically set most field types ignoring those passed in via kwargs.
Expand Down Expand Up @@ -457,7 +457,7 @@ def testing_set_related(cls, kwargs, model,

# generic logic to respect existing kwargs setting on either field
if not {relationship_name, relationship_field} & set(kwargs.keys()):
kwargs[relationship_name] = model.testing_create(
kwargs[relationship_name] = model.fake(
*testing_create_args,
**testing_create_kwargs
)
Expand Down Expand Up @@ -562,9 +562,9 @@ def delete(cls, oid):
@might_commit
@might_flush
@classmethod
def testing_create(cls, *args, _is_deleted=False, **kwargs):
def fake(cls, *args, _is_deleted=False, **kwargs):
kwargs.setdefault('deleted_utc', arrow.utcnow() if _is_deleted else None)
return super().testing_create(*args, **kwargs)
return super().fake(*args, **kwargs)

@staticmethod
def sqla_before_delete_event(mapper, connection, target):
Expand Down
1 change: 1 addition & 0 deletions keg_elements/templates/keg-elements/form-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
{% block page_content_title %}
<h1>{{ title }}</h1>
{% endblock %}
FOO
{% block form %}{% endblock %}
{% endblock %}
6 changes: 3 additions & 3 deletions keg_elements/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setup_method(self):

def test_add(self):
self.ent_delete_all()
o = self.entity_cls.testing_create()
o = self.entity_cls.fake()
assert self.entity_cls.query.count() == 1
if hasattr(self.entity_cls, 'id'):
assert o.id
Expand Down Expand Up @@ -219,9 +219,9 @@ def test_all_columns_are_constraint_tested(self):
)

def check_unique_constraint(self, **kwargs):
self.entity_cls.testing_create(**kwargs)
self.entity_cls.fake(**kwargs)
try:
self.entity_cls.testing_create(**kwargs)
self.entity_cls.fake(**kwargs)
raise AssertionError('Uniqueness error was not encountered.')
except Exception as e:
if not validate_unique_exc(e):
Expand Down
6 changes: 3 additions & 3 deletions keg_elements/tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class TestColumns(object):

def test_testing_create_for_timezone_columns(self):
obj = ents.ColumnTester.testing_create()
obj = ents.ColumnTester.fake()
assert obj.time_zone in pytz.common_timezones

obj.time_zone = 'other'
Expand All @@ -21,7 +21,7 @@ def test_testing_create_for_timezone_columns(self):

def test_encrypted_null(self):
ents.ColumnTester.delete_cascaded()
obj = ents.ColumnTester.testing_create(encrypted1=None, encrypted2=None, encrypted3=None)
obj = ents.ColumnTester.fake(encrypted1=None, encrypted2=None, encrypted3=None)
assert obj.encrypted1 is None
assert obj.encrypted2 is None
assert obj.encrypted3 is None
Expand All @@ -32,7 +32,7 @@ def test_encrypted_null(self):

def test_store_encrypted(self):
ents.ColumnTester.delete_cascaded()
obj = ents.ColumnTester.testing_create(encrypted1='Foo', encrypted2='Bar', encrypted3='Baz')
obj = ents.ColumnTester.fake(encrypted1='Foo', encrypted2='Bar', encrypted3='Baz')
assert obj.encrypted1 == 'Foo'
assert obj.encrypted2 == 'Bar'
assert obj.encrypted3 == 'Baz'
Expand Down

0 comments on commit 747d208

Please sign in to comment.