def test_no_room(self, ctx, mock_payment_method_repository: PaymentMethodRepository, mock_account_repository: AccountRepository, mock_transaction_repository: TransactionRepository, member_manager: MemberManager, sample_membership_pending_payment_validation: Membership, sample_account1: Account, sample_payment_method: PaymentMethod): mock_payment_method_repository.get_by_id = MagicMock( return_value=(sample_payment_method) ) # in this test don't care of the return value, the most important thing is that the function does not raise NotFound exception mock_account_repository.search_by = MagicMock( side_effect=[([sample_account1], 0), ([sample_account1], 0)]) mock_account_repository.get_by_id = MagicMock( return_value=(sample_account1)) mock_transaction_repository.create = MagicMock(return_value=(None)) sample_membership_pending_payment_validation.has_room = False member_manager.add_membership_payment_record( ctx, sample_membership_pending_payment_validation, False) mock_payment_method_repository.get_by_id.assert_called_once() mock_account_repository.search_by.assert_called() mock_account_repository.get_by_id.assert_called_once() mock_transaction_repository.create.assert_called_once()
def test_dst_technical_account_not_found( self, ctx, sample_payment_method, mock_payment_method_repository: PaymentMethodRepository, mock_account_repository: AccountRepository, product_manager: ProductManager): mock_payment_method_repository.get_by_id = MagicMock( return_value=(sample_payment_method)) mock_account_repository.search_by = MagicMock(return_value=([], 0)) with pytest.raises(AccountNotFoundError): product_manager.buy(ctx, 0, 0, [1]) mock_payment_method_repository.get_by_id.assert_called_once_with( ctx, 0) mock_account_repository.search_by.assert_called_once()
def test_no_asso_account( self, ctx, mock_payment_method_repository: PaymentMethodRepository, mock_account_repository: AccountRepository, member_manager: MemberManager, sample_membership_empty: Membership): mock_payment_method_repository.get_by_id = MagicMock( return_value=() ) # in this test don't care of the return value, the most important thing is that the function does not raise NotFound exception mock_account_repository.search_by = MagicMock(side_effect=[([], 0)]) with raises(AccountNotFoundError): member_manager.add_membership_payment_record( ctx, sample_membership_empty, False) mock_payment_method_repository.get_by_id.assert_called_once() mock_account_repository.search_by.assert_called_once()
def test_product_not_found( self, ctx, sample_account1: Account, sample_account2: Account, sample_payment_method: PaymentMethod, mock_payment_method_repository: PaymentMethodRepository, mock_account_repository: AccountRepository, mock_product_repository: ProductRepository, product_manager: ProductManager): mock_payment_method_repository.get_by_id = MagicMock( return_value=(sample_payment_method)) mock_account_repository.search_by = MagicMock( side_effect=[([sample_account1], 1), ([sample_account2], 1)]) mock_product_repository.get_by_id = MagicMock( return_value=(None), side_effect=ProductNotFoundError("")) with pytest.raises(ProductNotFoundError): product_manager.buy(ctx, 0, 0, [1]) mock_payment_method_repository.get_by_id.assert_called_once_with( ctx, 0) mock_account_repository.search_by.assert_called() mock_product_repository.get_by_id.assert_called_once_with(ctx, 1)
def test_happy_path( self, ctx, sample_account1: Account, sample_account2: Account, sample_product: Product, sample_payment_method: PaymentMethod, mock_payment_method_repository: PaymentMethodRepository, mock_account_repository: AccountRepository, mock_product_repository: ProductRepository, mock_transaction_repository: TransactionRepository, product_manager: ProductManager): mock_payment_method_repository.get_by_id = MagicMock( return_value=(sample_payment_method)) mock_account_repository.search_by = MagicMock( side_effect=[([sample_account1], 1), ([sample_account2], 1)]) mock_product_repository.get_by_id = MagicMock( return_value=(sample_product)) mock_transaction_repository.create = MagicMock() product_manager.buy(ctx, 0, 0, [1]) mock_payment_method_repository.get_by_id.assert_called_once_with( ctx, 0) mock_account_repository.search_by.assert_called() mock_product_repository.get_by_id.assert_called_once_with(ctx, 1) mock_transaction_repository.create.assert_called_once()