예제 #1
0
def test_store_generates_a_new_account_number_each_time(account_repository):
    account1 = Account(customer_id='12345', account_status='active')
    account2 = Account(customer_id='12345', account_status='active')
    account_repository.store(account1)
    account_repository.store(account2)

    assert account1.account_number != account2.account_number
예제 #2
0
def test_fetch_by_account_number_returns_the_account(account_repository):
    saved = Account(customer_id='12345', account_status='active')
    other = Account(customer_id='99999', account_status='active')
    account_repository.store(saved)
    account_repository.store(other)

    fetched = account_repository.fetch_by_account_number(saved.account_number)

    assert fetched is saved
def test_close_account_closes_the_account(account_repository, customer_client):
    customer_client.add_customer_with_id('12345')
    account = Account(customer_id='12345', account_status='active')
    account_repository.store(account)

    commands.close_account(account.account_number, account_repository)

    assert account.account_status == 'closed'
def test_get_account_when_account_is_found(account_repository):
    account = Account(customer_id='1234', account_status='active')
    account_repository.store(account)
    account_number = account.account_number

    returned_account = commands.get_account(
        account_number=account_number, account_repository=account_repository)

    assert account == returned_account
def create_account(customer_id, account_repository, customer_client):
    if not customer_client.has_customer_with_id(customer_id):
        raise CustomerNotFound()

    account = Account(customer_id=customer_id, account_status='active')

    account_repository.store(account)

    return account.formatted_account_number
예제 #6
0
def test_create_account_stores_the_account(customer_client):
    account_repository = Mock()
    customer_client.add_customer_with_id('12345')
    account = Account(customer_id='12345', account_status='active')

    commands.create_account(account=account,
                            account_repository=account_repository,
                            customer_client=customer_client)

    account_repository.store.assert_called_with(account)
예제 #7
0
def test_create_account_when_customer_not_found(customer_client):
    account_repository = Mock()
    account = Account(customer_id='12345', account_status='active')

    with pytest.raises(CustomerNotFound):
        commands.create_account(account=account,
                                account_repository=account_repository,
                                customer_client=customer_client)

    assert not account_repository.store.called
    def fetch_by_account_number(self, account_number):
        doc_ref = self.account_repo.document(account_number)
        doc = doc_ref.get()

        account_json = doc.to_dict()
        if account_json is not None:
            return Account(account_number=account_json["account_number"],
                           account_status=account_json["account_status"],
                           customer_id=account_json["customer_id"])
        else:
            raise AccountNotFound()
예제 #9
0
def test_get_accounts_by_number_when_account_exists(get_account,
                                                    web_client,
                                                    account_repository):
    get_account.return_value = Account(account_number=123,
                                       account_status='active',
                                       customer_id='12345')

    response = web_client.get(f'/accounts/00000123')

    get_account.assert_called_with(account_number=123,
                                   account_repository=account_repository)

    assert response.status_code == 200
    assert response.is_json
    assert response.get_json() == {'customerId': '12345',
                                   'accountNumber': '00000123',
                                   'accountStatus': 'active'}
def post_account():
    if not request.is_json:
        raise ContentTypeError()

    body = request.get_json()

    POST_ACCOUNT_PAYLOAD_SCHEMA.validate(body)

    customer_id = body['customerId']

    account = Account(account_status='active', customer_id=customer_id)

    commands.create_account(account=account,
                            account_repository=current_app.account_repository,
                            customer_client=current_app.customer_client)

    return jsonify({
        'customerId': customer_id,
        'accountNumber': account.formatted_account_number,
        'accountStatus': 'active'
    }), HTTPStatus.CREATED
예제 #11
0
def test_store_sets_the_account_number_to_an_integer(account_repository):
    account = Account(customer_id='12345', account_status='active')
    account_repository.store(account)

    assert type(account.account_number) is str
def create_account(context, status, customer_id):
    account = Account(customer_id=customer_id, account_status=status)
    context.account_repository.store(account)
    context.account_number = account.account_number
예제 #13
0
def test_formatted_account_number():
    account = Account(account_number=1,
                      account_status='active',
                      customer_id='12345')

    assert account.formatted_account_number == '00000001'
예제 #14
0
def test_formatted_account_number_when_no_number():
    account = Account(account_status='active',
                      customer_id='12345')

    assert account.formatted_account_number is None