示例#1
0
    def test_get(self, view, mget_bill, billed_at):
        """
        .get should return serialized bill data
        """
        bill = Bill(uid=uuid4(),
                    place="Lidl",
                    billed_at=billed_at,
                    wallet_uid=uuid4())
        bill.add_item(uuid4(),
                      name="coke",
                      quantity=1.4,
                      value=1.5,
                      group_uid=uuid4())
        mget_bill.return_value = bill

        assert view.get() == {
            "uid":
            str(bill.uid),
            "place":
            "Lidl",
            "billed_at":
            "2018-01-03",
            "wallet_uid":
            str(bill.wallet_uid),
            "items": [{
                "uid": str(bill.items[0].uid),
                "name": "coke",
                "quantity": "1.40",
                "value": "1.50",
                "group_uid": str(bill.items[0].group_uid),
            }],
        }
示例#2
0
 def new_bill(self, bill_uid, first_item_uid, second_item_uid,
              third_item_uid):
     bill = Bill(uid=bill_uid, place="place", billed_at=date(2018, 1, 1))
     bill.add_item(first_item_uid, "red", 1.0, 2.0)
     bill.add_item(second_item_uid, "green", 2.0, 4.0)
     bill.add_item(third_item_uid, "blue", 3.0, 6.0)
     return bill
示例#3
0
 def old_bill(self, bill_uid, first_item_uid, second_item_uid,
              third_item_uid):
     bill = Bill(uid=bill_uid, place="place", billed_at="2018-01-01")
     bill.add_item(first_item_uid, "red", 1.0, 2.0)
     bill.add_item(second_item_uid, "green", 2.0, 4.0)
     bill.add_item(third_item_uid, "blue", 3.0, 6.0)
     return bill
示例#4
0
文件: schemas.py 项目: socek/cashcat
 def make_model(self, data):
     return Bill(
         uid=data.get("uid"),
         place=data.get("place"),
         billed_at=data.get("billed_at"),
         wallet_uid=data.get("wallet_uid"),
         items=[item for item in data.get("items", [])],
         total=data.get("total"),
     )
示例#5
0
文件: dbmodels.py 项目: socek/cashcat
 def to_model(self):
     return Bill(
         uid=self.uid,
         created_at=self.created_at,
         updated_at=self.updated_at,
         place=self.place,
         billed_at=self.billed_at,
         wallet_uid=self.wallet_uid,
     )
示例#6
0
    def test_list_for_wallet(self, wallet, second_wallet, bill_query,
                             bill_command, group):
        """
        .list_for_wallet should return only list of bill for that wallet
        """
        bills = [
            Bill(uuid4(),
                 place="lidl",
                 billed_at=date(2018, 1, 2),
                 wallet_uid=wallet.uid),
            Bill(
                uuid4(),
                place="biedronka",
                billed_at=date(2018, 1, 3),
                wallet_uid=wallet.uid,
            ),
            Bill(
                uuid4(),
                place="tesco",
                billed_at=date(2018, 1, 4),
                wallet_uid=second_wallet.uid,
            ),
        ]
        for bill in bills:
            bill_command.create(bill)

        try:
            result = set([
                bill.place for bill in bill_query.list_for_wallet(wallet.uid)
            ])
            assert result == set(["lidl", "biedronka"])

            result = set([
                bill.place
                for bill in bill_query.list_for_wallet(second_wallet.uid)
            ])
            assert result == set(["tesco"])
        finally:
            for bill in bills:
                bill_command.force_delete(bill.uid)
示例#7
0
    def test_creating_with_items(self, wallet, bill_query, bill_command,
                                 group):
        """
        query and command should operate on bill items.
        """
        uid = uuid4()
        bill = Bill(uid,
                    place="lidl",
                    billed_at=date(2018, 1, 2),
                    wallet_uid=wallet.uid)
        bill.add_item(uuid4(),
                      name="cola",
                      quantity=1,
                      value=10,
                      group_uid=group.uid)
        bill.add_item(uuid4(),
                      name="celery",
                      quantity=1.25,
                      value=10,
                      group_uid=group.uid)
        bill_command.create(bill)

        try:
            bill = bill_query.get_active_by_uid(uid,
                                                wallet_uid=wallet.uid,
                                                with_items=True)

            assert bill.place == "lidl"
            item_names = set([item.name for item in bill.items])
            assert set(["cola", "celery"]) == item_names
        finally:
            bill_command.force_delete(uid)
示例#8
0
    def test_get_active_by_uid_with_wrong_owner(self, wallet, second_wallet,
                                                bill_query, bill_command):
        """
        .get_active_by_uid should return object only for wallet
        """
        uid = uuid4()
        bill = Bill(uid,
                    place="lidl",
                    billed_at=date(2018, 1, 2),
                    wallet_uid=wallet.uid)
        bill_command.create(bill)

        try:
            assert bill_query.get_active_by_uid(uid, wallet.uid)

            bill_command.delete(uid)

            with raises(NoResultFound):
                bill_query.get_active_by_uid(uid, second_wallet.uid)
        finally:
            bill_command.force_delete(uid)
