<s> """<STR_LIT>""" <EOL> from decimal import Decimal <EOL> import moneyed <EOL> import pytest <EOL> from moneyed import Money <EOL> from . testapp . forms import ( <EOL> MoneyForm , <EOL> MoneyFormMultipleCurrencies , <EOL> MoneyModelForm , <EOL> OptionalMoneyForm , <EOL> ) <EOL> from . testapp . models import ModelWithVanillaMoneyField <EOL> pytestmark = pytest . mark . django_db <EOL> def test_save ( ) : <EOL> money = Money ( Decimal ( '<STR_LIT>' ) , moneyed . SEK ) <EOL> form = MoneyModelForm ( { '<STR_LIT>' : money . amount , '<STR_LIT>' : money . currency } ) <EOL> assert form . is_valid ( ) <EOL> instance = form . save ( ) <EOL> retrieved = ModelWithVanillaMoneyField . objects . get ( pk = instance . pk ) <EOL> assert money == retrieved . money <EOL> def test_validate ( ) : <EOL> money = Money ( Decimal ( '<STR_LIT>' ) , moneyed . SEK ) <EOL> form = MoneyForm ( { '<STR_LIT>' : money . amount , '<STR_LIT>' : money . currency } ) <EOL> assert form . is_valid ( ) <EOL> result = form . cleaned_data [ '<STR_LIT>' ] <EOL> assert result == money <EOL> @ pytest . mark . parametrize ( <EOL> '<STR_LIT:data>' , <EOL> ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : moneyed . SEK } , <EOL> { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : moneyed . SEK } , <EOL> { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : moneyed . SEK } , <EOL> { '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : moneyed . EUR } <EOL> ) <EOL> ) <EOL> def test_form_is_invalid ( data ) : <EOL> assert not MoneyForm ( data ) . is_valid ( ) <EOL> @ pytest . mark . parametrize ( <EOL> '<STR_LIT>' , <EOL> ( <EOL> ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : moneyed . SEK } , [ ] ) , <EOL> ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : moneyed . SEK } , [ '<STR_LIT>' ] ) , <EOL> ) <EOL> ) <EOL> def test_changed_data ( data , result ) : <EOL> assert MoneyForm ( data ) . changed_data == result <EOL> def test_change_currency_not_amount ( ) : <EOL> """<STR_LIT>""" <EOL> form = MoneyFormMultipleCurrencies ( <EOL> { '<STR_LIT>' : Decimal ( <NUM_LIT:10> ) , '<STR_LIT>' : moneyed . EUR } , <EOL> initial = { '<STR_LIT>' : Money ( Decimal ( <NUM_LIT:10> ) , moneyed . SEK ) } <EOL> ) <EOL> assert form . changed_data == [ '<STR_LIT>' ] <EOL> @ pytest . mark . parametrize ( <EOL> '<STR_LIT>' , <EOL> ( <EOL> ( { '<STR_LIT>' : moneyed . SEK } , True ) , <EOL> ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : moneyed . SEK } , True ) , <EOL> ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : moneyed . SEK } , False ) , <EOL> ) <EOL> ) <EOL> def test_optional_money_form ( data , result ) : <EOL> """<STR_LIT>""" <EOL> assert OptionalMoneyForm ( data ) . is_valid ( ) is result </s>
