Exemple #1
0
    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()
Exemple #2
0
    def test_unknown_payment_method(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository,
            mock_charter_repository: CharterRepository,
            mock_account_repository: AccountRepository,
            mock_payment_method_repository: PaymentMethodRepository,
            sample_member: Member,
            sample_subscription_duration_account_payment_method:
        SubscriptionBody, sample_membership_pending_rules: Membership,
            sample_account1: Account, member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(
            return_value=([sample_membership_pending_rules], 1))
        mock_account_repository.get_by_id = MagicMock(
            return_value=(sample_account1))
        mock_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))
        mock_payment_method_repository.get_by_id = MagicMock(
            return_value=(None), side_effect=PaymentMethodNotFoundError(""))

        with raises(PaymentMethodNotFoundError):
            member_manager.update_subscription(
                ctx, sample_member.id,
                sample_subscription_duration_account_payment_method)

        mock_membership_repository.search.assert_called_once()
        mock_member_repository.get_by_id.assert_called_once()
        mock_account_repository.get_by_id.assert_called_once()
        mock_charter_repository.get.assert_called_once()
        mock_payment_method_repository.get_by_id.assert_called_once()
        mock_membership_repository.update.assert_not_called()
Exemple #3
0
    def test_from_pending_payment_to_pending_payment_validation(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository,
            mock_account_repository: AccountRepository,
            mock_payment_method_repository: PaymentMethodRepository,
            sample_member: Member,
            sample_membership_pending_payment: Membership,
            sample_subscription_duration_account_payment_method:
        SubscriptionBody, sample_account1: Account,
            sample_payment_method: PaymentMethod,
            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(
            return_value=([sample_membership_pending_payment], 1))
        mock_account_repository.get_by_id = MagicMock(
            return_value=(sample_account1))
        mock_payment_method_repository.get_by_id = MagicMock(
            return_value=(sample_payment_method))
        # When...
        member_manager.update_subscription(
            ctx, sample_member.id,
            sample_subscription_duration_account_payment_method)

        # Expect to create a new membership record...
        mock_membership_repository.update.assert_called_once()
        mock_membership_repository.search.assert_called_once()
        mock_member_repository.get_by_id.assert_called_once()
        mock_account_repository.get_by_id.assert_called_once()
Exemple #4
0
    def test_payment_validation(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository,
            mock_account_repository: AccountRepository,
            mock_payment_method_repository: PaymentMethodRepository,
            sample_member: Member, mock_charter_repository: CharterRepository,
            sample_subscription_duration_account_payment_method:
        SubscriptionBody, sample_account1: Account,
            sample_payment_method: PaymentMethod,
            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))
        mock_account_repository.get_by_id = MagicMock(
            return_value=(sample_account1))
        mock_payment_method_repository.get_by_id = MagicMock(
            return_value=(sample_payment_method))
        mock_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))
        # When...
        member_manager.create_subscription(
            ctx, sample_member.id,
            sample_subscription_duration_account_payment_method)

        # Expect to create a new membership record...
        mock_membership_repository.create.assert_called_once()
Exemple #5
0
    def test_unknown_account(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository,
            mock_account_repository: AccountRepository, sample_member: Member,
            mock_charter_repository: CharterRepository,
            sample_subscription_duration_account_payment_method:
        SubscriptionBody, member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))
        mock_account_repository.get_by_id = MagicMock(
            return_value=(None), side_effect=AccountNotFoundError(""))
        mock_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))

        with raises(AccountNotFoundError):
            member_manager.create_subscription(
                ctx, sample_member.id,
                sample_subscription_duration_account_payment_method)
Exemple #6
0
    def test_no_src_account(
            self, ctx, mock_payment_method_repository: PaymentMethodRepository,
            mock_account_repository: AccountRepository,
            member_manager: MemberManager, sample_membership_empty: 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(
            side_effect=AccountNotFoundError(""))

        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()
        mock_account_repository.get_by_id.assert_called_once()