tests: use freezegun in test_notification (#22732)

This commit is contained in:
Benjamin Dauvergne 2018-03-24 02:09:33 +01:00 committed by Frédéric Péters
parent 1e892549f9
commit a16ee38a99
1 changed files with 18 additions and 21 deletions

View File

@ -256,12 +256,11 @@ def test_notification_id_and_origin(john_doe):
@mock.patch('combo.utils.requests_wrapper.RequestsSession.request')
def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypatch):
@pytest.mark.freeze_time('2016-01-02')
def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypatch, freezer):
datetime_format = '%Y-%m-%dT%H:%M:%S'
invoice_now = now()
creation_date = (invoice_now - timedelta(days=1)).date().isoformat()
pay_limit_date = (invoice_now + timedelta(days=20)).date().isoformat()
new_pay_limit_date = (invoice_now + timedelta(days=5)).date().isoformat()
invoice_now = freezer()
FAKE_PENDING_INVOICES = {
"data":
{
@ -272,8 +271,8 @@ def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypat
'label': '010101',
'total_amount': '10',
'amount': '10',
'created': creation_date,
'pay_limit_date': pay_limit_date,
'created': '2016-01-01',
'pay_limit_date': '2016-01-20',
'has_pdf': False,
},
{
@ -281,8 +280,8 @@ def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypat
'label': '0101011',
'total_amount': '1.5',
'amount': '1.5',
'created': creation_date,
'pay_limit_date': pay_limit_date,
'created': '2016-01-01',
'pay_limit_date': '2016-01-20',
'has_pdf': False,
}
]
@ -294,8 +293,8 @@ def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypat
'label': '020202',
'total_amount': '2.0',
'amount': '2.0',
'created': creation_date,
'pay_limit_date': pay_limit_date,
'created': '2016-01-01',
'pay_limit_date': '2016-01-20',
'has_pdf': False,
},
{
@ -304,8 +303,8 @@ def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypat
'label': '050505',
'total_amount': '24',
'amount': '24',
'created': (invoice_now - timedelta(days=25)).date().isoformat(),
'pay_limit_date': (invoice_now - timedelta(days=10)).date().isoformat(),
'created': '2015-12-05',
'pay_limit_date': '2015-12-30',
'has_pdf': False,
}
]
@ -318,8 +317,8 @@ def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypat
'label': '030303',
'total_amount': '42',
'amount': '42',
'created': creation_date,
'pay_limit_date': pay_limit_date,
'created': '2016-01-01',
'pay_limit_date': '2016-01-20',
'has_pdf': False,
}
]
@ -378,21 +377,19 @@ def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypat
cell = ActiveItems(page=page, placeholder='content', order=0)
cell.save()
for username in FAKE_PENDING_INVOICES['data']:
for invoice in FAKE_PENDING_INVOICES['data'][username]['invoices']:
invoice['pay_limit_date'] = new_pay_limit_date
freezer.move_to(invoice_now + timedelta(days=16))
# create remind notifications
regie.notify_new_remote_invoices()
assert Notification.objects.exclude(external_id__startswith='invoice-%s:reminder-' % regie.slug) \
.visible().count() == 0
assert Notification.objects.filter(external_id__startswith='invoice-%s:reminder-' % regie.slug) \
.visible().new().count() == 3
assert Notification.objects.count() == 5
.visible().new().count() == 2
assert Notification.objects.count() == 4
# url appeared on new reminder notifications
assert len([notif for notif in Notification.objects.all() if notif.url == page.get_online_url()]) == 3
assert len([notif for notif in Notification.objects.all() if notif.url == page.get_online_url()]) == 2
# be sure the are no more reminders created
regie.notify_new_remote_invoices()
assert Notification.objects.count() == 5
assert Notification.objects.count() == 4