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_free_not_super_admin( self, ctx_only_admin, member_manager: MemberManager, sample_membership_pending_payment_validation: Membership): with pytest.raises(UnauthorizedError): member_manager.add_membership_payment_record( ctx_only_admin, sample_membership_pending_payment_validation, True)
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()