File tree Expand file tree Collapse file tree 2 files changed +37
-8
lines changed
tests/all/integration/api/helpers Expand file tree Collapse file tree 2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -164,14 +164,12 @@ def expire_pending_tickets():
164164def event_invoices_mark_due ():
165165 from app import current_app as app
166166 with app .app_context ():
167- db .session .query (EventInvoice ).\
168- filter (EventInvoice .status == 'upcoming' ,
169- EventInvoice .event .ends_at >= datetime .datetime .now (),
170- (EventInvoice .created_at + datetime .timedelta (days = 30 ) <=
171- datetime .datetime .now ())).\
172- update ({'status' : 'due' })
173-
174- db .session .commit ()
167+ db .session .query (EventInvoice ).filter (
168+ EventInvoice .status == 'upcoming' ,
169+ Event .id == EventInvoice .event_id ,
170+ Event .ends_at >= datetime .datetime .now (),
171+ (EventInvoice .created_at + datetime .timedelta (days = 30 ) <= datetime .datetime .now ())
172+ ).update ({EventInvoice .status : 'due' }, synchronize_session = False )
175173
176174
177175def send_monthly_event_invoice ():
Original file line number Diff line number Diff line change 1+ import datetime
2+
3+ from app import current_app as app , db
4+ from app .factories .event_invoice import EventInvoiceFactory
5+ from app .models .event_invoice import EventInvoice
6+ from app .api .helpers .scheduled_jobs import event_invoices_mark_due
7+
8+ from tests .all .integration .utils import OpenEventTestCase
9+
10+
11+ class TestScheduledJobs (OpenEventTestCase ):
12+
13+ def test_event_invoices_mark_due (self ):
14+ """Method to test marking of event invoices as due"""
15+
16+ with app .test_request_context ():
17+ event_invoice_new = EventInvoiceFactory (event__ends_at = datetime .datetime (2019 , 7 , 20 ))
18+ event_invoice_paid = EventInvoiceFactory (status = "paid" )
19+
20+ db .session .commit ()
21+
22+ event_invoice_new_id = event_invoice_new .id
23+ event_invoice_paid_id = event_invoice_paid .id
24+
25+ event_invoices_mark_due ()
26+
27+ status_new = EventInvoice .query .get (event_invoice_new_id ).status
28+ status_paid = EventInvoice .query .get (event_invoice_paid_id ).status
29+
30+ self .assertEqual (status_new , "due" )
31+ self .assertNotEqual (status_paid , "due" )
You can’t perform that action at this time.
0 commit comments