Esempio n. 1
0
 def test_schedule_update_existing_record(self, get):
     reimbursement = Reimbursement()
     get.return_value = reimbursement
     content = {'document_id': 42, 'receipt_text': 'lorem ipsum'}
     self.command.queue = []
     self.command.schedule_update(content)
     get.assert_called_once_with(document_id=42)
     self.assertEqual(content['receipt_text'], reimbursement.receipt_text)
Esempio n. 2
0
def serialize(row):
    """
    Read the dict generated by the reimbursement command and returns a
    Reimbursement model instance.
    """
    for key, type_ in TYPES:
        value = row.get(key)
        row[key] = type_.deserialize(value)

    if row['issue_date']:
        return Reimbursement(**row)
Esempio n. 3
0
def serialize(row):
    """
    Read the dict generated by the reimbursement command and returns a
    Reimbursement model instance.
    """
    for key, type_ in TYPES:
        value = row.get(key)
        row[key] = type_.deserialize(value)

    for old, new in RENAME:
        row[new] = row.pop(old)

    return Reimbursement(**row)
Esempio n. 4
0
    def test_count_not_suspicions(
        self,
        mocker,
        reimbursement_data,
    ):
        data = reimbursement_data.copy()
        data['document_id'] = 42 * 2
        del data['suspicions']
        del data['probability']

        mock_queryset = ExtendableMockSet(
            Reimbursement(**reimbursement_data),
            Reimbursement(**data),
            model=Reimbursement,
        )
        mocker.patch(
            'jarbas.chamber_of_deputies.models.Reimbursement'
            '.objects',
            mock_queryset,
        )

        assert Reimbursement.objects.suspicions(False).count() == 1
Esempio n. 5
0
 def test_schedule_update_existing_record(self, get):
     reimbursement = Reimbursement()
     get.return_value = reimbursement
     content = {
         'document_id': 42,
         'probability': 0.618,
         'suspicions': {'answer': 42}
     }
     self.command.queue = []
     self.command.schedule_update(content)
     get.assert_called_once_with(document_id=42)
     self.assertEqual(0.618, reimbursement.probability)
     self.assertEqual({'answer': 42}, reimbursement.suspicions)
     self.assertEqual([reimbursement], self.command.queue)
 def test_reimbursement_property(self, print_):
     self.command.path = os.path.join(
         settings.BASE_DIR,
         'jarbas',
         'core',
         'tests',
         'fixtures',
         'reimbursements.csv'
     )
     result, *_ = tuple(self.command.reimbursements)
     expected = Reimbursement(
         applicant_id=3052,
         batch_number=1524175,
         cnpj_cpf='05634562000100',
         congressperson_document=365,
         congressperson_id=178982,
         congressperson_name='LUIZ LAURO FILHO',
         document_id=6657248,
         document_number='827719',
         document_type=4,
         document_value=195.47,
         installment=0,
         issue_date=date(2018, 8, 15),
         leg_of_the_trip='',
         month=8,
         party='PSB',
         passenger='',
         numbers=['6369'],
         remark_value=0.0,
         state='SP',
         subquota_description='Fuels and lubricants',
         subquota_group_description='Veículos Automotores',
         subquota_group_id=1,
         subquota_number=3,
         supplier='POSTO AVENIDA NOSSA SENHORA DE FÁTIMA CAMPINAS LTDA',
         term=2015,
         term_id=55,
         total_net_value=195.47,
         total_value=0.0,
         year=2018,
     )
     for field_object in Reimbursement._meta.fields:
         field = field_object.name
         with self.subTest():
             self.assertEqual(
                 getattr(expected, field),
                 getattr(result, field),
                 field,
             )
