Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix and test cron job for Invoice Due Marking #6510

Merged
merged 4 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/api/helpers/scheduled_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
31 changes: 31 additions & 0 deletions tests/all/integration/api/helpers/test_scheduled_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import datetime

from app import current_app as app, db
iamareebjamal marked this conversation as resolved.
Show resolved Hide resolved
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():
iamareebjamal marked this conversation as resolved.
Show resolved Hide resolved
event_invoice_new = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20))
event_invoice_paid = EventInvoiceFactory(status="paid")

db.session.commit()

event_invoice_new_id = event_invoice_new.id
event_invoice_paid_id = event_invoice_paid.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

mrsaicharan1 marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(status_new, "due")
self.assertNotEqual(status_paid, "due")