test: new test cases
This commit is contained in:
parent
2c5ccb0529
commit
87b6b71f44
2 changed files with 48 additions and 28 deletions
|
|
@ -130,12 +130,8 @@ class AssignmentRule(Document):
|
|||
return [d.day for d in self.assignment_days]
|
||||
|
||||
def is_rule_not_applicable_today(self):
|
||||
# If today is in assignment_rule_days then return False
|
||||
# If today is not in assignment_rule_days then return True
|
||||
today = frappe.utils.get_weekday()
|
||||
print(today)
|
||||
today = frappe.flags.assignment_day or frappe.utils.get_weekday()
|
||||
assignment_days = self.get_assignment_days()
|
||||
print(assignment_days)
|
||||
if assignment_days and not today in assignment_days:
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,21 @@ from __future__ import unicode_literals
|
|||
import frappe
|
||||
import unittest
|
||||
from frappe.utils import random_string
|
||||
from frappe.test_runner import make_test_records
|
||||
|
||||
class TestAutoAssign(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.assignment_rule = get_assignment_rule()
|
||||
make_test_records("User")
|
||||
days = [
|
||||
dict(day = 'Sunday'),
|
||||
dict(day = 'Monday'),
|
||||
dict(day = 'Tuesday'),
|
||||
dict(day = 'Wednesday'),
|
||||
dict(day = 'Thursday'),
|
||||
dict(day = 'Friday'),
|
||||
dict(day = 'Saturday'),
|
||||
]
|
||||
self.assignment_rule = get_assignment_rule([days, days])
|
||||
clear_assignments()
|
||||
|
||||
def test_round_robin(self):
|
||||
|
|
@ -142,30 +153,52 @@ class TestAutoAssign(unittest.TestCase):
|
|||
status = 'Open'
|
||||
), 'owner'), 'test@example.com')
|
||||
|
||||
def check_assignment_rule_scheduling(self):
|
||||
frappe.db.sql("DELETE FROM `tabAssignment Rule`")
|
||||
|
||||
days_1 = [dict(day = 'Sunday'), dict(day = 'Monday'), dict(day = 'Tuesday')]
|
||||
|
||||
days_2 = [dict(day = 'Wednesday'), dict(day = 'Thursday'), dict(day = 'Friday'), dict(day = 'Saturday')]
|
||||
|
||||
get_assignment_rule([days_1, days_2], ['public == 1', 'public == 1'])
|
||||
|
||||
frappe.flags.assignment_day = "Monday"
|
||||
note = make_note(dict(public=1))
|
||||
|
||||
self.assertIn(frappe.db.get_value('ToDo', dict(
|
||||
reference_type = 'Note',
|
||||
reference_name = note.name,
|
||||
status = 'Open'
|
||||
), 'owner'), ['test@example.com', 'test1@example.com', 'test2@example.com'])
|
||||
|
||||
frappe.flags.assignment_day = "Friday"
|
||||
note = make_note(dict(public=1))
|
||||
|
||||
self.assertIn(frappe.db.get_value('ToDo', dict(
|
||||
reference_type = 'Note',
|
||||
reference_name = note.name,
|
||||
status = 'Open'
|
||||
), 'owner'), ['test3@example.com'])
|
||||
|
||||
def clear_assignments():
|
||||
frappe.db.sql("delete from tabToDo where reference_type = 'Note'")
|
||||
|
||||
def get_assignment_rule():
|
||||
def get_assignment_rule(days, assign=None):
|
||||
frappe.delete_doc_if_exists('Assignment Rule', 'For Note 1')
|
||||
|
||||
if not assign:
|
||||
assign = ['public == 1', 'notify_on_login == 1']
|
||||
|
||||
assignment_rule = frappe.get_doc(dict(
|
||||
name = 'For Note 1',
|
||||
doctype = 'Assignment Rule',
|
||||
priority = 0,
|
||||
document_type = 'Note',
|
||||
assign_condition = 'public == 1',
|
||||
assign_condition = assign[0],
|
||||
unassign_condition = 'public == 0 or notify_on_login == 1',
|
||||
close_condition = '"Closed" in content',
|
||||
rule = 'Round Robin',
|
||||
assignment_days = [
|
||||
dict(day = 'Sunday'),
|
||||
dict(day = 'Monday'),
|
||||
dict(day = 'Tueday'),
|
||||
dict(day = 'Wednesday'),
|
||||
dict(day = 'Thursday'),
|
||||
dict(day = 'Friday'),
|
||||
dict(day = 'Saturday'),
|
||||
],
|
||||
assignment_days = days[0],
|
||||
users = [
|
||||
dict(user = 'test@example.com'),
|
||||
dict(user = 'test1@example.com'),
|
||||
|
|
@ -181,24 +214,15 @@ def get_assignment_rule():
|
|||
doctype = 'Assignment Rule',
|
||||
priority = 1,
|
||||
document_type = 'Note',
|
||||
assign_condition = 'notify_on_login == 1',
|
||||
assign_condition = assign[1],
|
||||
unassign_condition = 'notify_on_login == 0',
|
||||
rule = 'Round Robin',
|
||||
assignment_days = [
|
||||
dict(day = 'Sunday'),
|
||||
dict(day = 'Monday'),
|
||||
dict(day = 'Tueday'),
|
||||
dict(day = 'Wednesday'),
|
||||
dict(day = 'Thursday'),
|
||||
dict(day = 'Friday'),
|
||||
dict(day = 'Saturday'),
|
||||
],
|
||||
assignment_days = days[1],
|
||||
users = [
|
||||
dict(user = 'test3@example.com')
|
||||
]
|
||||
)).insert()
|
||||
|
||||
|
||||
return assignment_rule
|
||||
|
||||
def make_note(values=None):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue