Exemplo n.º 1
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")
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
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'
    }