summaryrefslogtreecommitdiffstats
path: root/tests/test_lingo_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_lingo_manager.py')
-rw-r--r--tests/test_lingo_manager.py88
1 files changed, 74 insertions, 14 deletions
diff --git a/tests/test_lingo_manager.py b/tests/test_lingo_manager.py
index ffff1f3..a66a178 100644
--- a/tests/test_lingo_manager.py
+++ b/tests/test_lingo_manager.py
@@ -10,12 +10,19 @@ import pytest
import eopayment
from combo.data.models import Page
-from combo.apps.lingo.models import Regie, BasketItem, Transaction, ActiveItems, TipiPaymentFormCell
+from combo.apps.lingo.models import (Regie, BasketItem, Transaction, ActiveItems,
+ TipiPaymentFormCell, PaymentBackend)
from decimal import Decimal
pytestmark = pytest.mark.django_db
+@pytest.fixture
+def payment_backend():
+ return PaymentBackend.objects.create(
+ label='test1', slug='test1', service='dummy', service_options={'siret': '1234'})
+
+
def login(app, username='admin', password='admin'):
login_page = app.get('/login/')
login_form = login_page.forms[0]
@@ -30,7 +37,7 @@ def test_access(app, admin_user):
resp = app.get('/manage/', status=200)
assert '/manage/lingo/' in resp.text
-def test_add_regie(app, admin_user):
+def test_add_regie(app, admin_user, payment_backend):
Regie.objects.all().delete()
app = login(app)
resp = app.get('/manage/lingo/regies/', status=200)
@@ -38,7 +45,7 @@ def test_add_regie(app, admin_user):
resp.forms[0]['label'] = 'Test'
resp.forms[0]['slug'] = 'test'
resp.forms[0]['description'] = 'description'
- resp.forms[0]['service'] = 'dummy'
+ resp.forms[0]['payment_backend'] = payment_backend.pk
assert resp.form['is_default'].checked is True
resp = resp.forms[0].submit()
assert resp.location.endswith('/manage/lingo/regies/')
@@ -47,8 +54,8 @@ def test_add_regie(app, admin_user):
assert regie.label == 'Test'
assert regie.is_default is True
-def test_edit_regie(app, admin_user):
- test_add_regie(app, admin_user)
+def test_edit_regie(app, admin_user, payment_backend):
+ test_add_regie(app, admin_user, payment_backend)
app = login(app)
resp = app.get('/manage/lingo/regies/', status=200)
resp = resp.click('Test')
@@ -59,18 +66,17 @@ def test_edit_regie(app, admin_user):
regie = Regie.objects.all()[0]
assert regie.description == 'other description'
-def test_delete_regie(app, admin_user):
- test_add_regie(app, admin_user)
+def test_delete_regie(app, admin_user, payment_backend):
+ test_add_regie(app, admin_user, payment_backend)
app = login(app)
resp = app.get('/manage/lingo/regies/', status=200)
resp = resp.click('remove')
assert 'Are you sure you want to delete this?' in resp.text
resp = resp.forms[0].submit()
- assert resp.location.endswith('/manage/lingo/regies/')
assert Regie.objects.count() == 0
-def test_add_second_regie(app, admin_user):
- test_add_regie(app, admin_user)
+def test_add_second_regie(app, admin_user, payment_backend):
+ test_add_regie(app, admin_user, payment_backend)
regie = Regie.objects.all()[0]
app = login(app)
@@ -79,7 +85,7 @@ def test_add_second_regie(app, admin_user):
resp.forms[0]['label'] = 'Test2'
resp.forms[0]['slug'] = 'test2'
resp.forms[0]['description'] = 'description'
- resp.forms[0]['service'] = 'dummy'
+ resp.forms[0]['payment_backend'] = payment_backend.pk
assert resp.form['is_default'].checked is False
resp = resp.forms[0].submit()
assert resp.location.endswith('/manage/lingo/regies/')
@@ -88,8 +94,8 @@ def test_add_second_regie(app, admin_user):
assert Regie.objects.get(id=regie.id).is_default is True
assert Regie.objects.exclude(id=regie.id)[0].is_default is False
-def test_download_transaction(app, admin_user):
- test_add_regie(app, admin_user)
+def test_download_transaction(app, admin_user, payment_backend):
+ test_add_regie(app, admin_user, payment_backend)
regie = Regie.objects.filter(slug='test')[0]
user = User.objects.create_user('dimebag', 'dime@bag.pan', 'pwd')
user.last_name = u'Darëll'
@@ -164,7 +170,7 @@ def test_configure_tipi_cell(app, admin_user):
assert resp.text.count('ROLDEB:') == 1
assert resp.text.count('ROLDET:') == 1
-def test_configure_invoices_cell(app, admin_user):
+def test_configure_invoices_cell(app, admin_user, payment_backend):
page = Page(title='xxx', slug='test', template_name='standard')
page.save()
@@ -179,6 +185,7 @@ def test_configure_invoices_cell(app, admin_user):
regie.label = 'Test'
regie.slug = 'test'
regie.description = 'test'
+ regie.payment_backend = payment_backend
regie.save()
resp = app.get('/manage/pages/%s/' % page.id, status=200)
@@ -202,6 +209,7 @@ def test_configure_invoices_cell(app, admin_user):
regie2.slug = 'test2'
regie2.description = 'test2'
regie2.webservice_url = 'http://example.net/'
+ regie2.payment_backend = payment_backend
regie2.save()
resp = app.get('/manage/pages/%s/' % page.id, status=200)
@@ -215,3 +223,55 @@ def test_configure_invoices_cell(app, admin_user):
resp.form['clingo_activeitems-%s-regie' % cell.id].value = 'test2'
resp.form.submit()
assert ActiveItems.objects.get(id=cell.id).regie == regie2.slug
+
+
+def test_payment_backend_list(app, admin_user):
+ PaymentBackend.objects.create(label='label1', slug='slug1')
+ PaymentBackend.objects.create(label='label2', slug='slug2')
+ app = login(app)
+ resp = app.get('/manage/lingo/paymentbackends/', status=200)
+
+ assert '/manage/lingo/paymentbackends/add' in resp.text
+ assert 'label1' in resp.content
+ assert 'label2' in resp.content
+
+ for payment_backend in PaymentBackend.objects.all():
+ assert '/manage/lingo/paymentbackends/%s' % payment_backend.pk in resp.text
+ assert '/manage/lingo/paymentbackends/%s/delete' % payment_backend.pk in resp.text
+
+
+def test_add_payment_backend(app, admin_user):
+ assert not PaymentBackend.objects.count()
+ app = login(app)
+ resp = app.get('/manage/lingo/paymentbackends/add/', status=200)
+ assert '/manage/lingo/paymentbackends/' in resp.text
+
+ resp.forms[0]['label'] = 'Test'
+ resp.forms[0]['slug'] = 'test-add'
+ resp.forms[0]['service'] = 'dummy'
+ resp.forms[0]['service_options'] = '{"siret": "1234"}'
+ resp = resp.forms[0].submit()
+
+ assert PaymentBackend.objects.count() == 1
+ payment_backend = PaymentBackend.objects.get(slug='test-add')
+ assert payment_backend.label == 'Test'
+ assert payment_backend.service_options == {'siret': '1234'}
+
+ assert resp.location.endswith('/manage/lingo/paymentbackends/')
+
+
+def test_edit_payment_backend(app, admin_user):
+ payment_backend = PaymentBackend.objects.create(label='label1', slug='slug1')
+ app = login(app)
+ resp = app.get('/manage/lingo/paymentbackends/%s/edit' % payment_backend.pk, status=200)
+ assert '/manage/lingo/paymentbackends/' in resp.text
+
+ resp.forms[0]['label'] = 'label1-modified'
+ resp.forms[0]['slug'] = 'slug1'
+ resp.forms[0]['service'] = 'dummy'
+ resp.forms[0]['service_options'] = '{"siret": "1234"}'
+ resp = resp.forms[0].submit()
+
+ assert resp.location.endswith('/manage/lingo/paymentbackends/')
+ payment_backend = PaymentBackend.objects.get(slug='slug1')
+ assert payment_backend.label == 'label1-modified'