Пример #1
0
 def _open(stub: BankAccountServiceStub):
     account_owner = "random owner"
     cmd = OpenAccountRequest(account_owner=account_owner, balance=200)
     response = stub.OpenAccount(cmd)
     assert isinstance(response, ApiResponse)
     account_id = response.account.account_id
     logger.info(f"created account {account_id}")
     return account_id
Пример #2
0
    def _missing_owner_rich_error(stub: BankAccountServiceStub):
        logger.info("missing account owner, rich error")
        # open account request missing the owner
        cmd = OpenAccountRequest(balance=200)
        did_fail = False
        try:
            stub.OpenAccount(cmd)
        except RpcError as e:
            error_status = rpc_status.from_call(e)
            assert error_status.details, 'missing details'
            bad_request = unpack_any(error_status.details[0],
                                     error_details_pb2.BadRequest)
            assert bad_request.field_violations, 'missing violations'
            violation = bad_request.field_violations[0]
            assert violation.field == "account_owner"
            assert violation.description == "missing account owner"
            did_fail = True

        assert did_fail, "did not fail"
Пример #3
0
    def _consistent_account(stub: BankAccountServiceStub):
        logger.info("test consistent account")
        id = '6ff6f770-7ab4-4161-b7f2-7aff57357065'

        try:
            # lazily create the account, ignore if already exists
            cmd = OpenAccountRequest(account_owner="consistent owner",
                                     balance=200,
                                     account_id=id)
            stub.OpenAccount(cmd)
            logger.info(f"created consistent account {id}")
        except RpcError as e:
            assert e.code(
            ) == StatusCode.ALREADY_EXISTS, f"wrong status code {e.code()}"
            logger.info(f"found consistent account {id}")

        request = DebitAccountRequest(account_id=id, amount=1)
        response = stub.DebitAccount(request)
        assert isinstance(response, ApiResponse)
        assert response.account.account_id == id
        logger.info(
            f"debitted consistent account {id}, balance {response.account.account_balance}"
        )