def test_notification_is_attached(self): todo = frappe.get_doc( dict(doctype='ToDo', description='Test recurring notification attachment', assigned_by='Administrator')).insert() doc = make_auto_repeat( reference_document=todo.name, notify=1, recipients="*****@*****.**", subject="New ToDo", message="A new ToDo has just been created for you") data = get_auto_repeat_entries(getdate(today())) create_repeated_entries(data) frappe.db.commit() new_todo = frappe.db.get_value('ToDo', { 'auto_repeat': doc.name, 'name': ('!=', todo.name) }, 'name') linked_comm = frappe.db.exists( "Communication", dict(reference_doctype="ToDo", reference_name=new_todo)) self.assertTrue(linked_comm)
def monthly_auto_repeat(self, doctype, docname, start_date, end_date = None): def get_months(start, end): diff = (12 * end.year + end.month) - (12 * start.year + start.month) return diff + 1 doc = make_auto_repeat( reference_doctype=doctype, frequency='Monthly', reference_document=docname, start_date=start_date, end_date=end_date) doc.disable_auto_repeat() data = get_auto_repeat_entries(getdate(today())) create_repeated_entries(data) docnames = frappe.get_all(doc.reference_doctype, {'auto_repeat': doc.name}) self.assertEqual(len(docnames), 1) doc = frappe.get_doc('Auto Repeat', doc.name) doc.db_set('disabled', 0) months = get_months(getdate(start_date), getdate(today())) data = get_auto_repeat_entries(getdate(today())) create_repeated_entries(data) docnames = frappe.get_all(doc.reference_doctype, {'auto_repeat': doc.name}) self.assertEqual(len(docnames), months)
def test_weekly_auto_repeat_with_weekdays(self): todo = frappe.get_doc( dict(doctype='ToDo', description='test auto repeat with weekdays', assigned_by='Administrator')).insert() weekdays = list(week_map.keys()) current_weekday = getdate().weekday() days = [{ 'day': weekdays[current_weekday] }, { 'day': weekdays[(current_weekday + 2) % 7] }] doc = make_auto_repeat(reference_doctype='ToDo', frequency='Weekly', reference_document=todo.name, start_date=add_days(today(), -7), days=days) self.assertEqual(doc.next_schedule_date, today()) data = get_auto_repeat_entries(getdate(today())) create_repeated_entries(data) frappe.db.commit() todo = frappe.get_doc(doc.reference_doctype, doc.reference_document) self.assertEqual(todo.auto_repeat, doc.name) doc.reload() self.assertEqual(doc.next_schedule_date, add_days(getdate(), 2))
def test_weekly_auto_repeat(self): todo = frappe.get_doc( dict(doctype='ToDo', description='test weekly todo', assigned_by='Administrator')).insert() doc = make_auto_repeat(reference_doctype='ToDo', frequency='Weekly', reference_document=todo.name, start_date=add_days(today(), -7)) self.assertEqual(doc.next_schedule_date, today()) data = get_auto_repeat_entries(getdate(today())) create_repeated_entries(data) frappe.db.commit() todo = frappe.get_doc(doc.reference_doctype, doc.reference_document) self.assertEqual(todo.auto_repeat, doc.name) new_todo = frappe.db.get_value('ToDo', { 'auto_repeat': doc.name, 'name': ('!=', todo.name) }, 'name') new_todo = frappe.get_doc('ToDo', new_todo) self.assertEqual(todo.get('description'), new_todo.get('description'))
def test_submit_on_creation(self): doctype = 'Test Submittable DocType' create_submittable_doctype(doctype) current_date = getdate() submittable_doc = frappe.get_doc(dict(doctype=doctype, test='test submit on creation')).insert() submittable_doc.submit() doc = make_auto_repeat(frequency='Daily', reference_doctype=doctype, reference_document=submittable_doc.name, start_date=add_days(current_date, -1), submit_on_creation=1) data = get_auto_repeat_entries(current_date) create_repeated_entries(data) docnames = frappe.db.get_all(doc.reference_doctype, filters={'auto_repeat': doc.name}, fields=['docstatus'], limit=1 ) self.assertEquals(docnames[0].docstatus, 1)
def test_next_schedule_date(self): current_date = getdate(today()) todo = frappe.get_doc( dict(doctype='ToDo', description='test next schedule date todo', assigned_by='Administrator')).insert() doc = make_auto_repeat(frequency='Monthly', reference_document=todo.name, start_date=add_months(today(), -2)) #check next_schedule_date is set as per current date #it should not be a previous month's date self.assertEqual(doc.next_schedule_date, current_date) data = get_auto_repeat_entries(current_date) create_repeated_entries(data) docnames = frappe.get_all(doc.reference_doctype, {'auto_repeat': doc.name}) #the original doc + the repeated doc self.assertEqual(len(docnames), 2)
def test_next_schedule_date(self): current_date = getdate(today()) todo = frappe.get_doc( dict(doctype='ToDo', description='test next schedule date todo', assigned_by='Administrator')).insert() doc = make_auto_repeat(frequency='Monthly', reference_document=todo.name, start_date=add_months(today(), -2)) #check next_schedule_date self.assertEqual(doc.next_schedule_date, getdate(add_months(today(), -2))) data = get_auto_repeat_entries(current_date) create_repeated_entries(data) docnames = frappe.get_all(doc.reference_doctype, filters={'auto_repeat': doc.name}) #the original doc + the repeated doc self.assertEqual(len(docnames), 3) doc.load_from_db() self.assertEqual(doc.next_schedule_date, getdate(add_months(today(), 1)))