def consulta_municipios_na_regiao(request):
    """ Return the render from page with query by municipalities in region.
    @param request context request from view
    @return HTML page with query by municipalities in region.
    """

    try:
        # Id from UF requested
        uf_id = request.GET["uf_id"]
    except MultiValueDictKeyError:
        # logger.error(str(e))
        erro = "Preencha corretamente o formulário!"
        return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request))

    try:
        valida_caracteres(uf_id)
    except ParametroInseguroClienteError:
        # logger.error(str(e))
        erro = "Preencha corretamente o formulário!"
        return render_to_response("index.html", {"erro": erro}, context_instance=RequestContext(request))

    try:
        # object DAO from municipalities
        municipalities_dao = MunicipioDAO()
        # list of municipalities
        municipalities_list = municipalities_dao.lista_municipios(uf_id)
    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))

    return render_to_response(
        "municipio.html", {"municipio_list": municipalities_list}, context_instance=RequestContext(request)
    )
class TestMunicipio(DAO_Tests):

    """docstring for TestMunicipio
    Class that tests the methods municipio_dao
    """

    def test_existing_municipio_dao_instance(self):
        """
        Tests if the returned county is not NULL
        """

        self.municipio = MunicipioDAO()
        self.assertIsNotNone(self.municipio)

    def test_list_municipio(self):
        """
        Tests if the list of counties does not return null, in general and in
        a determined limit.
        """

        self.municipio = MunicipioDAO()
        for i in self.municipio.lista_municipios("DF"):
            self.assertIsNotNone(i)
        for i in self.municipio.lista_municipios("DF", limite=3):
            self.assertIsNotNone(str(i))
            self.assertIsNotNone(i)
    def test_existing_municipio_dao_instance(self):
        """
        Tests if the returned county is not NULL
        """

        self.municipio = MunicipioDAO()
        self.assertIsNotNone(self.municipio)
    def test_list_municipio(self):
        """
        Tests if the list of counties does not return null, in general and in
        a determined limit.
        """

        self.municipio = MunicipioDAO()
        for i in self.municipio.lista_municipios("DF"):
            self.assertIsNotNone(i)
        for i in self.municipio.lista_municipios("DF", limite=3):
            self.assertIsNotNone(str(i))
            self.assertIsNotNone(i)