示例#9
0
 def bill(self, wallet, group, bill_command):
     uid = uuid4()
     bill = Bill(uid,
                 place="lidl",
                 billed_at=date(2018, 1, 1),
                 wallet_uid=wallet.uid)
     bill.add_item(uuid4(),
                   name="cola",
                   quantity=1,
                   value=10,
                   group_uid=group.uid)
     bill.add_item(uuid4(),
                   name="celery",
                   quantity=1.25,
                   value=10,
                   group_uid=group.uid)
     bill_command.create(bill)
     yield bill
     bill_command.force_delete(uid)
示例#10
0
    def base(self, group, second_group, wallet, bill_command):
        uuids = []
        bill = Bill(
            uuid4(),
            place="lidl",
            billed_at=date(2018, 1, 2),
            wallet_uid=wallet.uid)
        bill.add_item(
            uuid4(), name="cola", quantity=1, value=10, group_uid=group.uid)
        bill.add_item(
            uuid4(),
            name="celery",
            quantity=1.25,
            value=10,
            group_uid=group.uid)
        bill_command.create(bill)
        uuids.append(bill.uid)

        bill = Bill(
            uuid4(),
            place="biedronka",
            billed_at=date(2018, 1, 3),
            wallet_uid=wallet.uid)
        bill.add_item(
            uuid4(), name="cola", quantity=1, value=10, group_uid=group.uid)
        bill.add_item(
            uuid4(),
            name="celery",
            quantity=1.25,
            value=10,
            group_uid=group.uid)
        bill_command.create(bill)
        uuids.append(bill.uid)

        bill = Bill(
            uuid4(),
            place="kaufland",
            billed_at=date(2018, 1, 4),
            wallet_uid=wallet.uid)
        bill.add_item(
            uuid4(),
            name="cola",
            quantity=1,
            value=10,
            group_uid=second_group.uid)
        bill.add_item(
            uuid4(),
            name="celery",
            quantity=1.25,
            value=10,
            group_uid=second_group.uid)
        bill_command.create(bill)
        uuids.append(bill.uid)

        yield uuids

        for uid in uuids:
            bill_command.force_delete(uid)
示例#11
0
    def test_list_for_wallet_summary(self, wallet, second_wallet, bill_query,
                                     bill_command, group):
        """
        .list_for_wallet should compute total for each bill
        """
        first = Bill(uuid4(),
                     place="lidl",
                     billed_at=date(2018, 1, 2),
                     wallet_uid=wallet.uid)
        first.add_item(uuid4(),
                       name="cola",
                       quantity=1,
                       value=10,
                       group_uid=group.uid)
        first.add_item(uuid4(),
                       name="fanta",
                       quantity=2,
                       value=5,
                       group_uid=group.uid)

        second = Bill(
            uuid4(),
            place="biedronka",
            billed_at=date(2018, 1, 3),
            wallet_uid=wallet.uid,
        )
        second.add_item(uuid4(),
                        name="beer",
                        quantity=6,
                        value=1,
                        group_uid=group.uid)
        second.add_item(uuid4(),
                        name="wine",
                        quantity=1,
                        value=100,
                        group_uid=group.uid)

        bills = [first, second]
        for bill in bills:
            bill_command.create(bill)

        try:
            result = {
                bill.place: bill
                for bill in bill_query.list_for_wallet(wallet.uid)
            }
            assert result["lidl"].total == 20
            assert result["biedronka"].total == 106
        finally:
            for bill in bills:
                bill_command.force_delete(bill.uid)
示例#12
0
    def test_updating_total(self, wallet, second_wallet, bill_query,
                            bill_command, group, dbsession):
        """
        Updating items should update total values as well
        """
        update_item_uid = uuid4()
        remove_item_uid = uuid4()
        first = Bill(uuid4(),
                     place="lidl",
                     billed_at=date(2018, 1, 2),
                     wallet_uid=wallet.uid)
        first.add_item(update_item_uid,
                       name="cola",
                       quantity=1,
                       value=10,
                       group_uid=group.uid)
        first.add_item(uuid4(),
                       name="fanta",
                       quantity=2,
                       value=5,
                       group_uid=group.uid)

        second = Bill(
            uuid4(),
            place="biedronka",
            billed_at=date(2018, 1, 3),
            wallet_uid=wallet.uid,
        )
        second.add_item(uuid4(),
                        name="beer",
                        quantity=6,
                        value=1,
                        group_uid=group.uid)
        second.add_item(remove_item_uid,
                        name="wine",
                        quantity=1,
                        value=100,
                        group_uid=group.uid)

        bills = [first, second]
        for bill in bills:
            bill_command.create(bill)

        bill_command.patch_by_uid(
            first.uid,
            create_items=[
                BillItem(
                    uid=uuid4(),
                    name="green up",
                    quantity=1,
                    value=5,
                    group_uid=group.uid,
                )
            ],
            items_update={update_item_uid: {
                "quantity": 2
            }},
        )

        bill_command.patch_by_uid(second.uid, remove_items=[remove_item_uid])

        dbsession.flush()

        try:
            result = {
                bill.place: bill
                for bill in bill_query.list_for_wallet(wallet.uid)
            }
            assert result["biedronka"].total == 6
            assert result["lidl"].total == 35
        finally:
            for bill in bills:
                bill_command.force_delete(bill.uid)