def test_get_hbase_flags(self, _get_table):
        table_mock = mock.MagicMock()
        table_mock.scan.return_value = [(b"1", {
            b"identificacao:representante_dk": b"1234",
            b"flags:is_pinned": b"True",
            b"flags:is_removed": b"False"
        }),
                                        (b"2", {
                                            b"identificacao:representante_dk":
                                            b"123",
                                            b"flags:is_pinned": b"True"
                                        })]
        _get_table.return_value = table_mock

        expected_output = {
            1234: {
                "is_pinned": True,
                "is_removed": False
            },
            123: {
                "is_pinned": True,
                "is_removed": False
            },
        }

        data = PIPPrincipaisInvestigadosDAO.get_hbase_flags("1", "2")

        hbspace = settings.PROMOTRON_HBASE_NAMESPACE
        _get_table.assert_called_once_with(hbspace + "pip_investigados_flags")
        table_mock.scan.assert_called_once_with(row_prefix=b"12")
        assert data == expected_output
    def test_save_hbase_flags_unremove(self, _get_table):
        table_mock = mock.MagicMock()
        table_mock.delete.return_value = None
        _get_table.return_value = table_mock

        expected_output = {"status": "Success!"}

        data = PIPPrincipaisInvestigadosDAO.save_hbase_flags(
            "1", "2", "1234", "unremove")

        hbspace = settings.PROMOTRON_HBASE_NAMESPACE
        _get_table.assert_called_once_with(hbspace + "pip_investigados_flags")
        table_mock.delete.assert_called_once_with(b"121234",
                                                  columns=["flags:is_removed"])
        assert expected_output == data
Example #3
0
    def get(self, request, *args, **kwargs):
        orgao_id = kwargs.get(self.orgao_url_kwarg)
        cpf = kwargs.get("cpf")
        search_string = request.GET.get("search_string", "")
        page = int(request.GET.get("page", 1))

        data = PIPPrincipaisInvestigadosDAO.get(orgao_id=orgao_id, cpf=cpf)

        data = self.search(search_string, data)

        page_data = self.paginate(data, page=page, page_size=self.PAGE_SIZE)
        response = {
            'investigados': page_data,
            'nr_paginas': self.get_n_pages(data)
        }

        return Response(response)
Example #4
0
    def post(self, request, *args, **kwargs):
        orgao_id = kwargs.get(self.orgao_url_kwarg)
        cpf = kwargs.get("cpf")

        # TODO: Verificar que o post foi feito pelo mesmo orgao
        action = request.POST.get("action")
        representante_dk = request.POST.get("representante_dk")

        # Nome de personagem é necessário para a chave do HBase
        if not representante_dk:
            raise ValueError("Campo 'representante_dk' não foi dado!")
        if not action:
            raise ValueError("Campo 'action' não foi dado!")

        data = PIPPrincipaisInvestigadosDAO.save_hbase_flags(
            orgao_id, cpf, representante_dk, action)

        return Response(data)
    def test_save_hbase_flags_remove(self, _get_table):
        table_mock = mock.MagicMock()
        table_mock.put.return_value = None
        _get_table.return_value = table_mock

        expected_output = {"status": "Success!"}

        expected_call_arguments = {
            b"identificacao:orgao_id": b"1",
            b"identificacao:cpf": b"2",
            b"identificacao:representante_dk": b"1234",
            b"flags:is_removed": b"True"
        }

        data = PIPPrincipaisInvestigadosDAO.save_hbase_flags(
            "1", "2", "1234", "remove")

        hbspace = settings.PROMOTRON_HBASE_NAMESPACE
        _get_table.assert_called_once_with(hbspace + "pip_investigados_flags")
        table_mock.put.assert_called_once_with(b"121234",
                                               expected_call_arguments)
        assert expected_output == data
    def test_get(self, _get, _get_hbase):
        _get_hbase.return_value = {
            "1278": {
                "is_pinned": True,
                "is_removed": False
            },
            "5678": {
                "is_pinned": False,
                "is_removed": True
            },
        }
        _get.return_value = [
            {
                "nm_investigado": "Nome1",
                "representante_dk": "1234",
                "pip_codigo": 1,
                "nr_investigacoes": 10,
                "flag_multipromotoria": None,
                "flag_top50": True,
            },
            {
                "nm_investigado": "Nome2",
                "representante_dk": "1278",
                "pip_codigo": 1,
                "nr_investigacoes": 5,
                "flag_multipromotoria": True,
                "flag_top50": None,
            },
            {
                "nm_investigado": "Nome3",
                "representante_dk": "5678",
                "pip_codigo": 1,
                "nr_investigacoes": 15,
                "flag_multipromotoria": None,
                "flag_top50": None,
            },
        ]

        expected_output = [
            {
                "nm_investigado": "Nome2",
                "representante_dk": "1278",
                "pip_codigo": 1,
                "nr_investigacoes": 5,
                "flag_multipromotoria": True,
                "flag_top50": None,
                "is_pinned": True,
                "is_removed": False
            },
            {
                "nm_investigado": "Nome1",
                "representante_dk": "1234",
                "pip_codigo": 1,
                "nr_investigacoes": 10,
                "flag_multipromotoria": None,
                "flag_top50": True,
                "is_pinned": False,
                "is_removed": False
            },
        ]

        data = PIPPrincipaisInvestigadosDAO.get("1", "2")
        assert data == expected_output