diff --git a/wscacicneo/__init__.py b/wscacicneo/__init__.py index d7b3a43..939edeb 100755 --- a/wscacicneo/__init__.py +++ b/wscacicneo/__init__.py @@ -28,6 +28,7 @@ def main(global_config, **settings): cfg.add_route('root', '/') cfg.add_route('home', 'home') + cfg.add_route('error', 'error') cfg.add_route('graficop', 'graficop') cfg.add_route('notifications', 'notifications') cfg.add_route('admin', 'admin') diff --git a/wscacicneo/model/reports.py b/wscacicneo/model/reports.py index 3a92257..c9389f2 100644 --- a/wscacicneo/model/reports.py +++ b/wscacicneo/model/reports.py @@ -25,18 +25,62 @@ class Reports(): self.rest_url = config.REST_URL else: self.rest_url = rest_url - self.base = coleta_manual.ColetaManualBase(nm_base, self.rest_url).lbbase + self.coleta_manual_base = coleta_manual.ColetaManualBase(nm_base, self.rest_url) + self.base = self.coleta_manual_base.lbbase print(type(self.base)) self.documentrest = DocumentREST(self.rest_url, self.base, response_object=True) def get_base_orgao(self): """ - retorna todos os documentos da base + Retorna todos os documentos da base """ + # A resposta nao pode ser object aqui + self.documentrest.response_object = False search = Search( limit=None ) get = self.documentrest.get_collection(search_obj=search) return get + + def get_attribute(self, attr): + """ + Testa recuperar atributo do Documento + """ + # A resposta nao pode ser object aqui + self.documentrest.response_object = False + + # FIXME: Adicionar lista de atributos obrigatórios nos campos que vao retornar na busca + # Referência: http://dev.lightbase.cc/projects/liblightbase/repository/revisions/master/entry/liblightbase/lbbase/content.py#L34 + + # A busca deve obrigatoriamente retornar todos os atributos obrigatórios + search = Search( + limit=None, + select=[attr, "data_coleta"] + ) + get = self.documentrest.get_collection(search_obj=search) + + return get + + def count_attribute(self, attr, child=None): + """ + retorna dicionário de atributos agrupados por contador + """ + attr_dict = self.get_attribute(attr) + results = attr_dict.results + + saida = dict() + for elm in results: + if child: + parent = getattr(elm, attr) + attribute = getattr(parent, child) + else: + attribute = getattr(elm, attr) + + if saida.get(attribute): + saida[attribute] = saida.get(attribute) + 1 + else: + saida[attribute] = 1 + + return saida diff --git a/wscacicneo/templates/error.pt b/wscacicneo/templates/error.pt new file mode 100644 index 0000000..3e6c853 --- /dev/null +++ b/wscacicneo/templates/error.pt @@ -0,0 +1,45 @@ + + +
+ +
+
+ +
+ +
+ Error +
+ +
+
+ +

Opps!!! It's 404

+

Aliquam consequat, purus vitae auctor ullamcorper, sem velit convallis quam, a pharetra justo nunc et mauris.

+
+ +
+ + + + +
+ +
+ +
+
+ +
+
+
+
+
+
+
+ + + +
diff --git a/wscacicneo/test/test_reports.py b/wscacicneo/test/test_reports.py index 7e054ad..004c10c 100644 --- a/wscacicneo/test/test_reports.py +++ b/wscacicneo/test/test_reports.py @@ -3,11 +3,12 @@ __author__ = 'eduardo' import unittest +import json from wscacicneo.model import reports from liblightbase.lbbase.struct import Base from liblightbase.lbutils import conv -class TestOrgaoBase(unittest.TestCase): +class TestRelatorio(unittest.TestCase): """ Testa base do órgão no LB """ @@ -22,8 +23,34 @@ class TestOrgaoBase(unittest.TestCase): """ Testa busca o documento completo da base """ - get_doc = reports.Reports(self.rest_url, self.nm_base) - lbbase = get_doc.get_base_orgao + get_doc = reports.Reports(self.nm_base, self.rest_url) + lbbase = get_doc.get_base_orgao() + self.assertGreater(len(lbbase.results), 0) + + def test_get_attribute(self): + """ + Teste recuperar um atributo específico da base + """ + get_doc = reports.Reports(self.nm_base, self.rest_url) + coleta = get_doc.get_base_orgao() + hd = get_doc.get_attribute('hd') + self.assertGreater(len(hd.results), 0) + + def test_count_attribute(self): + """ + Método que retora um dicionário de atributos agrupados com o valor + de ocorrência de cada um deles + """ + get_doc = reports.Reports(self.nm_base, self.rest_url) + coleta = get_doc.get_base_orgao() + hd = get_doc.get_attribute('hd') + self.assertGreater(len(hd.results), 0) + + hd_count = get_doc.count_attribute('hd', 'tipo_hd') + fd = open('/tmp/teste.json', 'w+') + fd.write(json.dumps(hd_count)) + fd.close() + self.assertGreater(len(hd_count.keys()), 0) def tearDown(self): """ diff --git a/wscacicneo/utils/utils.py b/wscacicneo/utils/utils.py index 2631541..73e1ecb 100755 --- a/wscacicneo/utils/utils.py +++ b/wscacicneo/utils/utils.py @@ -17,3 +17,4 @@ class Utils: return True else: return False + -- libgit2 0.21.2