def generate_summary_file(): """ We need this function in order to test the real generate_summary_file function. Its name has been changed to __... :return: the time necessary to execute this function """ start_time = time() # Read configuration config = DITICConfig() # List of emails list_emails = set(config.get_email_to_user().keys()) # List of possible status list_status = config.get_list_status() # Let use system config list system = config.get_system() rt_object = RTApi(system['server'], system['username'], system['password']) summary = __generate_summary_file(rt_object, list_emails, list_status) # The summary of all files will be flushed to this file. try: with open(summary_filename(system['working_dir'], system['summary_file']), 'w') as file_handler: dump(summary, file_handler) except IOError as e: raise IOError('Error:' + str(e)) return '%0.2f seconds' % (time() - start_time)
def generate_summary_file(): """ We need this function in order to test the real generate_summary_file function. Its name has been changed to __... :return: the time necessary to execute this function """ start_time = time() # Read configuration config = DITICConfig() # List of emails list_emails = set(config.get_email_to_user().keys()) # List of possible status list_status = config.get_list_status() # Let use system config list system = config.get_system() rt_object = RTApi(system['server'], system['username'], system['password']) summary = __generate_summary_file(rt_object, list_emails, list_status) # The summary of all files will be flushed to this file. try: with open( summary_filename(system['working_dir'], system['summary_file']), 'w') as file_handler: dump(summary, file_handler) except IOError as e: raise IOError('Error:' + str(e)) return '%0.2f seconds' % (time() - start_time)
def test_get_email_to_user(): test_config = DITICConfig() test_config.email_to_user = { '*****@*****.**': 'Vapi', '*****@*****.**': 'Alex', } response = test_config.get_email_to_user() assert response == { '*****@*****.**': 'Vapi', '*****@*****.**': 'Alex', }
def create_default_result(): # Default header configuration result = {"title": "Still testing..."} # Summary information result.update({"summary": get_summary_info()}) # Mapping email do uer alias config = DITICConfig() result.update({"alias": config.get_email_to_user()}) return result
def create_default_result(): # Default header configuration result = { 'title': 'Still testing...' } # Summary information result.update({'summary': get_summary_info()}) # Mapping email do uer alias config = DITICConfig() result.update({'alias': config.get_email_to_user()}) return result
def create_default_result(): # Default header configuration result = {'title': 'Dashboard'} call(['update_statistics']) call(["generate_summary_file"]) # Summary information result.update({'summary': get_summary_info()}) # Mapping email do uer alias config = DITICConfig() result.update({'alias': config.get_email_to_user()}) return result
def get_summary_info(): """ returns a dictionary with the following format { 'email': { 'status': 'value', ... } ... } :return: """ #generate_summary_file() #retirar o comando generate_summary_file #stats_update_json_file() # retirar o comando update_statistics # Read configuration config = DITICConfig() # List of known emails list_emails = config.get_email_to_user().keys() # List of known status list_status = config.get_list_status() # Let use system config list system = config.get_system() # Get the file information try: with open( summary_filename(system['working_dir'], system['summary_file']), 'r') as file_handler: summary = load(file_handler) except IOError: # If there is an error, then return everything zeroed summary = { email: {status: 0 for status in list_status} for email in list_emails } summary['dir'] = {status: 0 for status in list_status} summary['dir-inbox'] = {status: 0 for status in list_status} summary['unknown'] = {status: 0 for status in list_status} return summary
def create_default_result(): # Default header configuration result = { 'title': 'Dashboard' } call(['update_statistics']) call(["generate_summary_file"]) # Summary information result.update({'summary': get_summary_info()}) # Mapping email do uer alias config = DITICConfig() result.update({'alias': config.get_email_to_user()}) return result
def get_summary_info(): """ returns a dictionary with the following format { 'email': { 'status': 'value', ... } ... } :return: """ #generate_summary_file() #retirar o comando generate_summary_file #stats_update_json_file() # retirar o comando update_statistics # Read configuration config = DITICConfig() # List of known emails list_emails = config.get_email_to_user().keys() # List of known status list_status = config.get_list_status() # Let use system config list system = config.get_system() # Get the file information try: with open(summary_filename(system['working_dir'], system['summary_file']), 'r') as file_handler: summary = load(file_handler) except IOError: # If there is an error, then return everything zeroed summary = {email: {status: 0 for status in list_status} for email in list_emails} summary['dir'] = {status: 0 for status in list_status} summary['dir-inbox'] = {status: 0 for status in list_status} summary['unknown'] = {status: 0 for status in list_status} return summary
class UserAuth: def __init__(self): self.config = DITICConfig() self.ids = { # Only used for tests... # u'10': { # 'email': '*****@*****.**', # 'rt_object': RTApi('server_address', 'username', 'password'), # } } def __get_new_id(self): while True: new_id = unicode(randint(0, 1000)) if new_id not in self.ids: return new_id # noinspection PyTypeChecker def get_email_id(self, email): if email not in self.config.get_email_to_user().keys(): raise ValueError('Unknown email') for uid in self.ids: if email == self.ids[uid]['email']: return uid raise ValueError('Unknown error! This should not be like this...') # noinspection PyTypeChecker def get_email_from_id(self, uid): if 'email' not in self.ids[uid]: raise ValueError('Unauthenticated user') return self.ids[uid]['email'] # noinspection PyTypeChecker,PyTypeChecker def get_rt_object_from_email(self, email): if email not in self.config.get_email_to_user().keys(): raise ValueError('Unknown email') for uid in self.ids: if email == self.ids[uid]['email']: return self.ids[uid]['rt_object'] raise ValueError('Unknown error! This should not be like this...') def check_id(self, uid): """ This function will check if id exists. It is important to say that id MUST be a unicode value! :param uid: unicode with id value :return: True or False, depending if ID exists or not """ if uid in self.ids: return True return False def check_password(self, email, pwd): if email not in self.config.get_email_to_user().keys(): raise ValueError('Unknown email') # Get system configurations system = self.config.get_system() # To check the password, we will try to check if user has any new ticket email_rt_api = RTApi(system['server'], email, pwd) data_dict = {'query': 'Owner = "%s" and Status = "new"' % email} response = email_rt_api.get_data_from_rest('/search/ticket', data_dict) if 'your username or password is incorrect' in response: raise ValueError('Password is incorrect') self.ids[self.__get_new_id()] = { 'email': email, 'rt_object': email_rt_api, } return True
def user_tickets_details(rt_object, email): query = 'Owner = "' + email + '" AND Queue = "general" ' config = DITICConfig() # If the user is dir, then build the search if email == 'dir': query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR" AND Owner = "Nobody" AND ' \ 'Status != "deleted" ' # If the user is dir-inbox, then search for it elif email == 'dir-inbox': query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" AND Owner = "Nobody" AND ' \ 'Status != "deleted" ' # If the user is unknown, then search all users but those that we already know elif email == 'unknown': query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" LIKE "DIR%" AND ' \ 'Status != "deleted" ' for user in config.get_email_to_user().keys(): query += 'AND Owner != "' + user + '" ' query += 'AND Owner != "Nobody"' # Otherwise, check if user is not known... elif not config.check_if_email_exist(email): raise ValueError('Unknown email/user:'******' AND Status != "deleted" ' # Get the information from the server. try: response = get_list_of_tickets(rt_object, query) except ValueError as e: response = [] if email == 'dir' or email == 'dir-inbox' or email == 'unknown': number_tickets_per_status = {email: len(response)} result = group_result_by(response, 'priority') for priority in result: for line in result[priority]: create_ticket_possible_actions(config, line, email, number_tickets_per_status) else: # Get some statistics response_grouped_by_status = group_result_by(response, 'status') number_tickets_per_status = {} for status in response_grouped_by_status: number_tickets_per_status[status] = len( response_grouped_by_status[status]) result = {} for status in response_grouped_by_status: grouped_by_priority = group_result_by( response_grouped_by_status[status], 'priority') result[status] = grouped_by_priority for priority in grouped_by_priority: for line in grouped_by_priority[priority]: create_ticket_possible_actions(config, line, email, number_tickets_per_status) # The user limits... email_limit = config.get_email_limits(email) return { 'tickets': result, 'number_tickets_per_status': number_tickets_per_status, 'email_limit': email_limit, }
def user_tickets_details(rt_object, email): query = 'Owner = "'+email+'" AND Queue = "general" ' config = DITICConfig() # If the user is dir, then build the search if email == 'dir': query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR" AND Owner = "Nobody" AND ' \ 'Status != "deleted" ' # If the user is dir-inbox, then search for it elif email == 'dir-inbox': query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" = "DIR-INBOX" AND Owner = "Nobody" AND ' \ 'Status != "deleted" ' # If the user is unknown, then search all users but those that we already know elif email == 'unknown': query = 'Queue = "general" AND "CF.{IS - Informatica e Sistemas}" LIKE "DIR%" AND ' \ 'Status != "deleted" ' for user in config.get_email_to_user().keys(): query += 'AND Owner != "'+user+'" ' query += 'AND Owner != "Nobody"' # Otherwise, check if user is not known... elif not config.check_if_email_exist(email): raise ValueError('Unknown email/user:'******' AND Status != "deleted" ' # Get the information from the server. try: response = get_list_of_tickets(rt_object, query) except ValueError as e: response = [] if email == 'dir' or email == 'dir-inbox' or email == 'unknown': number_tickets_per_status = {email: len(response)} result = group_result_by(response, 'priority') for priority in result: for line in result[priority]: create_ticket_possible_actions(config, line, email, number_tickets_per_status) else: # Get some statistics response_grouped_by_status = group_result_by(response, 'status') number_tickets_per_status = {} for status in response_grouped_by_status: number_tickets_per_status[status] = len(response_grouped_by_status[status]) result = {} for status in response_grouped_by_status: grouped_by_priority = group_result_by(response_grouped_by_status[status], 'priority') result[status] = grouped_by_priority for priority in grouped_by_priority: for line in grouped_by_priority[priority]: create_ticket_possible_actions(config, line, email, number_tickets_per_status) # The user limits... email_limit = config.get_email_limits(email) return { 'tickets': result, 'number_tickets_per_status': number_tickets_per_status, 'email_limit': email_limit, }