Example #1
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()
Example #2
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()
Example #3
0
    def test_happy_path(self, ctx, mock_member_repository: MemberRepository,
                        sample_member: Member, member_manager: MemberManager):
        # Given...
        mock_member_repository.search_by = MagicMock(
            return_value=([sample_member], 1))

        # When...
        test_terms = 'blah blah blah'
        test_offset = 42
        test_limit = 99
        result, _ = member_manager.search(ctx,
                                          limit=test_limit,
                                          offset=test_offset,
                                          terms=test_terms)

        # Expect...
        assert [sample_member.id] == result

        # Make sure that all the parameters are passed to the DB.
        mock_member_repository.search_by.assert_called_once_with(
            ctx,
            limit=test_limit,
            offset=test_offset,
            terms=test_terms,
            filter_=None)
Example #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()
Example #5
0
    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)
Example #6
0
 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())
Example #7
0
    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()
Example #8
0
    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)
Example #9
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()
Example #10
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()
Example #11
0
    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))
Example #12
0
    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)
Example #13
0
    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))
Example #14
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()
Example #15
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)
Example #16
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()
Example #17
0
    def test_no_account_type_adherent(
            self, ctx, mock_member_repository: MemberRepository,
            mock_account_type_repository: AccountTypeRepository,
            member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_login = MagicMock(return_value=(None))
        mock_account_type_repository.search_by = MagicMock(return_value=([],
                                                                         0))

        # When...
        with pytest.raises(AccountTypeNotFoundError):
            member_manager.create(ctx, body=MemberBody(username="******", ))

        # Expect...
        mock_account_type_repository.search_by.assert_called_once_with(
            ctx, terms="Adhérent")
Example #18
0
    def test_member_already_exist(self, ctx,
                                  mock_member_repository: MemberRepository,
                                  sample_member: AbstractMember,
                                  member_manager: MemberManager):
        # Given...
        mock_member_repository.get_by_login = MagicMock(
            return_value=(sample_member))

        # When...
        with pytest.raises(MemberAlreadyExist):
            member_manager.create(
                ctx, body=MemberBody(username=sample_member.username))

        # Expect...
        mock_member_repository.get_by_login.assert_called_once_with(
            ctx, sample_member.username)
Example #19
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)
Example #20
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()
Example #21
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)
Example #22
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()
Example #23
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()