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

Fixes for single currency form, templatetags and tests refactoring #78

Merged
merged 23 commits into from
Jul 5, 2019

Conversation

krzysztofwolski
Copy link
Contributor

@krzysztofwolski krzysztofwolski commented Jul 3, 2019

Updated:

  • available_currencies is now a list of currency codes
  • FixedCurrencyWidget is now using always 2 widgets (hidden one for currency)
  • When form field is optional and the amount is empty, None is returned
  • splitted tests into separate files. Only new tests in test_forms

tests/forms.py Outdated Show resolved Hide resolved
django_prices/forms.py Outdated Show resolved Hide resolved
django_prices/forms.py Outdated Show resolved Hide resolved
assert 'name="price_1"' in result
assert 'key="value"' in result
assert 'value="5"' in result
assert "USD" in result
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this could be tested with snapshot?

Also consider changing tests names to descriptive ones, eg test_money_input_widget_renders

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 about adding snapshottest for one or two tests. I would say it's good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#80

tests/test_forms.py Outdated Show resolved Hide resolved
tests/test_forms.py Outdated Show resolved Hide resolved
tests/test_templatetags.py Outdated Show resolved Hide resolved
# https://github.com/python-babel/babel/issues/30
translation.activate("oO_Oo")
amount = prices_i18n.amount(money_fixture, format="html")
assert amount # No exception, success!
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a noop. It does not test anything as any exception would be raised in the previous line. Why don't you instead document what the result should be with a snapshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not the original author of this test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#80

Copy link
Contributor

@patrys patrys left a comment

Choose a reason for hiding this comment

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

Since we now explicitly depend on Babel, I don't think it makes sense to support the non-i18n-aware version of the template tags. Can we move the i18n ones to prices and have prices_i18n call the ones from prices with a deprecation warning?

README.md Outdated Show resolved Hide resolved
django_prices/forms.py Outdated Show resolved Hide resolved
django_prices/forms.py Outdated Show resolved Hide resolved
if amount in self.empty_values and self.required:
raise ValidationError("Enter a valid amount of money")
if currency in self.empty_values and self.required:
raise ValidationError("Enter a valid currency code")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do users enter a currency code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's for those who use custom widgets.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm asking about the wording: "Enter a valid currency code" vs "Select a valid currency" as the currency is unlikely to be something entered (typed into the field) directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This occurs when somebody uses fixed currency form and submits (by example using curl) intentionally different value.
Currency Field in multicurrency form has its own validation.

django_prices/validators.py Outdated Show resolved Hide resolved
@krzysztofwolski krzysztofwolski requested a review from patrys July 4, 2019 15:27
@krzysztofwolski krzysztofwolski changed the title Fixes for single currency form Fixes for single currency form, templatetags and tests refactoring Jul 4, 2019
django_prices/forms.py Show resolved Hide resolved
django_prices/forms.py Show resolved Hide resolved
django_prices/templatetags/prices_i18n.py Outdated Show resolved Hide resolved
pattern = locale.currency_formats.get("standard").pattern

if html:
pattern = re.sub("(\xa4+)", '<span class="currency">\\1</span>', pattern)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe-ish putting the currency code somewhere in there may be useful? data-currency="USD".

tests/test_forms.py Outdated Show resolved Hide resolved
tests/test_forms.py Outdated Show resolved Hide resolved
tests/test_forms.py Outdated Show resolved Hide resolved
@krzysztofwolski krzysztofwolski requested a review from rafalp July 5, 2019 09:23
@krzysztofwolski
Copy link
Contributor Author

@patrys Rebased! Can be released as alpha 🎉

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.

5 participants