コード例 #1
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #2
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #3
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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
ファイル: test_member_manager.py プロジェクト: minet/adh6
    def test_not_found(self, ctx, mock_member_repository: MemberRepository,
                       sample_member, member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_id = MagicMock(return_value=(None))

        # When...
        with raises(MemberNotFoundError):
            member_manager.get_logs(ctx, sample_member.username)
コード例 #5
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
 def test_member_not_found(self, ctx,
                           mock_member_repository: MemberRepository,
                           sample_member: Member,
                           member_manager: MemberManager):
     mock_member_repository.get_by_id = MagicMock(
         return_value=(None), side_effect=MemberNotFoundError(""))
     # When...
     with pytest.raises(MemberNotFoundError):
         member_manager.create_subscription(ctx, sample_member.id,
                                            SubscriptionBody())
コード例 #6
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    def test_unknown_member(self, ctx,
                            mock_member_repository: MemberRepository,
                            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            side_effect=MemberNotFoundError(""))

        with raises(MemberNotFoundError):
            member_manager.validate_subscription(ctx, 0, False)

        mock_member_repository.get_by_id.assert_called_once()
コード例 #7
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    def test_unknown_member(self, ctx,
                            mock_member_repository: MemberRepository,
                            sample_subscription_empty: SubscriptionBody,
                            sample_member: Member,
                            member_manager: MemberManager):
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member), side_effect=MemberNotFoundError(""))

        with raises(MemberNotFoundError):
            member_manager.create_subscription(ctx, sample_member.id,
                                               sample_subscription_empty)
コード例 #8
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #9
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #10
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    def test_not_found(self, ctx, sample_member,
                       mock_member_repository: MemberRepository,
                       member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_id = MagicMock(
            return_value=(None), side_effect=MemberNotFoundError(""))

        # When...
        with raises(MemberNotFoundError):
            member_manager.get_by_id(ctx, id=sample_member.id)

        # Expect...
        mock_member_repository.get_by_id.assert_called_once_with(
            ctx, sample_member.id)
コード例 #11
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    def test_member_not_found(self, ctx,
                              mock_member_repository: MemberRepository,
                              member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_id = MagicMock(
            return_value=(None), side_effect=MemberNotFoundError(""))

        # When...
        with pytest.raises(MemberNotFoundError):
            member_manager.get_profile(ctx)

        # Expect...
        mock_member_repository.get_by_id.assert_called_once_with(
            ctx, ctx.get(CTX_ADMIN))
コード例 #12
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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)
コード例 #13
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    def test_happy_path(self, ctx, mock_member_repository: MemberRepository,
                        sample_member: Member, member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_id = MagicMock(
            return_value=(sample_member))

        # When...
        m, roles = member_manager.get_profile(ctx)

        # Expect...
        assert sample_member == m
        assert len(roles) == len(ctx.get(CTX_ROLES))
        assert len(roles) == len(set(roles) & set(ctx.get(CTX_ROLES)))
        mock_member_repository.get_by_id.assert_called_once_with(
            ctx, ctx.get(CTX_ADMIN))
コード例 #14
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #15
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #16
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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)
コード例 #17
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #18
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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)
コード例 #19
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()
コード例 #20
0
ファイル: test_member_manager.py プロジェクト: minet/adh6
    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()