tests: add check for past invoices cell
This commit is contained in:
parent
b051533e58
commit
e086e49092
|
@ -12,7 +12,8 @@ from django.utils import timezone
|
|||
|
||||
from combo.utils import check_query, aes_hex_encrypt
|
||||
from combo.data.models import Page
|
||||
from combo.apps.lingo.models import Regie, ActiveItems, SelfDeclaredInvoicePayment, Transaction, BasketItem
|
||||
from combo.apps.lingo.models import (Regie, ActiveItems, ItemsHistory,
|
||||
SelfDeclaredInvoicePayment, Transaction, BasketItem)
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
@ -68,7 +69,7 @@ class MockUser(object):
|
|||
self.saml_identifiers = MockSAMLUsers()
|
||||
|
||||
@mock.patch('combo.utils.RequestsSession.request')
|
||||
def test_remote_regie_cell(mock_request, remote_regie):
|
||||
def test_remote_regie_active_invoices_cell(mock_request, remote_regie):
|
||||
assert remote_regie.is_remote() == True
|
||||
|
||||
page = Page(title='xxx', slug='test_basket_cell', template_name='standard')
|
||||
|
@ -108,6 +109,47 @@ def test_remote_regie_cell(mock_request, remote_regie):
|
|||
content = cell.render(context)
|
||||
assert 'No items yet' in content
|
||||
|
||||
@mock.patch('combo.utils.RequestsSession.request')
|
||||
def test_remote_regie_past_invoices_cell(mock_request, remote_regie):
|
||||
assert remote_regie.is_remote() == True
|
||||
|
||||
page = Page(title='xxx', slug='test_basket_cell', template_name='standard')
|
||||
page.save()
|
||||
cell = ItemsHistory(regie='remote', page=page, placeholder='content', order=0)
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context['synchronous'] = True # to get fresh content
|
||||
|
||||
user = MockUser()
|
||||
context['user'] = user
|
||||
context['request'].user = user
|
||||
|
||||
assert cell.is_relevant(context) is True
|
||||
|
||||
# show regie with an invoice
|
||||
mock_json = mock.Mock()
|
||||
mock_json.json.return_value = {'err': 0, 'data': INVOICES}
|
||||
mock_request.return_value = mock_json
|
||||
content = cell.render(context)
|
||||
assert 'F-2016-One' in content
|
||||
assert '123.45' in content
|
||||
|
||||
# check if regie webservice has been correctly called
|
||||
assert mock_request.call_args[0][0] == 'GET'
|
||||
url = mock_request.call_args[0][1]
|
||||
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
||||
assert scheme == 'http'
|
||||
assert netloc == 'example.org'
|
||||
assert path == '/regie/invoices/history/'
|
||||
query = urlparse.parse_qs(querystring, keep_blank_values=True)
|
||||
assert query['NameID'][0] == 'r2d2'
|
||||
assert query['orig'][0] == 'combo'
|
||||
assert check_query(querystring, 'combo') == True
|
||||
|
||||
# with no invoice
|
||||
mock_json.json.return_value = {'err': 0, 'data': []}
|
||||
content = cell.render(context)
|
||||
assert 'No items yet' in content
|
||||
|
||||
@mock.patch('combo.apps.lingo.models.Regie.pay_invoice')
|
||||
@mock.patch('combo.apps.lingo.models.requests.get')
|
||||
def test_anonymous_successful_item_payment(mock_get, mock_pay_invoice, app, remote_regie):
|
||||
|
|
Loading…
Reference in New Issue