Esempio n. 7
0
    def test_count_suspicions_with_mockset(
        self,
        mocker,
        reimbursement_data,
    ):
        data = reimbursement_data.copy()
        data['document_id'] = 42 * 2
        del data['suspicions']
        del data['probability']

        mock_queryset = MockSet(
            Reimbursement(**reimbursement_data),
            Reimbursement(**data),
            model=Reimbursement,
        )
        mocker.patch(
            'jarbas.chamber_of_deputies.models.Reimbursement'
            '.objects',
            mock_queryset,
        )

        queryset = Reimbursement.objects.filter(suspicions__isnull=True)

        assert queryset.count() == 1
 def test_reimbursement_property(self, print_):
     self.command.path = os.path.join(settings.BASE_DIR, 'jarbas', 'core',
                                      'tests', 'fixtures',
                                      'reimbursements.xz')
     result, *_ = tuple(self.command.reimbursements)
     expected = Reimbursement(
         applicant_id=13,
         batch_number=9,
         cnpj_cpf='11111111111111',
         congressperson_document=2,
         congressperson_id=1,
         congressperson_name='Roger That',
         document_id=42,
         document_number='6',
         document_type=7,
         document_value=8.90,
         installment=7,
         issue_date=date(2014, 2, 12),
         leg_of_the_trip='8',
         month=1,
         net_values='1.99,2.99',
         party='Partido',
         passenger='John Doe',
         reimbursement_numbers='10,11',
         reimbursement_values='12.13,14.15',
         remark_value=1.23,
         state='UF',
         subquota_description='Subquota description',
         subquota_group_description='Subquota group desc',
         subquota_group_id=5,
         subquota_id=4,
         supplier='Acme',
         term=1970,
         term_id=3,
         total_net_value=4.56,
         total_reimbursement_value=None,
         year=1970)
     for field_object in Reimbursement._meta.fields:
         field = field_object.name
         with self.subTest():
             self.assertEqual(getattr(expected, field),
                              getattr(result, field))
Esempio n. 9
0
 def test_as_list(self):
     self.assertIsNone(Reimbursement.as_list(''))
     self.assertEqual(['1', '2'], Reimbursement.as_list('1,2'))
     self.assertEqual([1, 2], Reimbursement.as_list('1,2', int))
Esempio n. 10
0
 def setUp(self):
     self.data = {
         'applicant_id': '13',
         'batch_number': '9',
         'cnpj_cpf': '11111111111111',
         'congressperson_document': '2',
         'congressperson_id': '1',
         'congressperson_name': 'Roger That',
         'document_id': '42',
         'document_number': '6',
         'document_type': '7',
         'document_value': '8.90',
         'installment': '7',
         'issue_date': '2014-02-12T00:00:00',
         'leg_of_the_trip': '8',
         'month': '1',
         'net_values': '1.99,2.99',
         'party': 'Partido',
         'passenger': 'John Doe',
         'reimbursement_numbers': '10,11',
         'reimbursement_values': '12.13,14.15',
         'remark_value': '1.23',
         'state': 'UF',
         'subquota_description': 'Subquota description',
         'subquota_group_description': 'Subquota group desc',
         'subquota_group_id': '5',
         'subquota_number': '4',
         'supplier': 'Acme',
         'term': '1970',
         'term_id': '3',
         'total_net_value': '4.56',
         'reimbursement_value_total': '',
         'year': '1970'
     }
     self.serialized = Reimbursement(
         applicant_id=13,
         batch_number=9,
         cnpj_cpf='11111111111111',
         congressperson_document=2,
         congressperson_id=1,
         congressperson_name='Roger That',
         document_id=42,
         document_number='6',
         document_type=7,
         document_value=8.90,
         installment=7,
         issue_date=date(2014, 2, 12),
         leg_of_the_trip='8',
         month=1,
         net_values='1.99,2.99',
         party='Partido',
         passenger='John Doe',
         reimbursement_numbers='10,11',
         reimbursement_values='12.13,14.15',
         remark_value=1.23,
         state='UF',
         subquota_description='Subquota description',
         subquota_group_description='Subquota group desc',
         subquota_group_id=5,
         subquota_id=4,
         supplier='Acme',
         term=1970,
         term_id=3,
         total_net_value=4.56,
         total_reimbursement_value=None,
         year=1970)
 def test_as_list(self):
     self.assertIsNone(Reimbursement.as_list(''))
     self.assertEqual(['1', '2'], Reimbursement.as_list('1,2'))
     self.assertEqual([1, 2], Reimbursement.as_list('1,2', int))