Skip to content

Commit

Permalink
clean conftest, moved all catalog and header tests to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Berend Kapelle committed Feb 8, 2018
1 parent ba72357 commit 0425c90
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ htmlcov/*
.mr.developer.cfg
.project
.pydevproject
.eggs/
.pytest_cache/
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CHANGES
=======

* making tests green
* BAAS-31: Revert SSL
* BAAS-31: Fix string
* BAAS-31 Fix litreal
Expand Down
34 changes: 24 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
PASSWORD = 'some_words'


@pytest.fixture(scope='module')
def figo_connection():
def new_user_id():
return "{0}[email protected]".format(uuid.uuid4())



def get_figo_connection():
return FigoConnection(CREDENTIALS['client_id'],
CREDENTIALS['client_secret'],
"https://127.0.0.1/",
Expand All @@ -25,14 +29,11 @@ def figo_connection():


@pytest.fixture(scope='module')
def new_user_id():
return "{0}[email protected]".format(uuid.uuid4())


@pytest.fixture(scope='module')
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)
def figo_session():
user_id = new_user_id()
figo_connection = get_figo_connection()
figo_connection.add_user("Test", user_id, PASSWORD)
response = figo_connection.credential_login(user_id, PASSWORD)

scope = response['scope']

Expand Down Expand Up @@ -80,3 +81,16 @@ def giro_account(figo_session):
assert len(giro_accs) >= 1

yield giro_accs[0]

@pytest.fixture(scope='module')
def access_token():
user_id = new_user_id()
figo_connection = get_figo_connection()
figo_connection.add_user("Test", user_id, PASSWORD)
response = figo_connection.credential_login(user_id, PASSWORD)
access_token = response['access_token']

yield access_token

session = FigoSession(access_token)
session.remove_user()
65 changes: 65 additions & 0 deletions tests/test_catalog_and_language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest

from figo import FigoException
from figo import FigoSession
from figo.models import Service
from figo.models import LoginSettings

CREDENTIALS = ["figo", "figo"]
BANK_CODE = "90090042"
CLIENT_ERROR = 1000

@pytest.mark.parametrize('language', ['de', 'en'])
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_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


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)


def test_get_login_settings(access_token):
figo_session = FigoSession(access_token)
login_settings = figo_session.get_login_settings("de", "90090042")
assert login_settings.advice
assert login_settings.credentials


# XXX(Valentin): Catalog needs `accounts=rw`, so it doesn't work with the demo session.
# Sounds silly at first, but actually there is no point to view the catalog if
# you can't add accounts.
def test_get_catalog(access_token):
figo_session = FigoSession(access_token)
catalog = figo_session.get_catalog()
assert len(catalog) == 2


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)


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'
29 changes: 3 additions & 26 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@
from figo import FigoException
from figo.models import Notification
from figo.models import Payment
from figo.models import Process
from figo.models import ProcessToken
from figo.models import TaskToken



def test_set_unset_language(figo_session):
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_get_account(figo_session, account_ids):
account_id = account_ids[0]
account = figo_session.get_account(account_id)
Expand Down Expand Up @@ -145,20 +133,9 @@ def test_create_update_delete_payment(figo_session, giro_account):
figo_session.get_payment(modified_payment.account_id, modified_payment.payment_id)


def test_get_supported_payment_services(figo_session):
# Access token with accounts=rw needed
services = figo_session.get_supported_payment_services("de")
assert len(services) > 5


def test_get_login_settings(figo_session):
login_settings = figo_session.get_login_settings("de", "90090042")
assert login_settings.advice
assert login_settings.credentials


def test_delete_transaction(figo_session):
figo_session.delete_transaction("A1.1", "T1.24")
def test_delete_transaction(figo_session, giro_account):
transaction = giro_account.transactions[0]
figo_session.delete_transaction(giro_account.account_id, transaction.transaction_id)


def test_get_payment_proposals(figo_session):
Expand Down
39 changes: 2 additions & 37 deletions tests/test_writing_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from figo import FigoException
from figo import FigoPinException
from figo.models import LoginSettings
from figo.models import Service

from figo.models import TaskState
from figo.models import TaskToken

Expand All @@ -18,40 +17,6 @@
CLIENT_ERROR = 1000


# XXX(Valentin): Catalog needs `accounts=rw`, so it doesn't work with the demo session.
# Sounds silly at first, but actually there is no point to view the catalog if
# you can't add accounts.
def test_get_catalog(figo_session):
catalog = figo_session.get_catalog()
assert len(catalog) == 2


@pytest.mark.parametrize('language', ['de', 'en'])
def test_get_catalog_en(figo_session, language):
figo_session.language = language
catalog = figo_session.get_catalog()
for bank in catalog['banks']:
assert bank.language == language


def test_get_catalog_invalid_language(figo_session):
figo_session.language = 'xy'
with pytest.raises(FigoException) as e:
figo_session.get_catalog()
assert e.value.code == CLIENT_ERROR


def test_get_supported_payment_services(figo_session):
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)


def test_get_login_settings(figo_session):
login_settings = figo_session.get_login_settings("de", BANK_CODE)
assert isinstance(login_settings, LoginSettings)


def test_add_account(figo_session):
token = figo_session.add_account("de", CREDENTIALS, BANK_CODE)
assert isinstance(token, TaskToken)
Expand Down Expand Up @@ -116,7 +81,7 @@ def test_add_account_and_sync_wrong_pin_postbank(figo_session):


@pytest.mark.skip(reason="test is flaky as hell and should be rewritten completely")
def test_051_add_account_and_sync_wrong_and_correct_pin(figo_session):
def test_add_account_and_sync_wrong_and_correct_pin(figo_session):
wrong_credentials = [CREDENTIALS[0], "123456"]
figo_session.sync_poll_retry = 100
try:
Expand Down

0 comments on commit 0425c90

Please sign in to comment.