Exemplo n.º 1
0
def test_eqmock():
    some_value = EqMock()

    assert some_value == 1
    assert some_value == 0.5
    assert some_value == 'hello'

    only_int = EqMock(int)

    assert only_int != 'hello'
    assert only_int != 0.5
    assert only_int == 1
    assert only_int == 2

    only_first = EqMock(remember=True)

    assert only_first == 1
    assert only_first != 2
    assert only_first != 'hello'
    assert only_first == 1

    only_first_and_str = EqMock(str, remember=True)

    assert only_first_and_str != 1
    assert only_first_and_str == 'hello'
    assert only_first_and_str != 'world'

    int_or_str = EqMock((int, str))

    assert int_or_str == 1
    assert int_or_str == 'hello'
    assert int_or_str != 0.5
Exemplo n.º 2
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
            },
        ]
Exemplo n.º 3
0
    async def test_create_client(self, db: Db):
        async with db.transaction() as t:
            client = await Billing(t).create_client('Bill')

        assert client == {
            'id': EqMock(int),
            'name': 'Bill',
            'date': EqMock(datetime),
        }
Exemplo n.º 4
0
    async def test_create_client(self, db: Db):
        client = await controllers.create_client(name='Bill', db=db)

        assert client == {
            'id': EqMock(int),
            'date': EqMock(datetime),
            'name': 'Bill',
            'wallet': {
                'id': EqMock(int),
                'balance': Decimal(0),
            },
        }
Exemplo n.º 5
0
    async def test_create_client(self, client: TestClient):
        response: Response = await client.post('/clients',
                                               json={'name': 'Bob'})

        assert response.status_code == 201, response.text
        assert response.json() == {
            'id': EqMock(int),
            'name': 'Bob',
            'wallet': {
                'id': EqMock(int),
                'balance': '0',
            },
        }
Exemplo n.º 6
0
    async def test_create_wallet(self, db: Db):
        async with db.executor(Billing) as executor:
            client = await executor.create_client('Bill')
            wallet = await executor.create_wallet(client['id'])

        assert wallet == {
            'id': EqMock(int),
            'balance': Decimal('0'),
        }
Exemplo n.º 7
0
    async def test_get_client(self, client: TestClient):
        response: Response = await client.post('/clients',
                                               json={'name': 'Tom'})

        assert response.status_code == 201, response.text

        client_id = response.json()['id']

        response: Response = await client.get(f'/clients/{client_id}')

        assert response.status_code == 200, response.text
        assert response.json() == {
            'id': EqMock(int),
            'name': 'Tom',
            'wallet': {
                'id': EqMock(int),
                'balance': '0',
            },
        }
Exemplo n.º 8
0
    async def test_transfer_equal_wallets(self, client: TestClient):
        response: Response = await client.post(
            path='/transfers',
            json={
                'wallet_from': 1,
                'wallet_to': 1,
                'amount': '1'
            },
        )

        assert response.status_code == 422, response.text
        assert response.json() == {
            'error':
            'VALIDATION_ERROR',
            'detail': [
                {
                    'loc': EqMock(),
                    'msg': 'Wallets are equal',
                    'type': EqMock(str),
                },
            ],
        }
Exemplo n.º 9
0
    async def test_transfer_when_penniless(self, client: TestClient):
        response: Response = await client.post('/clients',
                                               json={'name': 'Tom'})
        client1_id = response.json()['id']
        wallet1_id = response.json()['wallet']['id']

        response: Response = await client.post('/clients',
                                               json={'name': 'Helen'})
        client2_id = response.json()['id']
        wallet2_id = response.json()['wallet']['id']

        response: Response = await client.post(
            path='/charges',
            json={
                'wallet_id': wallet1_id,
                'amount': '5'
            },
        )

        assert response.status_code == 204, response.text

        response: Response = await client.post(
            path='/transfers',
            json={
                'wallet_from': wallet1_id,
                'wallet_to': wallet2_id,
                'amount': '10'
            },
        )

        assert response.status_code == 400, response.text
        assert response.json() == {
            'error': 'NOT_ENOUGH_MONEY',
            'message': EqMock(str),
            'detail': None,
        }

        response: Response = await client.get(f'/clients/{client1_id}')

        assert response.json()['wallet']['balance'] == '5'

        response: Response = await client.get(f'/clients/{client2_id}')

        assert response.json()['wallet']['balance'] == '0'