Projet

Général

Profil

0003-tests-use-freezegun-in-test_notification-22732.patch

Benjamin Dauvergne, 24 mars 2018 02:20

Télécharger (3,85 ko)

Voir les différences:

Subject: [PATCH 3/5] tests: use freezegun in test_notification (#22732)

 tests/test_notification.py | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
tests/test_notification.py
255 255

  
256 256

  
257 257
@mock.patch('combo.apps.lingo.models.requests.get')
258
def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie):
259

  
260
    datetime_format = '%Y-%m-%dT%H:%M:%S'
261
    invoice_now = now()
262
    creation_date = (invoice_now - timedelta(days=1)).strftime(datetime_format)
263
    pay_limit_date = (invoice_now + timedelta(days=20)).strftime(datetime_format)
264
    new_pay_limit_date = (invoice_now + timedelta(days=5)).strftime(datetime_format)
258
@pytest.mark.freeze_time('2016-01-02')
259
def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, freezer):
260
    invoice_now = freezer()
265 261
    FAKE_PENDING_INVOICES = {
266 262
        "data":
267 263
        {
......
272 268
                        'label': '010101',
273 269
                        'total_amount': '10',
274 270
                        'amount': '10',
275
                        'created': creation_date,
276
                        'pay_limit_date': pay_limit_date,
271
                        'created': '2016-01-01T09:00:00',
272
                        'pay_limit_date': '2016-01-20T09:00:00',
277 273
                        'has_pdf': False,
278 274
                    },
279 275
                    {
......
281 277
                        'label': '0101011',
282 278
                        'total_amount': '1.5',
283 279
                        'amount': '1.5',
284
                        'created': creation_date,
285
                        'pay_limit_date': pay_limit_date,
280
                        'created': '2016-01-01T09:00:00',
281
                        'pay_limit_date': '2016-01-20T09:00:00',
286 282
                        'has_pdf': False,
287 283
                    }
288 284
                ]
......
294 290
                        'label': '020202',
295 291
                        'total_amount': '2.0',
296 292
                        'amount': '2.0',
297
                        'created': creation_date,
298
                        'pay_limit_date': pay_limit_date,
293
                        'created': '2016-01-01T09:00:00',
294
                        'pay_limit_date': '2016-01-20T09:00:00',
299 295
                        'has_pdf': False,
300 296
                    }
301 297
                ]
......
308 304
                        'label': '030303',
309 305
                        'total_amount': '42',
310 306
                        'amount': '42',
311
                        'created': creation_date,
312
                        'pay_limit_date': pay_limit_date,
307
                        'created': '2016-01-01T09:00:00',
308
                        'pay_limit_date': '2016-01-20T09:00:00',
313 309
                        'has_pdf': False,
314 310
                    }
315 311
                ]
......
336 332
    cell = ActiveItems(page=page, placeholder='content', order=0)
337 333
    cell.save()
338 334

  
339
    for john_doe in FAKE_PENDING_INVOICES['data']:
340
        for invoice in FAKE_PENDING_INVOICES['data'][john_doe]['invoices']:
341
            invoice['pay_limit_date'] = new_pay_limit_date
335
    freezer.move_to(invoice_now + timedelta(days=16))
342 336

  
343 337
    # create remind notifications
344 338
    regie.notify_new_remote_invoices()
345
-