def acidentes_br(request):
    """ Return the render from statistics. """

    try:
        data = datetime.now()
        br_dao = BRAcidentesDAO()
        br_overall_accidents = br_dao.acidentes_br_geral()
        accidents_ano = br_dao.acidentes_br_ano()

    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)
        )

    response = render_to_response(
        "br_acidentes.html", {
            'ano': range(2007, data.year + 1),
            'br_acidentes_geral': br_overall_accidents,
            'acidentes_ano': accidents_ano
        }, context_instance=RequestContext(request)
    )

    return response
class Test_BR_Acidentes(DAO_Tests):

    """
    Docstring for Test_BR_Acidentes
    Class that tests the methods from br_acidentes_dao
    """

    def test_br_acidentes(self):
        """
        Tests to see if the statistics were correctly instanced.
        """

        self.estatistica = BRAcidentesDAO()
        self.assertIsNotNone(self.estatistica)

    def test_acidentes_br_geral(self):
        """
        Tests to see if the query results return not NULL
        """

        self.estatistica = BRAcidentesDAO()
        self.assertIsNotNone(self.estatistica.acidentes_br_geral())

    def test_acidentes_br_ano(self):
        """
        Tests if a year is on the list of years.

        @brief Local variables:
            br_acidentes_ano_list -
                Receives a list of number of accidents per year.
            anos -
                receives a list of years.
            brs -
                receives a list of br's.
        """

        self.estatistica = BRAcidentesDAO()
        br_acidentes_ano_list = self.estatistica.acidentes_br_ano()

        anos = br_acidentes_ano_list[0].ano_list
        self.assertEquals([
            2007,
            2008,
            2009,
            2010,
            2011,
            2012,
            2013
        ], anos)

        brs = [i.br for i in br_acidentes_ano_list]
        self.assertIn('40', brs)
    def test_acidentes_br_ano(self):
        """
        Tests if a year is on the list of years.

        @brief Local variables:
            br_acidentes_ano_list -
                Receives a list of number of accidents per year.
            anos -
                receives a list of years.
            brs -
                receives a list of br's.
        """

        self.estatistica = BRAcidentesDAO()
        br_acidentes_ano_list = self.estatistica.acidentes_br_ano()

        anos = br_acidentes_ano_list[0].ano_list
        self.assertEquals([
            2007,
            2008,
            2009,
            2010,
            2011,
            2012,
            2013
        ], anos)

        brs = [i.br for i in br_acidentes_ano_list]
        self.assertIn('40', brs)
    def test_acidentes_br_geral(self):
        """
        Tests to see if the query results return not NULL
        """

        self.estatistica = BRAcidentesDAO()
        self.assertIsNotNone(self.estatistica.acidentes_br_geral())
    def test_br_acidentes(self):
        """
        Tests to see if the statistics were correctly instanced.
        """

        self.estatistica = BRAcidentesDAO()
        self.assertIsNotNone(self.estatistica)