Пример #1
0
def test_exchange_errors():
    with pytest.raises(TypeError):
        revolut.exchange(from_amount="100 EUR", to_currency="EUR")

    with pytest.raises(TypeError):
        revolut.exchange(from_amount=100, to_currency="EUR")

    with pytest.raises(KeyError):
        eur_to_unknown = Amount(real_amount=100, currency="EUR")
        revolut.exchange(from_amount=eur_to_unknown, to_currency="UNKNOWN")

    with pytest.raises(ConnectionError):
        # Should return a status code 400
        one_million_euros = Amount(real_amount=1000000, currency="EUR")
        revolut.exchange(from_amount=one_million_euros, to_currency="BTC")

    with pytest.raises(ConnectionError):
        # Should return a status code 422 for insufficient funds
        ten_thousands_euros = Amount(real_amount=10000, currency="AUD")
        revolut.exchange(from_amount=ten_thousands_euros, to_currency="BTC")

    with pytest.raises(ConnectionError):
        # Should return a status code 400 because from and to currencies
        # must be different
        ten_thousands_euros = Amount(real_amount=1, currency="EUR")
        revolut.exchange(from_amount=ten_thousands_euros, to_currency="EUR")

    with pytest.raises(ConnectionError):
        # Should return a status code 400 because the amount must be > 0
        ten_thousands_euros = Amount(real_amount=1, currency="EUR")
        revolut.exchange(from_amount=ten_thousands_euros, to_currency="EUR")
Пример #2
0
def test_quote():
    eur_to_btc = Amount(real_amount=5508.85, currency="EUR")
    quote_eur_btc = revolut.quote(from_amount=eur_to_btc, to_currency="BTC")
    assert type(quote_eur_btc) == Amount
    print()
    print('{} => {}'.format(eur_to_btc, eur_to_btc))

    btc_to_eur = Amount(real_amount=1, currency="BTC")
    quote_btc_eur = revolut.quote(from_amount=btc_to_eur, to_currency="EUR")
    assert type(quote_btc_eur) == Amount
    print('{} => {}'.format(btc_to_eur, quote_btc_eur))
Пример #3
0
def test_class_Amount_errors():
    with pytest.raises(KeyError):
        Amount(revolut_amount=100, currency="UNKNOWN")

    with pytest.raises(TypeError):
        Amount(revolut_amount="abc", currency="BTC")

    with pytest.raises(TypeError):
        Amount(real_amount="def", currency="EUR")

    with pytest.raises(ValueError):
        Amount(currency="BTC")
Пример #4
0
def test_class_Amount():
    amount = Amount(revolut_amount=100, currency="EUR")
    assert amount.real_amount == 1
    assert str(amount) == "1.00 EUR"

    amount = Amount(real_amount=1, currency="EUR")
    assert amount.revolut_amount == 100
    assert str(amount) == "1.00 EUR"

    amount = Amount(revolut_amount=100000000, currency="BTC")
    assert amount.real_amount == 1
    assert str(amount) == "1.00000000 BTC"
Пример #5
0
def test_class_Transaction():
    transaction = Transaction(from_amount=Amount(real_amount=10,
                                                 currency="USD"),
                              to_amount=Amount(real_amount=8.66,
                                               currency="EUR"),
                              date=datetime.strptime("10/07/18 16:30",
                                                     "%d/%m/%y %H:%M"))

    assert type(transaction) == Transaction
    assert str(transaction) == "(10/07/2018 16:30:00) 10.00 USD => 8.66 EUR"
    print()
    print(transaction)
Пример #6
0
def dict_transaction_to_Transaction(tr_dict):
    """ Converts a transaction dictionnary to a Transaction object """
    if set(tr_dict) != set(_CSV_COLUMNS):
        raise TypeError("Columns expected : {}\n{} received".format(
            _CSV_COLUMNS, list(tr_dict)))
    str_date = "{} {}".format(tr_dict["date"], tr_dict["hour"])
    tr = Transaction(from_amount=Amount(real_amount=float(
        tr_dict["from_amount"]),
                                        currency=tr_dict["from_currency"]),
                     to_amount=Amount(real_amount=float(tr_dict["to_amount"]),
                                      currency=tr_dict["to_currency"]),
                     date=datetime.strptime(str_date, "%d/%m/%Y %H:%M:%S"))
    return tr
