def test_group_result_by_known_parameter(): data = [ { 'owner': '*****@*****.**', 'status': 'open', }, { 'owner': '*****@*****.**', 'status': 'resolved', }, ] result = group_result_by(data, 'owner') assert result == { '*****@*****.**': [ { 'owner': '*****@*****.**', 'status': 'open', } ], '*****@*****.**': [ { 'owner': '*****@*****.**', 'status': 'resolved', } ], }
def test_group_result_by_known_parameter(): data = [ { 'owner': '*****@*****.**', 'status': 'open', }, { 'owner': '*****@*****.**', 'status': 'resolved', }, ] result = group_result_by(data, 'owner') assert result == { '*****@*****.**': [{ 'owner': '*****@*****.**', 'status': 'open', }], '*****@*****.**': [{ 'owner': '*****@*****.**', 'status': 'resolved', }], }
def __generate_summary_file(rt_object, list_emails, list_status): """ This function will search all tickets and generate a summary to be used by the summary report. :param rt_object: the rt_object for accessing get_list_of_tickets :param list_emails: A set with the known emails. It is a set to optimize the search :param list_status: A list of available status :return: summary (TODO: how it is done!) """ # Get the date from which we start searching tickets. previous_date = (date.today() - timedelta(0)).isoformat() # First step: search for all tickets of known emails known_email_query = '' for email in DITICConfig().get_email_to_user().keys(): if known_email_query: known_email_query += ' OR ' known_email_query += ' Owner = "%s" ' % email email_query = ' AND ('+known_email_query+') ' # Get the information from the server. try: response = get_list_of_tickets(rt_object, r'Queue = "general" AND ( Resolved > "%s" ' r'OR Status != "deleted" ) %s' % (previous_date, email_query)) except ValueError as e: raise ValueError('Error1:' + str(e)) # Second step: search for all tickets of DIR and DIR-INBOX try: response += get_list_of_tickets(rt_object, r'Queue = "general" AND ( "CF.{IS - Informatica e Sistemas}" = "DIR"' r'OR "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" )' r'AND Owner = "nobody" AND Status != "resolved" ' r'AND Status != "deleted" ') except ValueError as e: #raise ValueError('Error:2' + str(e)) pass # Third step: search for all tickets of unknown emails known_email_query = '' for email in DITICConfig().get_email_to_user().keys(): known_email_query += ' AND Owner != "%s" ' % email email_query = known_email_query+' AND Owner != "nobody" ' # Get the information from the server. try: response += get_list_of_tickets(rt_object, ''' Queue = "general" AND Status != "deleted" AND ( "CF.{IS - Informatica e Sistemas}" = "DIR"' OR "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" ) %s ''' % email_query) except ValueError as e: if str(e) != 'no matching results.': raise ValueError('Error:3' + str(e)) # Lets create summary dictionary summary = dict() summary['unknown'] = {status: 0 for status in list_status} summary['dir'] = {status: 0 for status in list_status} summary['dir-inbox'] = {status: 0 for status in list_status} group_by_email = group_result_by(response, 'owner') for email in sorted(group_by_email.keys()): group_by_status = group_result_by(group_by_email[email], 'status') # If this email is known, then identify it # If user is nobody, then it can be DIR or DIR-INBOX # Otherwise, it is unknown! if email in list_emails: summary[email] = {status: 0 for status in list_status} elif email == 'nobody': pass else: email = 'unknown' # Count the number of tickets in every status for this email for status in sorted(group_by_status.keys()): if email == 'nobody': group_by_cf = group_result_by(group_by_status[status], 'cf.{is - informatica e sistemas}') summary['dir'][status] += len(group_by_cf.get('dir', '')) summary['dir-inbox'][status] += len(group_by_cf.get('dir-inbox', '')) else: summary[email][status] += len(group_by_status[status]) return summary
def __generate_summary_file(rt_object, list_emails, list_status): """ This function will search all tickets and generate a summary to be used by the summary report. :param rt_object: the rt_object for accessing get_list_of_tickets :param list_emails: A set with the known emails. It is a set to optimize the search :param list_status: A list of available status :return: summary (TODO: how it is done!) """ # Get the date from which we start searching tickets. previous_date = (date.today() - timedelta(0)).isoformat() # First step: search for all tickets of known emails known_email_query = '' for email in DITICConfig().get_email_to_user().keys(): if known_email_query: known_email_query += ' OR ' known_email_query += ' Owner = "%s" ' % email email_query = ' AND (' + known_email_query + ') ' # Get the information from the server. try: response = get_list_of_tickets( rt_object, r'Queue = "general" AND ( Resolved > "%s" ' r'OR ( Status != "resolved" ' r'AND Status != "deleted" ) ) %s' % (previous_date, email_query)) except ValueError as e: raise ValueError('Error1:' + str(e)) # Second step: search for all tickets of DIR and DIR-INBOX try: response += get_list_of_tickets( rt_object, r'Queue = "general" AND ( "CF.{IS - Informatica e Sistemas}" = "INBOX"' r'OR "CF.{IS - Informatica e Sistemas}" = "INBOX" )' r'AND Owner = "nobody" AND Status != "resolved" ' r'AND Status != "deleted" ') except ValueError as e: #raise ValueError('Error:2' + str(e)) pass # Third step: search for all tickets of unknown emails known_email_query = '' for email in DITICConfig().get_email_to_user().keys(): known_email_query += ' AND Owner != "%s" ' % email email_query = known_email_query + ' AND Owner != "nobody" ' # Get the information from the server. try: response += get_list_of_tickets( rt_object, ''' Queue = "general" AND Status != "resolved" AND Status != "deleted" AND ( "CF.{IS - Informatica e Sistemas}" = "INBOX"' OR "CF.{IS - Informatica e Sistemas}" = "INBOX" ) %s ''' % email_query) except ValueError as e: if str(e) != 'no matching results.': raise ValueError('Error:3' + str(e)) # Lets create summary dictionary summary = dict() summary['unknown'] = {status: 0 for status in list_status} summary['inbox'] = {status: 0 for status in list_status} #summary['dir-inbox'] = {status: 0 for status in list_status} group_by_email = group_result_by(response, 'owner') for email in sorted(group_by_email.keys()): group_by_status = group_result_by(group_by_email[email], 'status') # If this email is known, then identify it # If user is nobody, then it can be DIR or DIR-INBOX # Otherwise, it is unknown! if email in list_emails: summary[email] = {status: 0 for status in list_status} elif email == 'nobody': pass else: email = 'unknown' # Count the number of tickets in every status for this email for status in sorted(group_by_status.keys()): if email == 'nobody': group_by_cf = group_result_by( group_by_status[status], 'cf.{is - informatica e sistemas}') #summary['dir'][status] += len(group_by_cf.get('dir', '')) summary['inbox'][status] += len(group_by_cf.get('inbox', '')) else: summary[email][status] += len(group_by_status[status]) return summary