예제 #1
0
    def issueMultipleCoupon(self,
                            couponSeriesId,
                            userList,
                            issueCouponParamObj={},
                            expectResponseException=[False]):
        issueMultipleCouponsRequest = {
            'couponSeriesId': couponSeriesId,
            'storeUnitId': self.tillId,
            'userIds': userList
        }
        issueMultipleCouponsRequest.update(issueCouponParamObj)
        issueMultipleCouponsRequestObj = LuciObject.issueMultipleCouponsRequest(
            issueMultipleCouponsRequest)

        couponDetailsList = self.connObj.issueMultipleCoupons(
            issueMultipleCouponsRequestObj)

        ExpectedUserIdsList = []
        ExpectExceptionList = []
        for couponDetails in couponDetailsList:
            couponDetails = couponDetails.__dict__
            if not expectResponseException[0]:
                ExpectedUserIdsList.append(couponDetails['issuedToUserId'])
                Assertion.constructAssertion(
                    couponDetails['ex'] is None,
                    'Coupon Details with Luci Exception Message: {}'.format(
                        couponDetails['ex']))
                Assertion.constructAssertion(
                    couponDetails['couponSeriesId'] == couponSeriesId,
                    'Coupon Series Id Actual : {} and Expected : {}'.format(
                        couponDetails['couponSeriesId'], couponSeriesId))
            elif couponDetails['ex'] is not None:
                ex = couponDetails['ex'].__dict__
                if ex['errorMsg'].lower() == expectResponseException[1]:
                    ExpectExceptionList.append(ex['errorMsg'])
                else:
                    Assertion.constructAssertion(
                        False,
                        'Expected Exception Message : {} and Actual : {}'.
                        format(expectResponseException[1],
                               ex['errorMsg'].lower()),
                        verify=False)
        if expectResponseException[0] and len(ExpectExceptionList) == 0:
            Assertion.constructAssertion(
                False,
                'Expected issual exception: {} not in Response '.format(
                    expectResponseException[1]),
                verify=False)
        elif expectResponseException[0] and len(ExpectExceptionList) > 0:
            return ExpectExceptionList

        Assertion.constructAssertion(
            len(userList) == len(ExpectedUserIdsList),
            'Multiple Coupons issued to Actual : {} and Expected : {}'.format(
                len(ExpectedUserIdsList), len(userList)))
        Assertion.constructAssertion(
            set(ExpectedUserIdsList) == set(userList),
            'Matched Issue Coupon request and Issued coupon UserIds')
        return couponDetailsList
    def est_LUCI_BulkIssual(self, description):
        couponConfigObj, couponSeriesId = LuciHelper.saveCouponConfigAndAssertions(
            self, couponConfigReq={"any_user": True})
        couponCodeList = []
        Logger.log('Coupon series Id: ', couponSeriesId)

        bulkUserIds = []
        for _ in range(1000000):
            bulkUserIds.append(randValues.randomInteger(9))
        bulkUserIds = list(set(bulkUserIds))
        limit = 500000
        i = 0
        Logger.log('Actial : ', len(bulkUserIds))
        for _ in range(len(bulkUserIds)):
            if limit > (len(bulkUserIds)):
                limit = len(bulkUserIds)
            issueMultipleCouponsRequest = {
                'couponSeriesId': couponSeriesId,
                'storeUnitId': self.tillId,
                'userIds': bulkUserIds[i:(limit)]
            }
            issueMultipleCouponsRequestObj = LuciObject.issueMultipleCouponsRequest(
                issueMultipleCouponsRequest)
            couponDetailsList = self.connObj.issueMultipleCoupons(
                issueMultipleCouponsRequestObj)

            for couponDetails in couponDetailsList:
                couponDetails = couponDetails.__dict__
                couponCodeList.append(couponDetails['couponCode'])
            if limit == len(bulkUserIds):
                break

            i = limit
            limit = limit + 1000

        for couponCode, userId in zip(couponCodeList, bulkUserIds):
            couponDetailsList = self.connObj.redeemCoupons(
                LuciHelper.redeemCouponRequest(
                    [couponCode],
                    userId,
                    billId=Utils.getTime(milliSeconds=True)))