class Main: def __init__(self): self.audit = Audit() self.audit.set_info(X_API_KEY, 'Arquivei-Consulta') self.db = DbController() self.api_consult = Consult() self.crypt = Crypt() def execute_consult(self): self.audit.insert_audit_log( 'Realizando consulta no endpoint do Arquivei') notes = self.api_consult.get_information() if notes: self.audit.insert_audit_log('{} notas encontradas'.format( len(notes['data']))) self.db_insert(notes) else: self.audit.insert_audit_log('Erro na consulta') def db_insert(self, notes): for note in notes['data']: self.audit.insert_audit_log('Inserindo chave de acesso: {}'.format( note['access_key'])) access_key = self.crypt.encrypt(note['access_key']) value = self.crypt.encrypt(str(base64.b64decode(note['xml']))) self.db.insert_file(access_key, value)
class Notes(Resource): def __init__(self): self.db = DbController() self.crypt = Crypt() self.audit = Audit() self.audit.set_info(X_API_KEY, 'Arquivei-Consulta') def get(self, note): notes = self.db.select_all_keys() for dbnote in notes: if note == self.crypt.decrypt(dbnote[1]): self.audit.insert_audit_log( 'Nota pesquisada: {} - Encontrada'.format(note)) return self.crypt.decrypt(dbnote[2]), 200 self.audit.insert_audit_log( 'Nota pesquisada: {} - Nao encontrada'.format(note)) return "Nota nao encontrada", 404
def test_audit_singleton(self): obj1 = Audit() obj1.set_info('a', 'b') obj2 = Audit() self.assertEqual(obj2.key, 'a') self.assertEqual(obj2.project, 'b')