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

Add validation for 'Verify win' stage of investment projects #286

Merged
merged 15 commits into from
Jul 6, 2017

Conversation

reupen
Copy link
Contributor

@reupen reupen commented Jul 5, 2017

This also changes how the validation works so it's simple and more maintainable.

@reupen reupen requested review from canni and elcct July 5, 2017 16:04
@codecov-io
Copy link

codecov-io commented Jul 5, 2017

Codecov Report

Merging #286 into develop will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop    #286      +/-   ##
==========================================
- Coverage     92.9%   92.9%   -0.01%     
==========================================
  Files           60      60              
  Lines         2214    2198      -16     
  Branches       200     193       -7     
==========================================
- Hits          2057    2042      -15     
  Misses         133     133              
+ Partials        24      23       -1
Impacted Files Coverage Δ
datahub/investment/serializers.py 99.01% <100%> (ø) ⬆️
datahub/investment/validate.py 100% <100%> (+1.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a17019...acd8ea8. Read the comment docs.

@@ -11,6 +11,11 @@
logger = getLogger(__name__)


def is_falsey(val):
"""Returns True if bool(val) is False"""
return not val
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RLY, why not a plain lambda? ;]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY? 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe run everywhere s/if not (.+):/if is_falsey($1)/ ;]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operator.not_() did the same thing, so it's gone now.

@@ -52,11 +52,11 @@
'non_fdi_type':
CondValRule('investment_type', InvestmentType.non_fdi.value.id, Phase.prospect.value),
'total_investment':
CondValRule('client_cannot_provide_total_investment', is_falsey, Phase.assign_pm.value),
CondValRule('client_cannot_provide_total_investment', not_, Phase.assign_pm.value),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@reupen reupen merged commit 104ae4e into develop Jul 6, 2017
@reupen reupen deleted the feature/investment-verify-win-validation branch July 6, 2017 11:05
'address_line_postcode': 'This field is required.',
'average_salary': 'This field is required.',
'client_cannot_provide_foreign_investment': 'This field is required.',
'foreign_equity_investment': 'This field is required.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to repeat This field is required. like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean – what is your suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way it doesn't immediately tells that the responses are identical. I would either use constant REQUIRED_MESSAGE or create a variable this_field_is_required and assert against it.
For example:

...
'address_line_postcode': REQUIRED_MESSAGE,
'average_salary': REQUIRED_MESSAGE,
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make much difference to me, but I kinda like seeing the output as is in tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it hints that maybe one of the responses is different than the others in a subtle way (for example missing dot or a typo), which you can't tell without looking more closely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants