def test_get_supported_payment_services(access_token):
    figo_session = FigoSession(access_token)
    services = figo_session.get_supported_payment_services("de")
    assert len(
        services
    ) > 10  # this a changing value, this tests that at least some are returned
    assert isinstance(services[0], Service)
Beispiel #2
0
def root(current_account_id=None):
    # check whether the user is logged in
    if not 'figo_token' in session:
        return redirect(
            connection.login_url(
                scope="accounts=ro transactions=ro balance=ro user=ro",
                state="qweqwe"))

    # open user figo connection
    figo_session = FigoSession(session['figo_token'])

    # open demo figo connection
    #figo_session = FigoSession("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")

    if current_account_id:
        current_account = figo_session.get_account(current_account_id)
    else:
        current_account = None

    if current_account:
        transactions = current_account.transactions
    else:
        transactions = figo_session.transactions

    return render_template('banking_root.html',
                           accounts=figo_session.accounts,
                           current_account=current_account,
                           transactions=transactions,
                           user=figo_session.user)
def test_set_unset_language(access_token):
    figo_session = FigoSession(access_token)
    assert figo_session.language is None
    figo_session.language = 'de'
    assert figo_session.language == 'de'
    figo_session.language = ''
    assert figo_session.language is None
    figo_session.language = 'de'
def test_set_unset_language(access_token):
    figo_session = FigoSession(access_token)
    assert figo_session.language is None
    figo_session.language = 'de'
    assert figo_session.language == 'de'
    figo_session.language = ''
    assert figo_session.language is None
    figo_session.language = 'de'
Beispiel #5
0
def access_token(figo_connection, new_user_id):
    figo_connection.add_user("Test", new_user_id, PASSWORD)
    response = figo_connection.credential_login(new_user_id, PASSWORD)
    access_token = response['access_token']

    yield access_token

    session = FigoSession(access_token)
    session.remove_user()
def main():
    session = FigoSession(DEMO_TOKEN)

    for account in session.accounts:
        print(account)
        print(u'  {}'.format(account.balance))
        print(u'  Transactions:')

        for transaction in session.get_account(account.account_id).transactions:
            print(u'    {}'.format(transaction))
Beispiel #7
0
def main():
    session = FigoSession("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")

    # print out a list of accounts including its balance
    for account in session.accounts:
        print account
        print account.balance

    # print out the list of all transactions on a specific account
    for transaction in session.get_account("A1.2").transactions:
        print transaction
Beispiel #8
0
def main():
    session = FigoSession(
        "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"
    )

    # print out a list of accounts including its balance
    for account in session.accounts:
        print account
        print account.balance

    # print out the list of all transactions on a specific account
    for transaction in session.get_account("A1.2").transactions:
        print transaction
Beispiel #9
0
def figo_session(figo_connection, new_user_id):
    figo_connection.add_user("Test", new_user_id, PASSWORD)
    response = figo_connection.credential_login(new_user_id, PASSWORD)

    scope = response['scope']

    required_scopes = [
        'accounts=rw',
        'transactions=rw',
        'user=rw',
        'create_user',
    ]

    if any(s not in scope for s in required_scopes):
        pytest.skip("The client ID needs write access to the servers.")

    session = FigoSession(response['access_token'])

    task_token = session.add_account("de", ("figo", "figo"), "90090042")
    state = session.get_task_state(task_token)

    while not (state.is_ended or state.is_erroneous):
        state = session.get_task_state(task_token)
        time.sleep(2)
    assert not state.is_erroneous

    yield session

    session.remove_user()
Beispiel #10
0
def demo_session():
    # TODO(Valentin): we need to run `test_session` (both read-only) against production API
    #                 using demo credentials, since there is no adequate client or data available
    #                 on `staging`. we could:
    #                 - drop these tests entirely and lose quite some code coverage
    #                 - replace by write-then-read tests which cannot be run on external PRs
    #                 - create a non-expiring demo session on `staging`
    return FigoSession(DEMO_TOKEN,
                       api_endpoint=DEMO_CREDENTIALS['api_endpoint'],
                       fingerprints=DEMO_CREDENTIALS['ssl_fingerprints'])
Beispiel #11
0
def root(current_account_id=None):
    # check whether the user is logged in
    if not 'figo_token' in session:
        return redirect(connection.login_url(scope="accounts=ro transactions=ro balance=ro user=ro", state="qweqwe"))

    # open user figo connection
    figo_session = FigoSession(session['figo_token'])

    # open demo figo connection
    #figo_session = FigoSession("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")

    if current_account_id:
        current_account = figo_session.get_account(current_account_id)
    else:
        current_account = None

    if current_account:
        transactions = current_account.transactions
    else:
        transactions = figo_session.transactions

    return render_template('banking_root.html', accounts=figo_session.accounts, current_account=current_account, transactions=transactions, user=figo_session.user)
Beispiel #12
0
def figo_session(figo_connection, new_user_id):
    figo_connection.add_user("Test", new_user_id, PASSWORD)
    response = figo_connection.credential_login(new_user_id, PASSWORD)

    scope = response['scope']

    required_scopes = [
        'accounts=rw',
        'transactions=rw',
        'user=rw',
        'categorization=rw',
        'create_user',
    ]

    if any(s not in scope for s in required_scopes):
        pytest.skip("The client ID needs write access to the servers.")

    session = FigoSession(response['access_token'])

    yield session

    session.remove_user()
Beispiel #13
0
def test_create_token_and_session():
    token = connection.credential_login("*****@*****.**", "password")
    pytest.token = token["access_token"]
    assert pytest.token
    pytest.session = FigoSession(token["access_token"])
    assert pytest.session.user.full_name == "John Doe"
Beispiel #14
0
import json
import webbrowser
from figo import FigoConnection, FigoSession
from pprint import pprint
from .transaction import Transaction
from .contact import Contact

#connection = FigoConnection("<client ID>", "<client secret>", "http://my-domain.org/redirect-url")
with open("config.json", "r") as data_file:
    data = json.loads(data_file.read())
session = FigoSession(data["figo"]["token"])


def get_accounts():
    accountlist = []
    for account in session.accounts:
        accountlist.append(account)

    return accountlist


def get_transactions(account):
    transact_list = []
    for trans in session.get_account(account.account_id).transactions:
        c = Contact(account.name, account.iban, account.bic)
        x = Transaction(trans.transaction_id, c, trans.type, trans.purpose,
                        trans.booking_text, trans.amount)
        transact_list.append(x)
    return transact_list

Beispiel #15
0
def test_add_access_with_wrong_access_id(access_token):
    figo_session = FigoSession(access_token)
    access_method_id = "pipo"
    response = figo_session.add_access(access_method_id, CREDENTIALS, CONSENT)
    assert response.has_key("error") == True
def test_get_login_settings(access_token):
    figo_session = FigoSession(access_token)
    login_settings = figo_session.get_login_settings("de", BANK_CODE)
    assert isinstance(login_settings, LoginSettings)
    assert login_settings.advice
    assert login_settings.credentials
Beispiel #17
0
def test_get_catalog(access_token):
    figo_session = FigoSession(access_token)
    catalog = figo_session.get_catalog()
    assert len(catalog) == 2
Beispiel #18
0
def test_get_catalog_en(access_token, language, country):
    figo_session = FigoSession(access_token)
    figo_session.language = language
    catalog = figo_session.get_catalog(country)
    for bank in catalog["banks"]:
        assert bank.country == country
Beispiel #19
0
 def setUp(self):
     self.sut = FigoSession(
         "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"
     )
def test_get_catalog_en(access_token, language):
    figo_session = FigoSession(access_token)
    figo_session.language = language
    catalog = figo_session.get_catalog()
    for bank in catalog['banks']:
        assert bank.language == language
def test_get_supported_payment_services(access_token):
    figo_session = FigoSession(access_token)
    services = figo_session.get_supported_payment_services("de")
    assert len(services) > 10  # this a changing value, this tests that at least some are returned
    assert isinstance(services[0], Service)
Beispiel #22
0
class TestSession(unittest.TestCase):

    def setUp(self):
        self.sut = FigoSession("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")

    def test_get_account(self):
        account = self.sut.get_account("A1.2")
        self.assertEqual(account.account_id, "A1.2")

    def test_get_account_tan_schemes(self):
        account = self.sut.get_account("A1.1")
        self.assertEqual(len(account.supported_tan_schemes), 3)

    def test_get_account_balance(self):
        # account sub-resources
        balance = self.sut.get_account_balance(self.sut.get_account("A1.2"))
        self.assertTrue(balance.balance)
        self.assertTrue(balance.balance_date)

    def test_get_account_transactions(self):
        transactions = self.sut.get_account("A1.2").transactions
        self.assertTrue(len(transactions) > 0)

    def test_get_account_payments(self):
        payments = self.sut.get_account("A1.2").payments
        self.assertTrue(len(payments) >= 0)

    def test_get_global_transactions(self):
        transactions = self.sut.transactions
        self.assertTrue(len(transactions) > 0)

    def test_get_global_payments(self):
        payments = self.sut.payments
        self.assertTrue(len(payments) >= 0)

    def test_get_notifications(self):
        notifications = self.sut.notifications
        self.assertTrue(len(notifications) >= 0)

    def test_get_missing_account(self):
        self.assertEqual(self.sut.get_account("A1.22"), None)

    def test_error_handling(self):
        try:
            self.sut.get_sync_url("", "http://*****:*****@figo.me")

    def test_create_update_delete_notification(self):
        added_notification = self.sut.add_notification(Notification.from_dict(self.sut, dict(observe_key="/rest/transactions", notify_uri="http://figo.me/test", state="qwe")))
        self.assertEqual(added_notification.observe_key, "/rest/transactions")
        self.assertEqual(added_notification.notify_uri, "http://figo.me/test")
        self.assertEqual(added_notification.state, "qwe")

        added_notification.state = "asd"
        modified_notification = self.sut.modify_notification(added_notification)
        self.assertEqual(modified_notification.observe_key, "/rest/transactions")
        self.assertEqual(modified_notification.notify_uri, "http://figo.me/test")
        self.assertEqual(modified_notification.state, "asd")

        self.sut.remove_notification(modified_notification.notification_id)
        self.assertEqual(self.sut.get_notification(modified_notification.notification_id), None)

    def test_create_update_delete_payment(self):
        added_payment = self.sut.add_payment(Payment.from_dict(self.sut, dict(account_id="A1.1", type="Transfer", account_number="4711951501", bank_code="90090042", name="figo", purpose="Thanks for all the fish.", amount=0.89)))
        self.assertEqual(added_payment.account_id, "A1.1")
        self.assertEqual(added_payment.bank_name, "Demobank")
        self.assertEqual(added_payment.amount, 0.89)

        added_payment.amount = 2.39
        modified_payment = self.sut.modify_payment(added_payment)
        self.assertEqual(modified_payment.payment_id, added_payment.payment_id)
        self.assertEqual(modified_payment.account_id, "A1.1")
        self.assertEqual(modified_payment.bank_name, "Demobank")
        self.assertEqual(modified_payment.amount, 2.39)

        self.sut.remove_payment(modified_payment)
        self.assertEqual(self.sut.get_payment(account_or_account_id=modified_payment.account_id, payment_id=modified_payment.payment_id), None)

    def test_set_bank_account_order(self):
        # Access token with accounts=rw needed
        accounts = [self.sut.get_account("A1.2"), self.sut.get_account("A1.1")]
        self.assertRaises(FigoException, self.sut.set_account_sort_order, accounts)

    def test_get_supported_payment_services(self):
        # Access token with accounts=rw needed
        self.assertRaises(FigoException, self.sut.get_supported_payment_services, "de")

    def test_get_login_settings(self):
        # Access token with accounts=rw needed
        self.assertRaises(FigoException, self.sut.get_login_settings, "de", "90090042")

    def test_setup_new_bank_account(self):
        # Access token with accounts=rw needed
        self.assertRaises(FigoException, self.sut.add_account, "de", ["figo", "figo"], "90090042")

    def test_modify_a_transaction(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.modify_transaction, "A1.1", "T1.24", False)

    def test_modify_all_transactions_of_account(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.modify_account_transactions, "A1.1", False)

    def test_modify_all_transactions(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.modify_account_transactions, False)

    def test_delete_transaction(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.delete_transaction, "A1.1", "T1.24")

    def test_get_payment_proposals(self):
        proposals = self.sut.get_payment_proposals()
        self.assertEqual(len(proposals), 2)

    def test_start_task(self):
        # Valid task token needed
        task_token = TaskToken(self.sut)
        task_token.task_token = "invalidTaskToken"
        self.assertRaises(FigoException, self.sut.start_task, task_token)

    def test_poll_task_state(self):
        # Valid task token needed
        task_token = TaskToken(self.sut)
        task_token.task_token = "invalidTaskToken"
        self.assertRaises(FigoException, self.sut.get_task_state, task_token)

    def test_cancel_task(self):
        # Valid task token needed
        task_token = TaskToken(self.sut)
        task_token.task_token = "invalidTaskToken"
        self.assertRaises(FigoException, self.sut.cancel_task, task_token)

    def test_start_process(self):
        # Valid process token needed
        process_token = ProcessToken(self.sut)
        process_token.process_token = "invalidProcessToken"
        self.assertRaises(FigoException, self.sut.start_process, process_token)

    def test_create_process(self):
        # Access token with process=rw needed
        process = Process(self.sut, email="*****@*****.**", password="******", state="qwer", steps=["not_valid"])
        self.assertRaises(FigoException, self.sut.create_process, process)
def test_get_catalog(access_token):
    figo_session = FigoSession(access_token)
    catalog = figo_session.get_catalog()
    assert len(catalog) == 2
Beispiel #24
0
def test_get_catalog_invalid_language(access_token):
    figo_session = FigoSession(access_token)
    with pytest.raises(FigoException) as e:
        figo_session.get_catalog("XY")
    assert e.value.code == CLIENT_ERROR
def test_get_catalog_invalid_language(access_token):
    figo_session = FigoSession(access_token)
    figo_session.language = 'xy'
    with pytest.raises(FigoException) as e:
        figo_session.get_catalog()
    assert e.value.code == CLIENT_ERROR
Beispiel #26
0
class TestSession(unittest.TestCase):
    def setUp(self):
        self.sut = FigoSession(
            "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"
        )

    def test_get_account(self):
        account = self.sut.get_account("A1.2")
        self.assertEqual(account.account_id, "A1.2")

    def test_get_account_tan_schemes(self):
        account = self.sut.get_account("A1.1")
        self.assertEqual(len(account.supported_tan_schemes), 3)

    def test_get_account_balance(self):
        # account sub-resources
        balance = self.sut.get_account_balance(self.sut.get_account("A1.2"))
        self.assertTrue(balance.balance)
        self.assertTrue(balance.balance_date)

    def test_get_account_transactions(self):
        transactions = self.sut.get_account("A1.2").transactions
        self.assertTrue(len(transactions) > 0)

    def test_get_account_payments(self):
        payments = self.sut.get_account("A1.2").payments
        self.assertTrue(len(payments) >= 0)

    def test_get_global_transactions(self):
        transactions = self.sut.transactions
        self.assertTrue(len(transactions) > 0)

    def test_get_global_payments(self):
        payments = self.sut.payments
        self.assertTrue(len(payments) >= 0)

    def test_get_notifications(self):
        notifications = self.sut.notifications
        self.assertTrue(len(notifications) >= 0)

    def test_get_missing_account(self):
        self.assertEqual(self.sut.get_account("A1.22"), None)

    def test_error_handling(self):
        try:
            self.sut.get_sync_url("", "http://*****:*****@figo.me")

    def test_create_update_delete_notification(self):
        added_notification = self.sut.add_notification(
            Notification.from_dict(
                self.sut,
                dict(observe_key="/rest/transactions",
                     notify_uri="http://figo.me/test",
                     state="qwe")))
        self.assertEqual(added_notification.observe_key, "/rest/transactions")
        self.assertEqual(added_notification.notify_uri, "http://figo.me/test")
        self.assertEqual(added_notification.state, "qwe")

        added_notification.state = "asd"
        modified_notification = self.sut.modify_notification(
            added_notification)
        self.assertEqual(modified_notification.observe_key,
                         "/rest/transactions")
        self.assertEqual(modified_notification.notify_uri,
                         "http://figo.me/test")
        self.assertEqual(modified_notification.state, "asd")

        self.sut.remove_notification(modified_notification.notification_id)
        self.assertEqual(
            self.sut.get_notification(modified_notification.notification_id),
            None)

    def test_create_update_delete_payment(self):
        added_payment = self.sut.add_payment(
            Payment.from_dict(
                self.sut,
                dict(account_id="A1.1",
                     type="Transfer",
                     account_number="4711951501",
                     bank_code="90090042",
                     name="figo",
                     purpose="Thanks for all the fish.",
                     amount=0.89)))
        self.assertEqual(added_payment.account_id, "A1.1")
        self.assertEqual(added_payment.bank_name, "Demobank")
        self.assertEqual(added_payment.amount, 0.89)

        added_payment.amount = 2.39
        modified_payment = self.sut.modify_payment(added_payment)
        self.assertEqual(modified_payment.payment_id, added_payment.payment_id)
        self.assertEqual(modified_payment.account_id, "A1.1")
        self.assertEqual(modified_payment.bank_name, "Demobank")
        self.assertEqual(modified_payment.amount, 2.39)

        self.sut.remove_payment(modified_payment)
        self.assertEqual(
            self.sut.get_payment(
                account_or_account_id=modified_payment.account_id,
                payment_id=modified_payment.payment_id), None)

    def test_set_bank_account_order(self):
        # Access token with accounts=rw needed
        accounts = [self.sut.get_account("A1.2"), self.sut.get_account("A1.1")]
        self.assertRaises(FigoException, self.sut.set_account_sort_order,
                          accounts)

    def test_get_supported_payment_services(self):
        # Access token with accounts=rw needed
        self.assertRaises(FigoException,
                          self.sut.get_supported_payment_services, "de")

    def test_get_login_settings(self):
        # Access token with accounts=rw needed
        self.assertRaises(FigoException, self.sut.get_login_settings, "de",
                          "90090042")

    def test_setup_new_bank_account(self):
        # Access token with accounts=rw needed
        self.assertRaises(FigoException, self.sut.add_account, "de",
                          ["figo", "figo"], "90090042")

    def test_modify_a_transaction(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.modify_transaction, "A1.1",
                          "T1.24", False)

    def test_modify_all_transactions_of_account(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.modify_account_transactions,
                          "A1.1", False)

    def test_modify_all_transactions(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.modify_account_transactions,
                          False)

    def test_delete_transaction(self):
        # Access token with transactions=rw needed
        self.assertRaises(FigoException, self.sut.delete_transaction, "A1.1",
                          "T1.24")

    def test_get_payment_proposals(self):
        proposals = self.sut.get_payment_proposals()
        self.assertEqual(len(proposals), 2)

    def test_start_task(self):
        # Valid task token needed
        task_token = TaskToken(self.sut)
        task_token.task_token = "invalidTaskToken"
        self.assertRaises(FigoException, self.sut.start_task, task_token)

    def test_poll_task_state(self):
        # Valid task token needed
        task_token = TaskToken(self.sut)
        task_token.task_token = "invalidTaskToken"
        self.assertRaises(FigoException, self.sut.get_task_state, task_token)

    def test_cancel_task(self):
        # Valid task token needed
        task_token = TaskToken(self.sut)
        task_token.task_token = "invalidTaskToken"
        self.assertRaises(FigoException, self.sut.cancel_task, task_token)

    def test_start_process(self):
        # Valid process token needed
        process_token = ProcessToken(self.sut)
        process_token.process_token = "invalidProcessToken"
        self.assertRaises(FigoException, self.sut.start_process, process_token)

    def test_create_process(self):
        # Access token with process=rw needed
        process = Process(self.sut,
                          email="*****@*****.**",
                          password="******",
                          state="qwer",
                          steps=["not_valid"])
        self.assertRaises(FigoException, self.sut.create_process, process)
