def test_prepare_camadas_data(self, mock_orcado, mock_empenhado):
        mock_orcado.return_value = 'mock_o'
        mock_empenhado.return_value = 'mock_e'

        execs_2017 = mommy.make(
            Execucao,
            year=date(2017, 1, 1),
            _quantity=2)
        execs_2018 = mommy.make(
            Execucao,
            year=date(2018, 1, 1),
            _quantity=2)
        execucoes = Execucao.objects.all()

        serializer = GeologiaSerializer(execucoes)
        ret = serializer.prepare_data()

        expected = {
            'orcado': ['mock_o', 'mock_o'],
            'empenhado': ['mock_e', 'mock_e'],
        }

        assert expected == ret

        execs = [execs_2017, execs_2018]
        for exec_year, call in zip(execs, mock_orcado.mock_calls):
            assert set(exec_year) == set(call[1][0])
        for exec_year, call in zip(execs, mock_empenhado.mock_calls):
            assert set(exec_year) == set(call[1][0])
Esempio n. 2
0
    def test_prepare_subfuncao_data(self, mock_orcado, mock_empenhado):
        mock_orcado.return_value = 'mock_o'
        mock_empenhado.return_value = 'mock_e'

        subfuncao_id = 1

        execs_2017_p1 = mommy.make(Execucao,
                                   year=date(2017, 1, 1),
                                   subfuncao__id=subfuncao_id,
                                   _quantity=2)
        mommy.make(Execucao,
                   year=date(2017, 1, 1),
                   subfuncao__id=2,
                   _quantity=2)
        execs_2018_p1 = mommy.make(Execucao,
                                   year=date(2018, 1, 1),
                                   subfuncao__id=subfuncao_id,
                                   _quantity=2)
        mommy.make(Execucao,
                   year=date(2018, 1, 1),
                   subfuncao__id=2,
                   _quantity=2)

        execucoes = Execucao.objects.all()

        serializer = GeologiaSerializer(execucoes, subfuncao_id=subfuncao_id)
        ret = serializer.prepare_data(subfuncao_id=subfuncao_id)

        expected = {
            'subfuncao_id': subfuncao_id,
            'orcado': ['mock_o', 'mock_o'],
            'empenhado': ['mock_e', 'mock_e'],
        }

        assert expected == ret

        execs = [execs_2017_p1, execs_2018_p1]
        for exec_year, call in zip(execs, mock_orcado.mock_calls):
            assert set(exec_year) == set(call[1][0])
        for exec_year, call in zip(execs, mock_empenhado.mock_calls):
            assert set(exec_year) == set(call[1][0])