Пример #7
0
def test_class_account():
    account = Account(account_type="CURRENT",
                      balance=Amount(real_amount=200.85, currency="EUR"),
                      state="ACTIVE",
                      vault_name="")
    assert account.name == "EUR CURRENT"
    assert str(account) == "EUR CURRENT : 200.85 EUR"

    vault = Account(account_type="SAVINGS",
                    balance=Amount(real_amount=150.35, currency="USD"),
                    state="ACTIVE",
                    vault_name="My vault")
    assert vault.name == "USD SAVINGS (My vault)"
    assert str(vault) == "USD SAVINGS (My vault) : 150.35 USD"
Пример #8
0
def test_class_Transaction_errors():
    with pytest.raises(TypeError):
        Transaction(from_amount="10 USD",
                    to_amount=Amount(real_amount=8.66, currency="EUR"),
                    date=datetime.strptime("10/07/18 16:30", "%d/%m/%y %H:%M"))

    with pytest.raises(TypeError):
        Transaction(from_amount=Amount(real_amount=10, currency="USD"),
                    to_amount="8.66 EUR",
                    date=datetime.strptime("10/07/18 16:30", "%d/%m/%y %H:%M"))

    with pytest.raises(TypeError):
        Transaction(from_amount=Amount(real_amount=10, currency="USD"),
                    to_amount=Amount(real_amount=8.66, currency="EUR"),
                    date="10/07/18 16:30")
Пример #9
0
def test_convert_Transaction_to_dict():
    transaction = Transaction(from_amount=Amount(real_amount=10,
                                                 currency="USD"),
                              to_amount=Amount(real_amount=8.66,
                                               currency="EUR"),
                              date=datetime.strptime("10/07/18 16:30",
                                                     "%d/%m/%y %H:%M"))
    tr_dict = revolut_bot.convert_Transaction_to_dict(transaction)
    assert tr_dict == {
        'date': '10/07/2018',
        'from_amount': 10.0,
        'from_currency': 'USD',
        'hour': '16:30:00',
        'to_amount': 8.66,
        'to_currency': 'EUR'
    }
Пример #10
0
def test_get_amount_with_margin_errors():
    with pytest.raises(TypeError):
        revolut_bot.get_amount_with_margin(amount=10, percent_margin=1)
    with pytest.raises(TypeError):
        revolut_bot.get_amount_with_margin(amount=Amount(real_amount=10,
                                                         currency="USD"),
                                           percent_margin="1%")
Пример #11
0
def test_exchange():
    eur_to_btc = Amount(real_amount=0.01, currency="EUR")
    exchange_transaction = revolut.exchange(from_amount=eur_to_btc,
                                            to_currency="BTC",
                                            simulate=_SIMU_EXCHANGE)
    assert type(exchange_transaction) == Transaction
    print()
    print('{} => {} : exchange OK'.format(eur_to_btc, exchange_transaction))
Пример #12
0
def test_get_amount_with_margin():
    amount = Amount(real_amount=10, currency="USD")
    percent_margin = 1  # 1%
    amount_with_margin = revolut_bot.get_amount_with_margin(
        amount=amount, percent_margin=percent_margin)
    assert type(amount_with_margin) == Amount
    assert amount_with_margin.real_amount == 10.1
    assert amount_with_margin.currency == "USD"
Пример #13
0
def test_quote_errors():
    with pytest.raises(TypeError):
        revolut.quote(from_amount="100 EUR", to_currency="EUR")

    with pytest.raises(TypeError):
        revolut.quote(from_amount=100, to_currency="EUR")

    with pytest.raises(KeyError):
        eur_to_unknown = Amount(real_amount=100, currency="EUR")
        revolut.quote(from_amount=eur_to_unknown, to_currency="UNKNOWN")
Пример #14
0
def test_quote_commission():
    currency1 = "USD"
    currency2 = "EUR"
    step1 = Amount(real_amount=5000, currency=currency1)
    step2 = revolut.quote(from_amount=step1, to_currency=currency2)
    step3 = revolut.quote(from_amount=step2, to_currency=currency1)
    print()
    comm_rate = 1-(step3.real_amount/step1.real_amount)
    print('Commission {}<->{} {:.2%}'.format(currency1, currency2, comm_rate))
    assert comm_rate < 0.05
Пример #15
0
def get_amount_with_margin(amount, percent_margin):
    """ Returns the amount with a margin
>>> print(get_amount_with_margin(amount=Amount(real_amount=100,\
currency="EUR"), percent_margin=1))
101.00 EUR
"""
    if type(amount) != Amount:
        raise TypeError
    if type(percent_margin) not in [float, int]:
        raise TypeError
    margin = percent_margin / 100

    amount_with_margin = amount.real_amount * (1 + margin)

    return Amount(real_amount=amount_with_margin, currency=amount.currency)