https://codereview.appspot.com/41350043/diff/1/quickstart/models/fields.py#newcode164
quickstart/models/fields.py:164: return self.default
So it is not possible to have an empty string as a field value? I've
seen systems with that policy before and it come back to bite them in
the long run. However, it looks like we're already there so I'm not
sure it is something we should address right this minute.
https://codereview.appspot.com/41350043/diff/1/quickstart/tests/models/test_envs.py#newcode641
quickstart/tests/models/test_envs.py:641: self.assertEqual(expected,
obtained)
One of my personal preferences, for your consideration: I try to avoid
variable names in tests like "expected" and "obtained" and instead try
to communicate more about the values held. For example, above I might
call them "valid_pairs" and "mapped_pairs". That way the assertion says
more about the truth the test is trying to get at:
self.assertEqual(mapped_pairs, valid_pairs)
Note that making the asserts read this way generally means the
"obtained" value is the first argument and the "expected" argument is
second. Python's test infrastructure is fine with this, but we have to
make sure any test-specific assertion helpers are too.
# To be valid, env_data must include the required values.
env_data = {'string-required': 'a string'}
validation_errors = envs.validate(self.env_metadata, env_data)
# No validation errors were found.
self.assertEqual(validation_errors, {})
Another thing was that the phrase "at least" primed me to expect the
test to be demonstrating invalid data instead of valid.
https://codereview.appspot.com/41350043/diff/1/quickstart/tests/models/test_envs.py#newcode741
quickstart/tests/models/test_envs.py:741: 'string-default': '\t another
one',
Changing the values by removing whitespace makes me nervous. Maybe for
the kinds of values we deal with it is OK, but I've been bitten by this
more than once. It seems better to me to let the occasional user screw
up with whitespace than to prevent another user from doing what they wan
to do (like having a multi-line config value).
https://codereview.appspot.com/41350043/diff/1/quickstart/tests/models/test_envs.py#newcode776
quickstart/tests/models/test_envs.py:776: # Since this value is the
default one, the field is excluded.
Given that defaults can change over time, I would be cautious about
implicitly removing default values that the user had explicitly
provided. If they provided a value we should assume they want to avoid
depending on the default.
This branch looks good. None of my comments are blockers, more like
"things you might like to consider", so this LGTM.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ models/ fields. py models/ fields. py (right):
File quickstart/
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ models/ fields. py#newcode128 models/ fields. py:128: return super(StringField, (value or None)
quickstart/
self).normalize
If the given value is the empty string then None will be passed to
.normalize and he default will be returned. That doesn't sound right.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ models/ fields. py#newcode164 models/ fields. py:164: return self.default
quickstart/
So it is not possible to have an empty string as a field value? I've
seen systems with that policy before and it come back to bite them in
the long run. However, it looks like we're already there so I'm not
sure it is something we should address right this minute.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py tests/models/ test_envs. py (right):
File quickstart/
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode514 tests/models/ test_envs. py:514: # The local environment
quickstart/
metadata is correctly returned.
It would be nice to expand "correctly returned" to describe a little
more what that means.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode526 tests/models/ test_envs. py:526: # The ec2 environment metadata
quickstart/
is correctly returned.
Same comment for "correctly returned" as above.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode641 tests/models/ test_envs. py:641: self.assertEqua l(expected, l(mapped_ pairs, valid_pairs)
quickstart/
obtained)
One of my personal preferences, for your consideration: I try to avoid
variable names in tests like "expected" and "obtained" and instead try
to communicate more about the values held. For example, above I might
call them "valid_pairs" and "mapped_pairs". That way the assertion says
more about the truth the test is trying to get at:
self.assertEqua
Note that making the asserts read this way generally means the
"obtained" value is the first argument and the "expected" argument is
second. Python's test infrastructure is fine with this, but we have to
make sure any test-specific assertion helpers are too.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode650 tests/models/ test_envs. py:650: self.assertEqua l(help,
quickstart/
field.help)
I suspect you intended to pass field.name as the third argument to this
assert too.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode689 tests/models/ test_envs. py:689: self.assertEqua l({}, self.env_ metadata, env_data))
quickstart/
envs.validate(
It took me a while to understand this test. Something like this might
have helped:
# To be valid, env_data must include the required values. self.env_ metadata, env_data) l(validation_ errors, {})
env_data = {'string-required': 'a string'}
validation_errors = envs.validate(
# No validation errors were found.
self.assertEqua
Another thing was that the phrase "at least" primed me to expect the
test to be demonstrating invalid data instead of valid.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode741 tests/models/ test_envs. py:741: 'string-default': '\t another
quickstart/
one',
Changing the values by removing whitespace makes me nervous. Maybe for
the kinds of values we deal with it is OK, but I've been bitten by this
more than once. It seems better to me to let the occasional user screw
up with whitespace than to prevent another user from doing what they wan
to do (like having a multi-line config value).
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode776 tests/models/ test_envs. py:776: # Since this value is the
quickstart/
default one, the field is excluded.
Given that defaults can change over time, I would be cautious about
implicitly removing default values that the user had explicitly
provided. If they provided a value we should assume they want to avoid
depending on the default.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_envs. py#newcode785 tests/models/ test_envs. py:785: # reason the field is
quickstart/
excluded.
This is very nicely commented.
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_fields. py tests/models/ test_fields. py (right):
File quickstart/
https:/ /codereview. appspot. com/41350043/ diff/1/ quickstart/ tests/models/ test_fields. py#newcode318 tests/models/ test_fields. py:318: # If the field is not
quickstart/
required no errors are raised.
Since you used a comma in the comment for the next test, you probably
intended to have one here too.
https:/ /codereview. appspot. com/41350043/