def issue_coupon(self, coupon_series_id, userId): with self.lock: self.result['queued_count'] -= 1 issue_coupon_obj = { 'couponSeriesId': coupon_series_id, 'storeUnitId': self.tillId, 'userId': userId } issue_coupon_request = LuciObject.issueCouponRequest(issue_coupon_obj) # Issue coupon request start = time.time() coupon_details = self.connObj.issueCoupon( issue_coupon_request).__dict__ end = time.time() total = end - start with self.lock: self.result['total_issue_count'] += 1 self.result['total_issue_time'] += total self.result['avg_issue_time'] = self.result[ 'total_issue_time'] / self.result['total_issue_count'] self.queue.put((userId, coupon_details['couponCode']))
def test_LUCI_GCD_024(self): # Save Coupon Config couponConfigObj, couponSeriesId = LuciHelper.saveCouponConfigAndAssertions(self) couponConfigObj.update({'allow_multiple_vouchers_per_user': True, 'do_not_resend_existing_voucher': True}) LuciHelper.saveCouponConfigAndAssertions(self,couponConfigObj) transactionId1 = Utils.getTime(milliSeconds=True); time.sleep(2) transactionId2 = Utils.getTime(milliSeconds=True); # Construct Obj and Issue Coupon Code issueCouponObj = {'couponSeriesRequired': True, 'billId': transactionId1} couponCode1 = LuciHelper.issueCouponAndAssertions(self,couponSeriesId, issueCouponObj)[0] # Change Issue obj billId and Issue one more coupon issueCouponObj = {'couponSeriesRequired': True, 'billId': transactionId2} couponCode2 = LuciHelper.issueCouponAndAssertions(self,couponSeriesId, issueCouponObj)[0] tempBill1 = self.billId LuciHelper.redeemCouponAndAssertions(self, couponSeriesId, couponCode1) tempBill2 = self.billId = Utils.getTime(milliSeconds=True) LuciHelper.redeemCouponAndAssertions(self, couponSeriesId, couponCode2) # coupon Search and Assertion redemptionFiltersObj = LuciObject.redemptionFilters({'transactionId' : [tempBill1]}) issualFilterObj = LuciObject.issualFilters({'transactionId': [transactionId1]}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode1]) redemptionFiltersObj = LuciObject.redemptionFilters({'transactionId' : [tempBill2]}) issualFilterObj = LuciObject.issualFilters({'transactionId': [transactionId2]}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode2]) redemptionFiltersObj = LuciObject.redemptionFilters({'transactionId' : [tempBill1,tempBill2]}) issualFilterObj = LuciObject.issualFilters({'transactionId': [transactionId1, transactionId2]}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode1, couponCode2])
def test_LUCI_GCD_021(self): # Save Coupon Config couponConfigObj, couponSeriesId = LuciHelper.saveCouponConfigAndAssertions(self) couponConfigObj.update({'allow_multiple_vouchers_per_user': True, 'do_not_resend_existing_voucher': True}) LuciHelper.saveCouponConfigAndAssertions(self,couponConfigObj) couponCode1, detailsDict = LuciHelper.issueCouponAndAssertions(self,couponSeriesId) issualStartTime1 = detailsDict['issuedDate'] issualEndTime1 = issualStartTime1 + 4000 Logger.log('Issued Date and Time : {} , EndTime : {}'.format(issualStartTime1,issualEndTime1)) # coupon Search and Assertion time.sleep(4) couponCode2, detailsDict = LuciHelper.issueCouponAndAssertions(self,couponSeriesId) issualStartTime2 = detailsDict['issuedDate'] issualEndTime2 = issualStartTime2 + 4000 redeemedDate1 = LuciHelper.redeemCouponAndAssertions(self, couponSeriesId, couponCode1)['redemptionDate'] time.sleep(4) self.billId = Utils.getTime(milliSeconds=True) redeemedDate2 = LuciHelper.redeemCouponAndAssertions(self, couponSeriesId, couponCode2)['redemptionDate'] # coupon Search and Assertion redemptionFiltersObj = LuciObject.redemptionFilters({'redemptionDateStart': (redeemedDate1 - 1000),'redemptionDateEnd': (redeemedDate1 + 1000)}) issualFilterObj = LuciObject.issualFilters({'issualDateStart': (issualStartTime1 - 1000), 'issualDateEnd': (issualEndTime1 + 1000)}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode1]) redemptionFiltersObj = LuciObject.redemptionFilters({'redemptionDateStart': (redeemedDate2 - 1000),'redemptionDateEnd': (redeemedDate2 + 1000)}) issualFilterObj = LuciObject.issualFilters({'issualDateStart': (issualStartTime2 - 1000), 'issualDateEnd': (issualEndTime2 + 1000)}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode2]) redemptionFiltersObj = LuciObject.redemptionFilters({'redemptionDateStart': (redeemedDate1 - 1000),'redemptionDateEnd': (redeemedDate2 + 1000)}) issualFilterObj = LuciObject.issualFilters({'issualDateStart': (issualStartTime1 - 1000), 'issualDateEnd': (issualEndTime2 + 1000)}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode1, couponCode2])
def test_LUCI_GCD_022(self): # Save Coupon Config couponConfigObj, couponSeriesId = LuciHelper.saveCouponConfigAndAssertions(self) couponConfigObj.update({'allow_multiple_vouchers_per_user': True, 'do_not_resend_existing_voucher': True}) LuciHelper.saveCouponConfigAndAssertions(self,couponConfigObj) couponCode1, detailsDict = LuciHelper.issueCouponAndAssertions(self,couponSeriesId) issualStartTime1 = detailsDict['issuedDate'] issualEndTime1 = issualStartTime1 + 1000 # coupon Search and Assertion time.sleep(4) couponCode2, detailsDict = LuciHelper.issueCouponAndAssertions(self,couponSeriesId) issualStartTime2 = detailsDict['issuedDate'] issualEndTime2 = issualStartTime2 + 1000 transNum1 = LuciHelper.redeemCouponAndAssertions(self, couponSeriesId, couponCode1)['transactionNumber'] self.billId = Utils.getTime(milliSeconds=True) transNum2 = LuciHelper.redeemCouponAndAssertions(self, couponSeriesId, couponCode2)['transactionNumber'] # coupon Search and Assertion redemptionFiltersObj = LuciObject.redemptionFilters({'transactionNumber' : [transNum1]}) issualFilterObj = LuciObject.issualFilters({'issualDateStart': (issualStartTime1), 'issualDateEnd': (issualEndTime1)}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode1]) redemptionFiltersObj = LuciObject.redemptionFilters({'transactionNumber' : [transNum2]}) issualFilterObj = LuciObject.issualFilters({'issualDateStart': (issualStartTime2), 'issualDateEnd': (issualEndTime2)}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode2]) redemptionFiltersObj = LuciObject.redemptionFilters({'transactionNumber' : [transNum1,transNum2]}) issualFilterObj = LuciObject.issualFilters({'issualDateStart': (issualStartTime1), 'issualDateEnd': (issualEndTime2)}) couponSearchRequest = {'redemptionFilters': redemptionFiltersObj, 'issualFilters': issualFilterObj} LuciHelper.couponSearchAndAssertion(self, [couponSeriesId], couponSearchRequest, [couponCode1, couponCode2])
def setup_class(self): Logger.logSuiteName(str(self).split('.')[-1]) self.constructObj = LuciObject() self.userId = constant.config['usersInfo'][0]['userId'] self.tillId = constant.config['tillIds'][0] self.billId = Utils.getTime(milliSeconds=True)
def uploadCouponAndAssertions(self, couponSeriesId, uploadType, issuedTo='-1', noOfCouponsToBeUpload=1, couponCode=None, dracraysUpload={}): isTaggedCoupon = True if uploadType == 2: isTaggedCoupon = False if False: #Change as True for old upload flow couponCodeVsUserMap = {} for _ in range(noOfCouponsToBeUpload): if couponCode == None or noOfCouponsToBeUpload != 1: couponCode = LuciHelper.generateCouponCode() if uploadType != 2: couponCodeVsUserMap.update({couponCode: str(issuedTo)}) else: couponCodeVsUserMap.update({couponCode: issuedTo}) uploadCouponRequest = { 'couponCodeVsUserMap': couponCodeVsUserMap, 'couponSeriesId': couponSeriesId, 's3Location': constant.config['requestId'], 'importType': uploadType } uploadCouponRes = self.connObj.uploadCoupons( LuciObject.uploadCouponsRequest(uploadCouponRequest)) if len(uploadCouponRes) == 0: # Get Coupon Configuration if issuedTo != '-1': LuciHelper.getCouponConfigAndAssertion( self, couponSeriesId, len(couponCodeVsUserMap), 0) else: LuciHelper.getCouponConfigAndAssertion( self, couponSeriesId, 0, 0) else: Assertion.constructAssertion( uploadCouponRes[couponCode] == 'duplicate coupon code', 'Duplicate Coupon Code is not uploaded') return {'coupons': [couponCode]} else: tmpDict = { 'errorCount': 0, 'userOnly': False, 'invalidCase': [False, False], 'couponCodeCAPS': True } tmpDict.update(dracraysUpload) uploadDict = DracarysHelper.uploadCoupons( self, couponSeriesId, onlyUser=tmpDict['userOnly'], is_invalidCase=tmpDict['invalidCase'], identifierType=self.constructObj. CustomerIdentifierDracarys[uploadType], userTaggedCoupons=isTaggedCoupon, noOfCouponUpload=noOfCouponsToBeUpload, expectedError=tmpDict['errorCount'], couponISCAPS=tmpDict['couponCodeCAPS']) couponIssuedDBDetails = LuciDBHelper.getIssuedCoupons( couponSeriesId) if len(couponIssuedDBDetails) != 0: issuedCouponList = list() for cc in couponIssuedDBDetails: issuedCouponList.append(cc['couponCode']) uploadDict['coupons'] = issuedCouponList return uploadDict else: return uploadDict
def issueCouponAndAssertions(self, couponSeriesId, issueCouponParamObj={}, couponIssuedCount=1, expectException=False): issueCouponObj = { 'couponSeriesId': couponSeriesId, 'storeUnitId': self.tillId, 'userId': self.userId } actualTillid = self.tillId if issueCouponParamObj.has_key('storeUnitId'): self.tillId = issueCouponParamObj['storeUnitId'] issueCouponObj.update(issueCouponParamObj) issueCouponRequest = LuciObject.issueCouponRequest(issueCouponObj) for _ in range(0, 5): couponDetails = self.connObj.issueCoupon( issueCouponRequest).__dict__ if couponDetails['ex'] != None and not expectException: time.sleep(1) else: break if expectException: return couponDetails['ex'].__dict__ couponCode = couponDetails['couponCode'] Assertion.constructAssertion(couponDetails != None, 'Issued Coupon Details not Empty') Assertion.constructAssertion( couponDetails['orgId'] == constant.config['orgId'], 'Coupon Series OrgId Actual : {} and Expected : {}'.format( couponDetails['orgId'], constant.config['orgId'])) Assertion.constructAssertion( couponDetails['couponSeriesId'] == couponSeriesId, 'Coupon Series Id Actual : {} and Expected : {}'.format( couponDetails['couponSeriesId'], couponSeriesId)) Assertion.constructAssertion( couponDetails['issuedToUserId'] == self.userId, 'Coupon code Issued to userId Actual : {} and Expected : {}'. format(couponDetails['issuedToUserId'], self.userId)) Assertion.constructAssertion( couponDetails['couponCode'] == couponCode, 'Issued Coupon code Actual : {} and Expected : {}'.format( couponDetails['couponCode'], couponCode)) couponIssuedDict = LuciDBHelper.getCouponsIssued( couponSeriesId, self.userId) Assertion.constructAssertion( couponIssuedDict != {}, 'Issued Coupon Code recorded in Coupons_issued table') Assertion.constructAssertion( couponIssuedDict['issuedBy'] == self.tillId, 'Issued by till Actual: {} and Expected : {}'.format( couponIssuedDict['issuedBy'], self.tillId)) # couponSentHistoryList = LuciDBHelper.getCouponSentHistoryList(couponSeriesId, couponIssuedDict['id']) # Assertion.constructAssertion(couponSentHistoryList != [], 'Issued Coupon details recorded in Coupon_sent_history') # Assertion.constructAssertion(len(couponSentHistoryList) == couponIssuedCount, 'Coupon_sent_history records Actual : {} and Expected : {}'.format(len(couponSentHistoryList), couponIssuedCount)) # Assertion.constructAssertion(couponSentHistoryList[0]['notes'] in ['ISSUED', 'RESENT'], 'Coupon_sent_history Notes Actual : {} and Expected : ISSUED/RESENT'.format(couponSentHistoryList[0]['notes'])) self.tillId = actualTillid return couponCode, couponDetails
def test_LUCI_GCC_006(self, description,getCouponRequest): configRequest = LuciObject.getCouponConfigRequest(getCouponRequest) couponConfigList = self.connObj.getCouponConfiguration(configRequest) Logger.log('Log Details : ', len(couponConfigList)) Assertion.constructAssertion(len(couponConfigList) == 5, 'GetCouponConfig Limit {} and couponconfig got {}'.format(5, len(couponConfigList))) Assertion.constructAssertion(couponConfigList != None, 'Retrieved couponConfig from GetCouponConfig by OwnedBy')
def setup_class(self): Logger.logSuiteName(str(self).split('.')[-1]) self.constructObj = LuciObject() self.DracarysObj = DracarysObject() self.userId = constant.config['usersInfo'][0]['userId'] self.tillId = constant.config['tillIds'][0]
def test_MULTI_INSTANCE_SCC_IC_CS_002(self, description): Logger.log('starting test_SCC_IC_CS_002_MULTI_INSTANCE execution') if not LuciHelper.verifyLuciServicesCount(2): pytest.skip("test requires minimum of 2 luci services running") self.connObj = LuciHelper.getFirstConn(newConnection=True) couponConfigObj, couponSeriesId = LuciHelper.saveCouponConfigAndAssertions( self) self.connObj = LuciHelper.getSecondConn(newConnection=True) userId = random.randint(1111111, 9999999) issueCouponObj = { 'couponSeriesId': couponSeriesId, 'storeUnitId': self.tillId, 'userId': userId } issueCouponRequest = LuciObject.issueCouponRequest(issueCouponObj) coupon_details = self.connObj.issueCoupon(issueCouponRequest).__dict__ Assertion.constructAssertion(coupon_details['couponCode'] is not None, 'Coupon code is not null') time.sleep(2) # update coupon config on second server dat = datetime.datetime.now() + datetime.timedelta(days=3) owner_validity = int(time.mktime(dat.timetuple()) * 1e3) couponConfigObj.update({ 'alphaNumeric': False, 'shortCodeLength': 4, 'ownerValidity': owner_validity, 'max_vouchers_per_user': 5 }) LuciHelper.saveCouponConfigAndAssertions(self, couponConfigObj) config1 = LuciHelper.getCouponConfigAndAssertion(self, couponSeriesId, no_issued=1) Assertion.constructAssertion(config1['alphaNumeric'] is False, 'alphanumeric config key updated') Assertion.constructAssertion(config1['shortCodeLength'] == 4, 'short code length updated') Assertion.constructAssertion( config1['ownerValidity'] == owner_validity, 'owner validity is updated') Assertion.constructAssertion(config1['max_vouchers_per_user'] == 5, 'max voucher per user is updated') self.connObj = LuciHelper.getFirstConn(newConnection=True) couponSearchRequest = { 'couponSeriesIds': [couponSeriesId], 'customerIds': [userId], 'couponSeriesRequired': True } couponDetailsList = None for _ in range(7): couponDetailsResponse = self.connObj.couponSearch( LuciObject.couponSearchRequest(couponSearchRequest)).__dict__ couponDetailsList = couponDetailsResponse['coupons'] if len(couponDetailsList) == 1 and vars( vars(couponDetailsResponse['coupons'][0]) ['couponSeries'])['alphaNumeric'] is not None: break time.sleep(10) Assertion.constructAssertion( len(couponDetailsList) == 1, 'Coupon Details list, Actual {} and Expected 1'.format( len(couponDetailsList))) for i in range(len(couponDetailsList)): couponDetails = couponDetailsList[i].__dict__ Assertion.constructAssertion( vars(couponDetails['couponSeries'])['alphaNumeric'] is False, 'alphanumeric config key updated') Assertion.constructAssertion( vars(couponDetails['couponSeries'])['shortCodeLength'] == 4, 'short code length updated') Assertion.constructAssertion( vars(couponDetails['couponSeries'])['ownerValidity'] == owner_validity, 'owner validity is updated') Assertion.constructAssertion( vars(couponDetails['couponSeries'])['max_vouchers_per_user'] == 5, 'max voucher per user is updated')
def test_authorize_sms_using_revokedvoucherseries(self, description, messageInfo): invalidateCouponReq = LuciObject.invalidateCouponRequest({'orgId' : constant.config['orgId'], 'couponSeriesId' : int(self.voucherId)}) Logger.log('Is Revoked Coupons : ' , self.luciObj.invalidateCoupons(invalidateCouponReq)) authorizeResult = authorize.authorizeCampaign(self, messageInfo, False) authorize.assertAuthorize(authorizeResult['authorizeResponse'], 200) authorize.dbAssertAuthorize(authorizeResult)