示例#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()
示例#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()
示例#3
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()
示例#4
0
    def test_unknown_membership(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository, sample_member: Member,
            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))

        with raises(MembershipNotFoundError):
            member_manager.validate_subscription(ctx, sample_member.id, False)

        mock_member_repository.get_by_id.assert_called_once()
        mock_membership_repository.search.assert_called_once()
示例#5
0
    def test_unknown_membership(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository, sample_member: Member,
            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(
            return_value=([], 0), side_effect=MembershipNotFoundError(""))

        with raises(MembershipNotFoundError):
            member_manager.update_subscription(ctx, sample_member.id,
                                               SubscriptionBody())
            mock_membership_repository.update.assert_not_called()
示例#6
0
    def test_happy_path(self, ctx, mock_member_repository: MemberRepository,
                        mock_membership_repository: MembershipRepository,
                        sample_member: Member, member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))

        # When...
        result = member_manager.get_by_id(ctx, id=sample_member.id)

        # Expect...
        assert sample_member == result
        mock_member_repository.get_by_id.assert_called_once_with(
            ctx, sample_member.id)
示例#7
0
    def test_not_payment_validation(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository, sample_member: Member,
            sample_membership_pending_payment: Membership,
            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))

        with raises(MembershipStatusNotAllowed):
            member_manager.validate_subscription(ctx, sample_member.id, False)

        mock_membership_repository.search.assert_called_once()
        mock_member_repository.get_by_id.assert_called_once()
示例#8
0
    def test_pending_payment_initial(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository, sample_member: Member,
            mock_charter_repository: CharterRepository,
            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))
        mock_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))
        # When...
        member_manager.create_subscription(ctx, sample_member.id,
                                           SubscriptionBody())

        # Expect to create a new membership record...
        mock_membership_repository.create.assert_called_once()
示例#9
0
    def test_unknown_price_asign_to_duration(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository, sample_member: Member,
            mock_charter_repository: CharterRepository,
            sample_subscription_empty: SubscriptionBody,
            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))
        mock_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))
        sample_subscription_empty.duration = 5

        with raises(NoPriceAssignedToThatDuration):
            member_manager.create_subscription(ctx, sample_member.id,
                                               sample_subscription_empty)
示例#10
0
    def test_fetch_failed(self, ctx,
                          mock_membership_repository: MembershipRepository,
                          mock_logs_repository: MagicMock,
                          mock_member_repository: MagicMock,
                          sample_member: Member,
                          member_manager: MemberManager):
        # Given...
        mock_member_repository.search_by = MagicMock(
            return_value=([sample_member], 1))
        mock_membership_repository.search = MagicMock(return_value=([], 0))
        mock_logs_repository.get_logs = MagicMock(side_effect=LogFetchError)

        # When...
        result = member_manager.get_logs(ctx, sample_member.username)

        # Expect use case to 'fail open', do not throw any error, assume there is no log.
        assert [] == result
示例#11
0
    def test_pending_rules(self, ctx,
                           mock_membership_repository: MembershipRepository,
                           mock_member_repository: MemberRepository,
                           sample_member: Member,
                           mock_charter_repository: CharterRepository,
                           sample_subscription_empty: SubscriptionBody,
                           member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))
        mock_membership_repository.search = MagicMock(return_value=([], 0))
        mock_charter_repository.get = MagicMock(return_value="")
        # When...
        member_manager.create_subscription(ctx, sample_member.id,
                                           sample_subscription_empty)

        # Expect to create a new membership record...
        mock_membership_repository.create.assert_called_once()
示例#12
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)
示例#13
0
    def test_from_pending_payment_initial_to_pending_payment(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository, sample_member: Member,
            mock_charter_repository: CharterRepository,
            sample_membership_pending_payment_initial: Membership,
            sample_subscription_duration_no_account: SubscriptionBody,
            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_initial], 1))
        mock_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))
        # When...
        member_manager.update_subscription(
            ctx, sample_member.id, sample_subscription_duration_no_account)

        # 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_charter_repository.get.assert_not_called()
示例#14
0
    def test_unknown_price_asign_to_duration(
            self, ctx, mock_membership_repository: MembershipRepository,
            mock_member_repository: MemberRepository,
            mock_charter_repository: CharterRepository, sample_member: Member,
            sample_subscription_duration_account_payment_method:
        SubscriptionBody, sample_membership_pending_rules: Membership,
            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_charter_repository.get = MagicMock(
            return_value=str(datetime.datetime.today()))
        sample_subscription_duration_account_payment_method.duration = 5

        with raises(NoPriceAssignedToThatDuration):
            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_charter_repository.get.assert_called_once()
        mock_membership_repository.update.assert_not_called()