From 2ae2ee09badfcbef3d5607ccd37c4aee01a9f728 Mon Sep 17 00:00:00 2001 From: mrsaicharan1 Date: Sun, 6 Oct 2019 19:40:39 +0530 Subject: [PATCH 1/4] fix: Fixed cron job and added tests - EVent Invoice Due Marking --- app/api/helpers/scheduled_jobs.py | 14 ++++---- .../api/helpers/test_scheduled_jobs.py | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 tests/all/integration/api/helpers/test_scheduled_jobs.py diff --git a/app/api/helpers/scheduled_jobs.py b/app/api/helpers/scheduled_jobs.py index 4c1dfa1628..c52da33165 100644 --- a/app/api/helpers/scheduled_jobs.py +++ b/app/api/helpers/scheduled_jobs.py @@ -164,14 +164,12 @@ def expire_pending_tickets(): def event_invoices_mark_due(): from app import current_app as app with app.app_context(): - db.session.query(EventInvoice).\ - filter(EventInvoice.status == 'upcoming', - EventInvoice.event.ends_at >= datetime.datetime.now(), - (EventInvoice.created_at + datetime.timedelta(days=30) <= - datetime.datetime.now())).\ - update({'status': 'due'}) - - db.session.commit() + db.session.query(EventInvoice).filter( + EventInvoice.status == 'upcoming', + Event.id == EventInvoice.event_id, + Event.ends_at >= datetime.datetime.now(), + (EventInvoice.created_at + datetime.timedelta(days=30) <= datetime.datetime.now()) + ).update({EventInvoice.status: 'due'}, synchronize_session=False) def send_monthly_event_invoice(): diff --git a/tests/all/integration/api/helpers/test_scheduled_jobs.py b/tests/all/integration/api/helpers/test_scheduled_jobs.py new file mode 100644 index 0000000000..6d262ce38b --- /dev/null +++ b/tests/all/integration/api/helpers/test_scheduled_jobs.py @@ -0,0 +1,36 @@ +import datetime + +from app import current_app as app, db +from app.factories.event_invoice import EventInvoiceFactory +from app.models.event_invoice import EventInvoice +from app.api.helpers.scheduled_jobs import event_invoices_mark_due + +from tests.all.integration.utils import OpenEventTestCase + + +class TestScheduledJobs(OpenEventTestCase): + + def test_event_invoices_mark_due(self): + """Method to test marking of event invoices as due""" + + with app.test_request_context(): + event_invoice = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20)) + db.session.commit() + event_invoice_id = event_invoice.id + status_1 = EventInvoice.query.get(event_invoice_id).status + + event_invoice = EventInvoiceFactory(status="paid") + db.session.commit() + event_invoice_id = event_invoice.id + status_2 = EventInvoice.query.get(event_invoice_id).status + + event_invoice = EventInvoiceFactory() + event_invoice.created_at = datetime.datetime(2099, 12, 14) + db.session.commit() + event_invoice_id = event_invoice.id + status_3 = EventInvoice.query.get(event_invoice_id).status + + event_invoices_mark_due() + self.assertEqual(status_1, "due") + self.assertNotEqual(status_2, "due") + self.assertNotEqual(status_3, "due") From 9ae08d2c58885deb0572dcf59d8641d7f3ae2fda Mon Sep 17 00:00:00 2001 From: Areeb Jamal Date: Tue, 8 Oct 2019 22:52:40 +0530 Subject: [PATCH 2/4] Update test_scheduled_jobs.py --- .../api/helpers/test_scheduled_jobs.py | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/all/integration/api/helpers/test_scheduled_jobs.py b/tests/all/integration/api/helpers/test_scheduled_jobs.py index 6d262ce38b..335b72965f 100644 --- a/tests/all/integration/api/helpers/test_scheduled_jobs.py +++ b/tests/all/integration/api/helpers/test_scheduled_jobs.py @@ -14,23 +14,22 @@ def test_event_invoices_mark_due(self): """Method to test marking of event invoices as due""" with app.test_request_context(): - event_invoice = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20)) + event_invoice_new = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20)) + event_invoice_paid = EventInvoiceFactory(status="paid") + event_invoice_future = EventInvoiceFactory(created_at=datetime.datetime(2099, 12, 14)) + db.session.commit() - event_invoice_id = event_invoice.id - status_1 = EventInvoice.query.get(event_invoice_id).status - - event_invoice = EventInvoiceFactory(status="paid") - db.session.commit() - event_invoice_id = event_invoice.id - status_2 = EventInvoice.query.get(event_invoice_id).status - - event_invoice = EventInvoiceFactory() - event_invoice.created_at = datetime.datetime(2099, 12, 14) - db.session.commit() - event_invoice_id = event_invoice.id - status_3 = EventInvoice.query.get(event_invoice_id).status - + + event_invoice_new_id = event_invoice_new.id + event_invoice_paid_id = event_invoice_paid.id + event_invoice_future_id = event_invoice_future.id + event_invoices_mark_due() - self.assertEqual(status_1, "due") - self.assertNotEqual(status_2, "due") - self.assertNotEqual(status_3, "due") + + status_new = EventInvoice.query.get(event_invoice_new_id).status + status_paid = EventInvoice.query.get(event_invoice_paid_id).status + status_future = EventInvoice.query.get(event_invoice_future_id).status + + self.assertEqual(status_new, "due") + self.assertNotEqual(status_paid, "due") + self.assertNotEqual(status_future, "due") From 3336d0cb13cf666e12be3ff71a019ae73abb9a56 Mon Sep 17 00:00:00 2001 From: Areeb Jamal Date: Tue, 8 Oct 2019 22:57:04 +0530 Subject: [PATCH 3/4] Update test_scheduled_jobs.py --- .../integration/api/helpers/test_scheduled_jobs.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/all/integration/api/helpers/test_scheduled_jobs.py b/tests/all/integration/api/helpers/test_scheduled_jobs.py index 335b72965f..0a92ad4b18 100644 --- a/tests/all/integration/api/helpers/test_scheduled_jobs.py +++ b/tests/all/integration/api/helpers/test_scheduled_jobs.py @@ -16,16 +16,17 @@ def test_event_invoices_mark_due(self): with app.test_request_context(): event_invoice_new = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20)) event_invoice_paid = EventInvoiceFactory(status="paid") - event_invoice_future = EventInvoiceFactory(created_at=datetime.datetime(2099, 12, 14)) - + event_invoice_future = EventInvoiceFactory() + event_invoice_future.created_at = datetime.datetime(2099, 12, 14) + db.session.commit() - + event_invoice_new_id = event_invoice_new.id event_invoice_paid_id = event_invoice_paid.id event_invoice_future_id = event_invoice_future.id - + event_invoices_mark_due() - + status_new = EventInvoice.query.get(event_invoice_new_id).status status_paid = EventInvoice.query.get(event_invoice_paid_id).status status_future = EventInvoice.query.get(event_invoice_future_id).status From 06d5402f6055476da3d3b80ba48a731f5e7c05a4 Mon Sep 17 00:00:00 2001 From: Areeb Jamal Date: Tue, 8 Oct 2019 23:02:37 +0530 Subject: [PATCH 4/4] Update test_scheduled_jobs.py --- tests/all/integration/api/helpers/test_scheduled_jobs.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/all/integration/api/helpers/test_scheduled_jobs.py b/tests/all/integration/api/helpers/test_scheduled_jobs.py index 0a92ad4b18..f638f87c7d 100644 --- a/tests/all/integration/api/helpers/test_scheduled_jobs.py +++ b/tests/all/integration/api/helpers/test_scheduled_jobs.py @@ -16,21 +16,16 @@ def test_event_invoices_mark_due(self): with app.test_request_context(): event_invoice_new = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20)) event_invoice_paid = EventInvoiceFactory(status="paid") - event_invoice_future = EventInvoiceFactory() - event_invoice_future.created_at = datetime.datetime(2099, 12, 14) db.session.commit() event_invoice_new_id = event_invoice_new.id event_invoice_paid_id = event_invoice_paid.id - event_invoice_future_id = event_invoice_future.id event_invoices_mark_due() status_new = EventInvoice.query.get(event_invoice_new_id).status status_paid = EventInvoice.query.get(event_invoice_paid_id).status - status_future = EventInvoice.query.get(event_invoice_future_id).status self.assertEqual(status_new, "due") self.assertNotEqual(status_paid, "due") - self.assertNotEqual(status_future, "due")