Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
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()
Beispiel #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()
Beispiel #5
0
    def test_payment_method_not_found(
            self, ctx, mock_payment_method_repository: PaymentMethodRepository,
            product_manager: ProductManager):
        mock_payment_method_repository.get_by_id = MagicMock(
            return_value=(None), side_effect=PaymentMethodNotFoundError("0"))

        with pytest.raises(PaymentMethodNotFoundError):
            product_manager.buy(ctx, 0, 0, [1])

        mock_payment_method_repository.get_by_id.assert_called_once_with(
            ctx, 0)
Beispiel #6
0
    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()
Beispiel #7
0
    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()
Beispiel #8
0
    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)
Beispiel #9
0
    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()