def test_ocorrencia_por_periodo(self): """ Tests is the number of occurrences were instantiated in a determined period, for a defined and an undefined limit. Also verifies if the return for the occurrences are in the same year. @brief Local variables oco - A list of occurences on a period. """ self.ocorrencia = OcorrenciaBasicaDAO() oco = self.ocorrencia.lista_ocorrencias_por_periodo( '06/01/06', '06/12/06' ) self.assertIsNotNone(oco) oco = self.ocorrencia.lista_ocorrencias_por_periodo( '06/01/06', '06/12/06', limite=3) self.assertIsNotNone(oco) self.assertLess(len(oco), 4) # verifica se as ocorrencias aconteceram em 2006 for i in oco: self.assertEqual(2006, i.ocodataocorrencia.year)
def test_existing_ocorrencia_dao_instance(self): """ Tests to see if the occurrence was correctly instantiated """ self.ocorrencia = OcorrenciaBasicaDAO() self.assertIsNotNone(self.ocorrencia)
def build_list_occurences(start_date, end_date, request): """ Creates a list of occurrences @param start_date Initial date. @param end_data Final date. @return List of occurrences """ try: # DAO object from basic occurrence occurrences_dao = OcorrenciaBasicaDAO() # list of occurrences occurrences_list = occurrences_dao.lista_ocorrencias_por_periodo( start_date, end_date, _MAX_QUERIES) except (MySQLdb.Error, ResultadoConsultaNuloError): raise MySQLdb.Error(ResultadoConsultaNuloError) return occurrences_list
def consulta_ocorrencias_por_municipio(request): """ Return the render from page with query by occurrences in the region. @param request context request from view @return HTML page with query by occurrences in the region. """ try: # Municipalitie Id municipalities_id = int(request.GET["municipio_id"]) except (ValueError, MultiValueDictKeyError): # logger.error(str(e)) erro = "Preencha corretamente o formulário!" return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request)) try: # Occurrences DAO occurrences_dao = OcorrenciaBasicaDAO() # List of occurrences occurrences_list = occurrences_dao.lista_ocorrencias_por_regiao(municipalities_id, _MAX_ITEMS) except (MySQLdb.Error, ResultadoConsultaNuloError): # logger.error(str(e)) erro = "Ocorreu um erro no sistema, tente novamente mais tarde!" return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request)) if len(occurrences_list) == 0: erro = "A consulta não retornou resultados!" return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request)) municipalities = occurrences_list[0].tmudenominacao uf = occurrences_list[0].tmuuf return render_to_response( "resultado.html", {"ocorrencia_list": occurrences_list, "tipo_consulta": "regiao", "municipio": municipalities, "uf": uf}, context_instance=RequestContext(request), )
def test_ocorrencia_por_regiao(self): """ Tests is the number of occurrences were instantiated, for a defined and an undefined limit. Also verifies if the return for the occurrences are in the same state. @brief Local variables oco - A list of occurences on a region. """ self.ocorrencia = OcorrenciaBasicaDAO() _brasilia = 97012 oco = self.ocorrencia.lista_ocorrencias_por_regiao(_brasilia) self.assertIsNotNone(oco) oco = self.ocorrencia.lista_ocorrencias_por_regiao(_brasilia, limite=3) self.assertIsNotNone(oco) self.assertLess(len(oco), 4) # verifica se todos os retornos estão no DF for i in oco: self.assertIsNotNone(str(i)) self.assertEqual(i.tmuuf, 'DF')
class TestOcorrencia(DAO_Tests): """docstring for TestOcorrencia Class that tests the methods from ocorrencia_basica_dao """ def test_existing_ocorrencia_dao_instance(self): """ Tests to see if the occurrence was correctly instantiated """ self.ocorrencia = OcorrenciaBasicaDAO() self.assertIsNotNone(self.ocorrencia) def test_ocorrencia_por_regiao(self): """ Tests is the number of occurrences were instantiated, for a defined and an undefined limit. Also verifies if the return for the occurrences are in the same state. @brief Local variables oco - A list of occurences on a region. """ self.ocorrencia = OcorrenciaBasicaDAO() _brasilia = 97012 oco = self.ocorrencia.lista_ocorrencias_por_regiao(_brasilia) self.assertIsNotNone(oco) oco = self.ocorrencia.lista_ocorrencias_por_regiao(_brasilia, limite=3) self.assertIsNotNone(oco) self.assertLess(len(oco), 4) # verifica se todos os retornos estão no DF for i in oco: self.assertIsNotNone(str(i)) self.assertEqual(i.tmuuf, 'DF') def test_ocorrencia_por_periodo(self): """ Tests is the number of occurrences were instantiated in a determined period, for a defined and an undefined limit. Also verifies if the return for the occurrences are in the same year. @brief Local variables oco - A list of occurences on a period. """ self.ocorrencia = OcorrenciaBasicaDAO() oco = self.ocorrencia.lista_ocorrencias_por_periodo( '06/01/06', '06/12/06' ) self.assertIsNotNone(oco) oco = self.ocorrencia.lista_ocorrencias_por_periodo( '06/01/06', '06/12/06', limite=3) self.assertIsNotNone(oco) self.assertLess(len(oco), 4) # verifica se as ocorrencias aconteceram em 2006 for i in oco: self.assertEqual(2006, i.ocodataocorrencia.year)