Exemplo n.º 1
0
    def test_should_remove_billing(self):
        user_uid = str(uuid.uuid4())

        billing_uid = str(uuid.uuid4())

        self._session.add(
            BillingTable(uid=billing_uid,
                         title='',
                         description='',
                         value=Decimal(10),
                         work_date=datetime.now(),
                         user_uid=user_uid))

        self._session.add(
            BillingTable(uid=str(uuid.uuid4()),
                         title='',
                         description='',
                         value=Decimal(10),
                         work_date=datetime.now(),
                         user_uid=user_uid))

        billing = Billing(title='',
                          description='',
                          value=Decimal(10),
                          work_date=datetime.now(),
                          uid=billing_uid)

        self._user_repository.remove_billing(billing)

        result = len(self._session.query(BillingTable).all())

        expected = 1

        self.assertEqual(expected, result)
Exemplo n.º 2
0
    def test_should_list_billing_not_received_return_second_billing_when_offset_is_equal_to_one(
            self):
        user_uid = str(uuid.uuid4())

        self._session.add(
            BillingTable(uid=str(uuid.uuid4()),
                         title='',
                         description='',
                         value=Decimal(10),
                         work_date=datetime.now(),
                         user_uid=user_uid))

        self._session.add(
            BillingTable(uid=str(uuid.uuid4()),
                         title='',
                         description='',
                         value=Decimal(10),
                         work_date=datetime.now(),
                         user_uid=user_uid))

        billing_received = self._user_repository.list_billing_not_received(
            user_uid, offset=1)

        self.assertEqual(1, len(billing_received))

        for it in billing_received:
            with self.subTest():
                self.assertIsInstance(it, BillingListQueryResult)
Exemplo n.º 3
0
    def test_should_list_billing_received_return_default_limit_and_offset_when_not_inform_limit_and_offset(
            self):
        user_uid = str(uuid.uuid4())

        self._session.add(
            BillingTable(uid=str(uuid.uuid4()),
                         title='',
                         description='',
                         value=Decimal(10),
                         work_date=datetime.now(),
                         receive_date=datetime.now(),
                         received=True,
                         user_uid=user_uid))

        self._session.add(
            BillingTable(uid=str(uuid.uuid4()),
                         title='',
                         description='',
                         value=Decimal(10),
                         work_date=datetime.now(),
                         receive_date=datetime.now(),
                         received=True,
                         user_uid=user_uid))

        billing_received = self._user_repository.list_billing_received(
            user_uid)

        self.assertEqual(2, len(billing_received))

        for it in billing_received:
            with self.subTest():
                self.assertIsInstance(it, BillingListQueryResult)
Exemplo n.º 4
0
    def test_should_save_billing_update_billing_when_exists(self):
        yesterday = datetime.now() + timedelta(days=1)

        billing_table = BillingTable(uid=str(uuid.uuid4()),
                                     title='Gas Station',
                                     description='Yesterday',
                                     value=Decimal(10),
                                     work_date=yesterday)

        self._session.add(billing_table)

        billing = Billing(title='Gas Station',
                          description='Yesterday',
                          value=Decimal(10),
                          work_date=yesterday,
                          uid=billing_table.uid)

        naruto = User()

        self._user_repository.save_billing(naruto, billing)

        result = len(self._session.query(BillingTable).all())

        expected = 1

        self.assertEqual(expected, result)
Exemplo n.º 5
0
    def test_should_return_str_repr(self):
        yesterday = datetime.now() - timedelta(days=1)

        billing = BillingTable(uid=str(uuid.uuid4()),
                               title='Gas Station',
                               description='Yesterday',
                               value=Decimal(10),
                               work_date=yesterday)

        result = repr(billing)

        expected = f"<Billing(uid='{billing.uid}', received={billing.received})>"

        self.assertEqual(expected, result)
Exemplo n.º 6
0
    def save_billing(self, user, billing):
        billing_table = self._uow.session.query(BillingTable).filter(
            BillingTable.uid == billing.uid).first()

        billing_table = billing_table or BillingTable()

        billing_table.uid = billing.uid
        billing_table.title = billing.title
        billing_table.description = billing.description
        billing_table.value = billing.value
        billing_table.work_date = billing.work_date
        billing_table.receive_date = billing.receive_date
        billing_table.received = billing.received
        billing_table.user_uid = user.uid

        self._uow.session.add(billing_table)
Exemplo n.º 7
0
    def test_should_get_billing_by_uid_return_billing_when_user_exists(self):
        user_uid = str(uuid.uuid4())

        billing_uid = str(uuid.uuid4())

        billing_table = BillingTable(uid=billing_uid,
                                     title='',
                                     description='',
                                     value=Decimal(10),
                                     work_date=datetime.now(),
                                     user_uid=user_uid)

        self._session.add(billing_table)

        user = User(user_uid)

        billing = self._user_repository.get_billing_by_uid(user, billing_uid)

        self.assertIsInstance(billing, Billing)