"""test_paypal_types.py - Unit tests for common PayPal API classes"""
# Copyright © 2020  Brett Smith
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import itertools

from decimal import Decimal

import pytest
from . import FLOAT_NUMBERS, WHOLE_NUMBERS

from paypal_rest import paypal_types

@pytest.mark.parametrize('number,currency', itertools.product(
    FLOAT_NUMBERS, ['USD', 'INR'],
))
def test_float_amount_from_api(number, currency):
    source = {'value': number, 'currency_code': currency}
    actual = paypal_types.Amount.from_api(source)
    assert actual.number == Decimal(number)
    assert actual.currency == currency

@pytest.mark.parametrize('number,currency', itertools.product(
    WHOLE_NUMBERS, ['JPY', 'CLP'],
))
def test_whole_amount_from_api(number, currency):
    source = {'value': number, 'currency_code': currency}
    actual = paypal_types.Amount.from_api(source)
    assert actual.number == int(number)
    assert actual.currency == currency
