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

Housekeeping #495

Merged
merged 6 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Avoid using setattr with constant attribute value
flake8-bugbear suggests:
Do not call setattr with a constant attribute value, it is not
any safer than normal property access.

The new version is also easier to read.

This also adds a missing test for the related lines of code.
  • Loading branch information
marcofucci committed Jul 4, 2019
commit 4d82338f306f65e0e298d3aa3fa3449eb61067ef
2 changes: 1 addition & 1 deletion mtp_cashbook/apps/disbursements/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def clean(self):
self.add_error(upper, forms.ValidationError(msg, code='bound_ordering'))
return self.cleaned_data

setattr(cls, 'clean', clean)
cls.clean = clean
return cls

return inner
Expand Down
16 changes: 16 additions & 0 deletions mtp_cashbook/apps/disbursements/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,19 @@ def test_date_options(self):
description = form.search_description
self.assertTrue(description['has_filters'])
self.assertIn('date confirmed before 10 Jan 2018', strip_tags(description['description']))

def test_invalid_date_options(self):
form = SearchForm(
request=None,
data={
'date_filter': 'created',
'date__gte': '11/01/18',
'date__lt': '10/01/2018',
}
)
self.assertFalse(form.is_valid())
errors = form.errors.as_data()
self.assertEqual(
[error.message for error in errors['date__lt']],
['Must be after the ‘from’ date']
)