3 |
3 |
import datetime
|
4 |
4 |
|
5 |
5 |
from django.contrib.auth.models import User
|
6 |
|
from django.core.wsgi import get_wsgi_application
|
7 |
6 |
from django.utils.timezone import now
|
8 |
|
from webtest import TestApp
|
|
7 |
|
|
8 |
import mock
|
9 |
9 |
import pytest
|
10 |
10 |
|
11 |
11 |
import eopayment
|
... | ... | |
364 |
364 |
bank_transaction_id='bank_id_5_bis',
|
365 |
365 |
amount=55555)
|
366 |
366 |
transaction5_bis.items.add(item5_bis)
|
367 |
|
|
368 |
|
# item with payment_date, no notification_date, but a cancellation_date, in the past
|
369 |
|
# => not displayed
|
|
367 |
# item with payment_date but no notification_date, in the past
|
|
368 |
# => displayed
|
370 |
369 |
item6 = BasketItem.objects.create(
|
371 |
370 |
user=user,
|
372 |
371 |
regie=regie,
|
373 |
372 |
subject='item 6',
|
374 |
|
source_url='http://example.net/6',
|
|
373 |
source_url='', # without source_url
|
375 |
374 |
amount=6,
|
376 |
375 |
payment_date=date_in_past,
|
377 |
|
notification_date=None,
|
378 |
|
cancellation_date=date_now)
|
|
376 |
notification_date=None)
|
379 |
377 |
transaction6 = Transaction.objects.create(
|
380 |
378 |
order_id='order id 6',
|
381 |
379 |
bank_transaction_id='bank_id_6',
|
382 |
380 |
amount=6)
|
383 |
381 |
transaction6.items.add(item6)
|
384 |
382 |
|
|
383 |
# item with payment_date, no notification_date, but a cancellation_date, in the past
|
|
384 |
# => not displayed
|
|
385 |
item7 = BasketItem.objects.create(
|
|
386 |
user=user,
|
|
387 |
regie=regie,
|
|
388 |
subject='item 7',
|
|
389 |
source_url='http://example.net/7',
|
|
390 |
amount=7,
|
|
391 |
payment_date=date_in_past,
|
|
392 |
notification_date=None,
|
|
393 |
cancellation_date=date_now)
|
|
394 |
transaction7 = Transaction.objects.create(
|
|
395 |
order_id='order id 7',
|
|
396 |
bank_transaction_id='bank_id_7',
|
|
397 |
amount=7)
|
|
398 |
transaction7.items.add(item7)
|
|
399 |
|
385 |
400 |
app = login(app)
|
386 |
401 |
resp = app.get('/manage/lingo/payments/error/', status=200)
|
387 |
|
assert list(resp.context['object_list']) == [item5, item3, item2]
|
|
402 |
assert list(resp.context['object_list']) == [item6, item5, item3, item2]
|
|
403 |
assert '<a href="%s">' % item6.source_url not in resp.text
|
388 |
404 |
assert '<a href="%s">' % item5.source_url in resp.text
|
389 |
405 |
assert '<a href="%s">' % item3.source_url in resp.text
|
390 |
406 |
assert '<a href="%s">' % item2.source_url not in resp.text
|
|
407 |
assert '/manage/lingo/?q=%s' % transaction6.bank_transaction_id in resp.text
|
391 |
408 |
assert '/manage/lingo/?q=%s' % transaction5.bank_transaction_id in resp.text
|
392 |
409 |
assert '/manage/lingo/?q=%s' % transaction3.bank_transaction_id not in resp.text
|
393 |
410 |
assert '/manage/lingo/?q=%s' % transaction22.bank_transaction_id not in resp.text
|
|
411 |
assert '/manage/lingo/item/%s/mark-as-notified/' % item6.pk not in resp.text
|
|
412 |
assert '/manage/lingo/item/%s/mark-as-notified/' % item5.pk in resp.text
|
|
413 |
assert '/manage/lingo/item/%s/mark-as-notified/' % item3.pk not in resp.text
|
|
414 |
assert '/manage/lingo/item/%s/mark-as-notified/' % item2.pk not in resp.text
|
394 |
415 |
|
395 |
416 |
|
396 |
417 |
def test_basketitem_error_list_search(app, admin_user, payment_backend):
|
... | ... | |
428 |
449 |
assert list(resp.context['object_list']) == [item]
|
429 |
450 |
|
430 |
451 |
|
|
452 |
def test_basketitem_mark_as_notified(app, admin_user, payment_backend):
|
|
453 |
regie = Regie.objects.create(
|
|
454 |
label='test-regie', slug='test-regie', payment_backend=payment_backend)
|
|
455 |
user = User.objects.create_user('dimebag', 'dime@bag.pan', 'pwd')
|
|
456 |
|
|
457 |
date_now = now()
|
|
458 |
date_in_past = date_now - datetime.timedelta(minutes=300)
|
|
459 |
|
|
460 |
item = BasketItem.objects.create(
|
|
461 |
user=user,
|
|
462 |
regie=regie,
|
|
463 |
subject='item',
|
|
464 |
source_url='http://example.net/',
|
|
465 |
amount=42,
|
|
466 |
payment_date=date_in_past,
|
|
467 |
notification_date=date_in_past)
|
|
468 |
|
|
469 |
app = login(app)
|
|
470 |
|
|
471 |
# notification_date is not None
|
|
472 |
resp = app.get('/manage/lingo/item/%s/mark-as-notified/' % item.pk, status=404)
|
|
473 |
# payment_date is not old enough
|
|
474 |
item.notification_date = None
|
|
475 |
item.payment_date = date_now
|
|
476 |
item.save()
|
|
477 |
resp = app.get('/manage/lingo/item/%s/mark-as-notified/' % item.pk, status=404)
|
|
478 |
# cancellation_date is not None
|
|
479 |
item.payment_date = date_in_past
|
|
480 |
item.cancellation_date = date_now
|
|
481 |
item.save()
|
|
482 |
resp = app.get('/manage/lingo/item/%s/mark-as-notified/' % item.pk, status=404)
|
|
483 |
# notification_date and cancellation_date are None, payment_date is old enough
|
|
484 |
# but webservice_url is not None
|
|
485 |
item.cancellation_date = None
|
|
486 |
item.save()
|
|
487 |
regie.webservice_url = 'http://example.net'
|
|
488 |
regie.save()
|
|
489 |
resp = app.get('/manage/lingo/item/%s/mark-as-notified/' % item.pk, status=404)
|
|
490 |
# notification_date and cancellation_date are None, payment_date is old enough
|
|
491 |
# but source_url is not set
|
|
492 |
regie.webservice_url = ''
|
|
493 |
regie.save()
|
|
494 |
item.source_url = ''
|
|
495 |
item.save()
|
|
496 |
resp = app.get('/manage/lingo/item/%s/mark-as-notified/' % item.pk, status=404)
|
|
497 |
|
|
498 |
# source_url is set
|
|
499 |
item.source_url = 'http://example.com'
|
|
500 |
item.save()
|
|
501 |
with mock.patch('combo.apps.lingo.models.BasketItem.notify') as mock_notify:
|
|
502 |
resp = app.get('/manage/lingo/item/%s/mark-as-notified/' % item.pk, status=302)
|
|
503 |
assert mock_notify.call_args_list == []
|
|
504 |
assert resp.location.endswith('/manage/lingo/payments/error/')
|
|
505 |
item.refresh_from_db()
|
|
506 |
assert item.notification_date is not None
|
|
507 |
|
|
508 |
|
431 |
509 |
def test_configure_tipi_cell(app, admin_user):
|
432 |
510 |
page = Page(title='tipi', slug='tipi', template_name='standard')
|
433 |
511 |
page.save()
|
434 |
|
-
|