Example #1
0
    async def test_make_transaction(self, client: dict, db: Db):
        wallet_id = client['wallet']['id']

        transactions = await get_transactions(wallet_id, db)

        assert transactions == []

        async with db.connection() as connection:
            await Billing(connection).save_transaction(
                wallet_id, Decimal('1'), OperationType.ACCRUAL,
                description={'wallet_from': 2},
            )

        transactions = await get_transactions(wallet_id, db)

        assert transactions == [
            {
                'id': EqMock(int),
                'date': EqMock(datetime),
                'type': OperationType.ACCRUAL,
                'wallet_id': wallet_id,
                'amount': Decimal('1'),
                'description': '{"wallet_from": 2}',  # BUG: https://github.com/CanopyTax/asyncpgsa/issues/44
            },
        ]
Example #2
0
async def get_transactions(wallet_id: int, db: Db):
    async with db.connection() as connection:
        transactions = await connection.fetch(
            sa.select([models.transaction]).where(wallet_id == wallet_id),
        )

    return [dict(t) for t in transactions]
Example #3
0
 async def test_make_transaction_wallet_not_found(self, db: Db):
     async with db.connection() as connection:
         with pytest.raises(errors.NotFound):
             await Billing(connection).save_transaction(1, Decimal('1'), OperationType.ACCRUAL)
Example #4
0
 async def test_create_wallet_with_wrong_currency(self, db: Db):
     async with db.connection() as connection:
         with pytest.raises(ValueError):
             await Billing(connection).create_wallet(1, 'RUB')
Example #5
0
 async def test_create_wallet_client_not_found(self, db: Db):
     async with db.connection() as connection:
         with pytest.raises(errors.NotFound):
             await Billing(connection).create_wallet(client_id=1)
Example #6
0
 async def test_get_client_not_found(self, db: Db):
     async with db.connection() as connection:
         with pytest.raises(errors.NotFound):
             await Billing(connection).get_client(1)
Example #7
0
    async def test_get_client(self, client, db: Db):
        async with db.connection() as connection:
            found_client = await Billing(connection).get_client(client['id'])

        assert found_client == client
        assert found_client is not client
Example #8
0
 async def test_change_balance_not_enough_money(self, client: dict, db: Db):
     async with db.connection() as connection:
         with pytest.raises(errors.NotEnoughMoney):
             await Billing(connection).change_balance(client['wallet']['id'], -Decimal('1'))
Example #9
0
 async def test_change_balance_wallet_not_found(self, db: Db):
     async with db.connection() as connection:
         with pytest.raises(errors.NotFound):
             await Billing(connection).change_balance(1, Decimal('1'))
Example #10
0
async def get_balance(wallet_id, db: Db):
    async with db.connection() as connection:
        return await connection.fetchval(
            sa.select([models.wallet.c.balance
                       ]).where(models.wallet.c.id == wallet_id, ), )