def test_get_login_settings(access_token):
    figo_session = FigoSession(access_token)
    login_settings = figo_session.get_login_settings("de", BANK_CODE)
    assert isinstance(login_settings, LoginSettings)
    assert login_settings.advice
    assert login_settings.credentials
def test_create_token_and_session(figo_connection):
    token = figo_connection.credential_login(pytest.new_user_id, PASSWORD)
    pytest.token = token["access_token"]
    assert pytest.token
    pytest.session = FigoSession(token["access_token"])
    assert pytest.session.user.full_name == "Jimmy"
def test_get_catalog_en(access_token, language):
    figo_session = FigoSession(access_token)
    figo_session.language = language
    catalog = figo_session.get_catalog()
    for bank in catalog['banks']:
        assert bank.language == language
Beispiel #30
0
def test_get_catalog_invalid_language(access_token):
    figo_session = FigoSession(access_token)
    catalog = figo_session.get_catalog("XY")
    assert catalog == {"banks": [], "services": []}
Beispiel #31
0
def test_get_payments():
    session = FigoSession(pytest.payments_token)
    response = session.get_payments(pytest.account_id, None, None, None, None)
    assert response == []
Beispiel #32
0
 def setUp(self):
     self.sut = FigoSession("ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ")
Beispiel #33
0
def figo_session(figo_connection, new_user_id):
    figo_connection.add_user("Test", new_user_id, PASSWORD)
    response = figo_connection.credential_login(new_user_id, PASSWORD)
    return FigoSession(response['access_token'])