Exemplo n.º 1
0
    def test__get_meeiro_by_cpf__expect_none(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432',
                                'planting_manager_teste')
        create_meeiro(name='tadeu', cpf='55584447213', rg='50658045x')

        m = Meeiro.get_meeiro(connection.session(), cpf='whatever')
        connection.session().close_all()

        self.assertIsNone(m)
Exemplo n.º 2
0
    def test__get_meeiro_by_cpf__expect_correct_instance(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432',
                                'planting_manager_teste')
        create_meeiro(name='tadeu', cpf='55584447213', rg='50658045x')
        m = Meeiro.get_meeiro(connection.session(), cpf='55584447213')
        connection.session().close_all()

        self.assertEqual(m.name, 'tadeu')
        self.assertEqual(m.rg, '50658045x')
Exemplo n.º 3
0
    def test__insert_meeiro_already_saved__expect_error(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432',
                                'planting_manager_teste')
        create_meeiro(name='tadeu', cpf='55584447213', rg='50658045x')
        connection.session().close_all()

        with self.assertRaises(DuplicatedValue):
            Meeiro.insert(connection.session(),
                          name='tadeu',
                          cpf='55584447213',
                          rg='50658045x')
Exemplo n.º 4
0
    def test__update_meeiro_cpf_already_saved_for_another__expected_ok(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432',
                                'planting_manager_teste')
        meeiro_id = create_meeiro(name='tadeu',
                                  cpf='55584447213',
                                  rg='50658045x')
        create_meeiro(name='another', cpf='1111111111', rg='2222222222')
        connection.session().expunge_all()
        connection.session().close_all()

        with self.assertRaises(DuplicatedValue):
            Meeiro.update(connection.session(),
                          new_cpf='1111111111',
                          new_rg='new_rg',
                          new_name='new_name',
                          id_=meeiro_id)
Exemplo n.º 5
0
    def test_get_entries__filter_by_range_date__expected_correct_result(self):
        america_timezone = pytz.timezone('America/Sao_Paulo')

        connection = Connection('postgres', 'root', '127.0.0.1:5432', 'planting_manager_teste')
        session = connection.session()
        meeiro_id = create_meeiro(name='tadeu', cpf='55584447213', rg='50658045x')
        entry_type_id = create_entry_type('despesas', connection)
        session.expunge_all()
        session.close()

        execute_session = connection.session()
        Entry.insert(meeiro_id=meeiro_id, entry_date=america_timezone.localize(datetime(2018, 10, 2, 1, 1)),
                     entry_type_id=entry_type_id, entry_value=100.0,
                     description='veneno', db_session=execute_session)

        Entry.insert(meeiro_id=meeiro_id, entry_date=america_timezone.localize(datetime(2018, 10, 1, 23, 58)),
                     entry_type_id=entry_type_id, entry_value=1520.0,
                     description='combustivel', db_session=execute_session)

        filters_ = Entry.get_filters_to_query_entry(db_session=execute_session,
                                                    date_filter=
                                                    DateRange(min_date=america_timezone.localize(datetime(2018, 10, 1, 23, 59)),
                                                              max_date=america_timezone.localize(datetime(2018, 10, 2, 1, 10)),
                                                              use_equal=True),
                                                    )
        entries = Entry.list(execute_session, filters_)
        self.assertEqual(len(entries), 1)
        expected_entry = entries[0]

        self.assertEqual(expected_entry._entry_type_id, entry_type_id)
        self.assertEqual(str(expected_entry._entry_date), str(america_timezone.localize(datetime(2018, 10, 2, 1, 1))))
        self.assertEqual(expected_entry._meeiro_id, meeiro_id)
        self.assertEqual(expected_entry._description, 'veneno')
        self.assertEqual(expected_entry._entry_value, 100.0)
Exemplo n.º 6
0
    def test_insert_entry__invalid_entry_type__expect_raise_error(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432', 'planting_manager_teste')
        session = connection.session()
        meeiro_id = create_meeiro(name='tadeu', cpf='55584447213', rg='50658045x')
        session.expunge_all()
        session.close()

        with self.assertRaises(RowNotFound):
            Entry.insert(meeiro_id=meeiro_id, entry_date=datetime(2018, 10, 1),
                         entry_type_id=23, entry_value=100.0,
                         description='veneno', db_session=connection.session())
Exemplo n.º 7
0
    def test_insert_entry__expect_correct_insert(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432', 'planting_manager_teste')
        session = connection.session()
        meeiro_id = create_meeiro(name='tadeu', cpf='55584447213', rg='50658045x')
        entry_type_id = create_entry_type('despesas', connection)
        session.expunge_all()
        session.close()

        Entry.insert(meeiro_id=meeiro_id, entry_date=datetime(2018, 10, 1),
                     entry_type_id=entry_type_id, entry_value=100.0,
                     description='veneno', db_session=connection.session())

        america_timezone = pytz.timezone('America/Sao_Paulo')
        entry = session.query(EntryMapping).one()
        self.assertEqual(entry.entry_type, entry_type_id)
        self.assertEqual(str(entry.entry_date), str(america_timezone.localize(datetime(2018, 10, 1))))
        self.assertEqual(entry.meeiro_id, meeiro_id)
        self.assertEqual(entry.description, 'veneno')
        self.assertEqual(entry.entry_value, 100.0)
Exemplo n.º 8
0
    def test__update_meeiro__expected_ok(self):
        connection = Connection('postgres', 'root', '127.0.0.1:5432',
                                'planting_manager_teste')
        meeiro_id = create_meeiro(name='tadeu',
                                  cpf='55584447213',
                                  rg='50658045x')
        connection.session().expunge_all()
        connection.session().close_all()

        result_set = Meeiro.update(connection.session(), 'new_cpf', 'new_rg',
                                   'new_name', meeiro_id)
        self.assertTrue(result_set)
        connection.session().expunge_all()
        connection.session().close_all()

        altered_obj = connection.session().query(MeeiroMapping).filter(
            MeeiroMapping.id == meeiro_id).one()
        self.assertEqual(altered_obj.name, 'new_name')
        self.assertEqual(altered_obj.rg, 'new_rg')
        self.assertEqual(altered_obj.cpf, 'new_cpf')