예제 #1
0
파일: test_SMS.py 프로젝트: anupsl/pyApps
    def test_SMSCharUTF8(self):
        self.nsadminHelper.configureGateway('HIGH', 'cardboardfishmock')
        messageArabic = "في شعري ، ونحن نعملمجمو باستمرار لمساعدة العملاء على تحقيق النجاح في الأسواق المتطورة بسرعة من خلال حلول عالمية"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "truncate": False,
            "message": messageArabic
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(
            resp[0][2].encode('utf8') == messageArabic, 'Arabic Char')
        Assertion.constructAssertion(resp[0][1] == 2, 'Message count')

        messageChinese = "在毛細管中,我們不斷努力,以幫助我們的客戶通過我們的世界級解決方案,服務和產品成功在快速發展的市場 - 將合併在毛細管中,我們不斷努力,以以- 將合併在毛細管中,我們不斷努力,以以"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "truncate": False,
            "message": messageChinese
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(
            resp[0][2].encode('utf8') == messageChinese, 'Chinese Char')
        Assertion.constructAssertion(resp[0][1] == 2, 'Message count')
예제 #2
0
 def setup_method(self, method):
     self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
     if self.cluster in ['nightly']:
         self.orgId = 780
     elif self.cluster == 'china':
         self.orgId = 200017
     self.nsadminHelper = NSAdminHelper(self.orgId, 'WECHAT')
     Logger.logMethodName(method.__name__)
예제 #3
0
 def setup_method(self, method):
     messageClass = 'SMS'
     if 'EMAIL' in method.__name__:
         messageClass = 'EMAIL'
     self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
     self.nsadminHelper = NSAdminHelper(self.orgId, messageClass)
     self.nsadminHelper.disableDomainPropertiesGatewayMap()
     Logger.logMethodName(method.__name__)
예제 #4
0
파일: irisHelper.py 프로젝트: anupsl/pyApps
 def createNewDummyGateway(channel):
     messageClass = 'SMS' if channel.lower() in ['mobile', 'sms'] else channel
     nsObj = NSAdminHelper.getConnObj(newConnection=True)
     nsadminHelper = NSAdminHelper(constant.config['orgId'], messageClass)
     for eachType in [('HIGH', 'localmail_HIGH_{}'.format(int(time.time())),["capillary", "otp"]),('BULK', 'localmail_BULK_{}'.format(int(time.time())),["capillary", "campaigns"])]:
         try:
             nsadminHelper.configureGateway(eachType[0], eachType[1] + '_2', False, eachType[2])
         except Exception,exp:
             Logger.log('Exception While Creating Dummy Gateway :{}'.format(exp))
예제 #5
0
 def setBaseState():
     module = constant.config['module']
     if module == 'nsadmin':
         NSAdminHelper.checkCommServerConn()
     if module == 'iris':
         NSAdminHelper.checkCommServerConn(ignoreConnectionError=True)
         LuciHelper.checkLuciConn(ignoreConnectionError=False)
     if module == 'irisv2':
         LuciHelper.checkLuciConn(ignoreConnectionError=True)
         ReonHelper.checkReonConnection(ignoreConnectionError=True)
         NSAdminHelper.checkCommServerConn()
         CampaignShardHelper.checkCampaignShardConnection()
     if module == 'luci':
         LuciHelper.loginAndGetCookies()
         LuciHelper.checkLuciConn()
         DracarysHelper.checkDracarysConn()
         LuciHelper.setBaseDetails()
     if module == 'veneno':
         LuciHelper.checkLuciConn(ignoreConnectionError=True)
         LuciDBHelper.getAdminUserId()
         VenenoHelper.checkVenenoServerConnection()
         NSAdminHelper.checkCommServerConn(ignoreConnectionError=True)
         CampaignShardHelper.checkCampaignShardConnection()
     if module == 'campaign_shard':
         CampaignShardHelper.checkCampaignShardConnection()
     if module == 'darknight':
         DarknightHelper.checkDarknightConn()
     if module == 'campaignsui':
         NSAdminHelper.checkCommServerConn(ignoreConnectionError=True)
         TemporalHelper.checkTemporalServerConnection(ignoreConnectionError=True)
         try:
             status, version = ChromeDriverManager.checkChromeDriverCompatibility()
             if not status:
                 ChromeDriverManager.downloadChromeDriver(version)
         except:
             Logger.log(traceback.format_exc())
     if module == 'emf' or module == 'peb':
         LoyaltyHelper.checkEMFConn()
         PEBHelper.checkPEBConn()
     if module == 'peb':
         PEBHelper.checkPEBConn()
     if module == 'social':
         SocialHelper.checkSocialConn()
         VenenoHelper.checkVenenoServerConnection()
         LuciHelper.checkLuciConn(ignoreConnectionError=True)
         LuciDBHelper.getAdminUserId()
         DracarysHelper.checkDracarysConn(ignoreConnectionError=True)
         LuciHelper.loginAndGetCookies()
         LuciHelper.setBaseDetails()
예제 #6
0
 def setup_class(self):
     Logger.logSuiteName(str(self).split('.')[-1])
     self.orgId = constant.config['orgId']
     self.cluster = constant.config['cluster']
     self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
     self.nsadminHelper = NSAdminHelper(self.orgId, 'EMAIL')
     self.nsadminHelper.disableDomainPropertiesGatewayMap()
     self.nsadminHelper.configureGateway('HIGH', 'sendgrid_HIGH')
     self.nsadminHelper.configureGateway('BULK', 'sendgrid_BULK')
     self.DR = DeliveryReceipt()
     self.msgDict = {
         "messageClass": "EMAIL",
         "priority": 'HIGH',
         "message": "test message for DLR"
     }
예제 #7
0
파일: test_SMS.py 프로젝트: anupsl/pyApps
    def test_SMScharLimit(self):
        self.nsadminHelper.configureGateway('HIGH', 'cardboardfishmock')
        message160CharSize = "At Capillary, we continuously work to help our clients succeed in rapidly evolving markets through our world-class solutions, services and products -  combining"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": message160CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(resp[0][2] == message160CharSize,
                                     '160 Char limit')
        Assertion.constructAssertion(resp[0][1] == 1, 'Message count')

        message320CharSize = "At Capillary, we continuously work to help our clients succeed in rapidly evolving markets through our world-class solutions, services and products. By combining big data with a robust, cloud-based analytics engine, we optimize the relevance and profitability of discounts and personalized offers to consumers in real time, significantly increasing both loyalty and sales"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": message320CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(resp[0][1] == 1,
                                     'Message count without truncate')

        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "truncate": False,
            "message": message320CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(resp[0][2] == message320CharSize,
                                     '320 Char limit')
        Assertion.constructAssertion(resp[0][1] == 3, 'Message count')
예제 #8
0
 def test_Count_Messages_RECEIVED_IN_QUEUE_READ(self):
     currentMonth = NSAdminHelper.getTableName()
     query = 'SELECT COUNT( * ) FROM ' + currentMonth + ' where sent_time >= SUBDATE( current_date, 2) and sent_time < current_date and status in (2,35)'
     output = dbHelper.queryDB(query, 'nsadmin')
     Assertion.constructAssertion(output[0][0] == 0,
                                  'RECEIVED_IN_QUEUE & READ count',
                                  verify=True)
예제 #9
0
 def setup_class(self):
     Logger.logSuiteName(str(self).split('.')[-1])
     nsPort = constant.config['nsMasterPort']
     self.nsHelper = NSAdminHelper(constant.config['orgId'], 'SMS')
     luciPort = constant.config['luciPort'].next()
     self.luciObj = LuciThrift(luciPort)
     self.constructObj = LuciObject()
     constant.config['requestId'] = 'requestId_IRIS_LUCI'
     createListresponse, createListPayload, campaignId = campaignList.createList({'customTagCount':0, 'name':'IRIS_LIST_' + str(int(time.time() * 100000))}, campaignType=['LIVE', 'ORG', 'List', 'TAGS', 0])
     campaignList.assertCreateList(createListresponse, 200)
     groupVersionDetailResult, bucketId = campaignList.assertCreateListDbCalls(createListresponse['json']['entity']['listId'], createListPayload, 'ORG')
     Logger.log('GroupVersionId : {}, bucketId : {}'.format(groupVersionDetailResult, bucketId))
     addRecipientResponse, addRecipientPayload = campaignList.addRecipient({}, campaignId, createListresponse['json']['entity']['listId'], 'mobile', 10, 0, newUser=False)
     campaignList.assertAddRecipient(addRecipientResponse, 200)
     campaignList.assertAddRecipientDbCalls(addRecipientResponse, addRecipientPayload, createListresponse, campaignId, bucketId, {'TEST':groupVersionDetailResult['TEST'], 'CONTROL':groupVersionDetailResult['CONTROL']}, 'mobile')
     self.bucketId = bucketId
     self.groupVersionResult = dbCallsList.getGroupVersionDetailsWithGroupId(createListresponse['json']['entity']['listId'])
     responseCoupon, payloadCoupon, campaignId = coupons.createCoupons(campaignId=campaignId)
     self.strategy = construct.constructStrategyIds()
     self.programeId = self.strategy['programeId']
     self.allocationStrategyId = self.strategy['allocationStrategyId']
     self.expiryStrategyId = self.strategy['expirationStrategyId']
     if 'errors' not in responseCoupon['json']:
         self.voucherId = responseCoupon['json']['entity']['voucherSeriesId']
     else:
         self.voucherId = dbCallsCoupons.getVoucherSeriesIdUsingCampaignId(campaignId)
     self.campaignId = campaignId
     self.listId = createListresponse['json']['entity']['listId']
     Logger.log('Using CampaignId : {} , listId : {} for Execution of Create Message'.format(self.campaignId, self.listId))
예제 #10
0
 def updateEmailStatus(listObject):
     nsObj = NSAdminHelper.getConnObj()
     for eachList in listObject:
         allusersInList = [
             eachUser.split(',')[2] for eachUser in listObject[eachList]
             ['addRecipientPayload']['data']
         ]
         if not nsObj.whitelistEmailIds(allusersInList):
             raise Exception("Not Able To Whitelist New Created users ")
예제 #11
0
class Test_Others():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']

    def setup_method(self, method):
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(constant.config['orgId'], 'SMS')
        Logger.logMethodName(method.__name__)

    def test_isAlive(self):
        output = self.nsObj.isAlive()
        Assertion.constructAssertion(output == True, 'isAlive output')

    def test_getStatus(self):
        output = self.nsObj.getStatus()
        Assertion.constructAssertion(output == 'All is well',
                                     'getStatus output')

    def test_isMaster(self):
        output = self.nsObj.isMaster()
        Assertion.constructAssertion(output == True,
                                     'isMaster output',
                                     verify=True)

    def test_getMessageLogs(self):
        msgDict = {
            "receiver": "",
            "messageClass": "SMS",
            "priority": "BULK",
            "message": "test message from auto"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict, 1)
        msgObj = self.nsObj.getMessagesById([msgId])[0]
        msgLogObj = self.nsObj.getMessageLogs(self.orgId, "SMS",
                                              msgObj.receiver)[0]
        Assertion.constructAssertion(msgLogObj.messageId == msgObj.messageId,
                                     'getMessageLogs messageId')
        Assertion.constructAssertion(msgLogObj.status == msgObj.status,
                                     'getMessageLogs status')

    def test_Count_Messages_RECEIVED_IN_QUEUE_READ(self):
        currentMonth = NSAdminHelper.getTableName()
        query = 'SELECT COUNT( * ) FROM ' + currentMonth + ' where sent_time >= SUBDATE( current_date, 2) and sent_time < current_date and status in (2,35)'
        output = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(output[0][0] == 0,
                                     'RECEIVED_IN_QUEUE & READ count',
                                     verify=True)

    def test_Count_Messages_DELAYED_SCHEDULED(self):
        currentMonth = NSAdminHelper.getTableName()
        query = 'SELECT COUNT( * ) FROM ' + currentMonth + ' where sent_time >= SUBDATE( current_date, 2) and sent_time < current_date and status in (33)'
        output = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(output[0][0] == 0,
                                     'DELAYED_SCHEDULED count')
예제 #12
0
    def test_sendMultipleMessageEmailWithBulkGateway(self):
        self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
        params = [[
            0, "BULK", "test message 1",
            "autoemail" + randValues.getRandomMobileNumber() + "@gmail.com",
            ['RECEIVED_IN_QUEUE', 'SENT']
        ],
                  [
                      1, "BULK", "test message 2", "autoemail" +
                      randValues.getRandomMobileNumber() + "@gmail.com",
                      ['RECEIVED_IN_QUEUE', 'SENT']
                  ],
                  [
                      2, "HIGH", "test message 3", "autoemail" +
                      randValues.getRandomMobileNumber() + "@gmail.com",
                      ['RECEIVED_IN_QUEUE', 'FAILED']
                  ]]
        self.nsObj.whitelistEmailIds(
            [params[0][3], params[1][3], params[2][3]])
        msgObjList = []
        for p in params:
            msgObj = NSAdminObject.message({
                "messageClass": "EMAIL",
                "inboxId": p[0],
                "priority": p[1],
                "message": p[2],
                "receiver": p[3],
                "body": "test body"
            })
            msgObjList.append(msgObj)
        resp = self.nsObj.sendMultipleMessages(msgObjList)
        for i in range(0, 3):
            msgId = resp[i]
            msgResp = self.nsObj.getMessagesById([msgId])[0]
            #inboxId = msgResp.inboxId
            msgParams = params[i]
            Assertion.constructAssertion(msgResp.status in msgParams[4],
                                         'Messages status')
            Assertion.constructAssertion(msgResp.priority == msgParams[1],
                                         'Messages priority')
            Assertion.constructAssertion(msgResp.message == msgParams[2],
                                         'Message')
            Assertion.constructAssertion(msgResp.receiver == msgParams[3],
                                         'Messages receiver')
            currentMonthTable = NSAdminHelper.getDataTableName()
            query = 'select nsadmin_id from ' + currentMonthTable + ' where nsadmin_id=' + str(
                msgId)
            dbResp = dbHelper.queryDB(query, 'nsadmin')
            Assertion.constructAssertion(dbResp[0][0] == msgId, 'Messages id')

        for p in params:
            msg = self.nsObj.getMessagesByReceiver(self.orgId, p[3])
            Assertion.constructAssertion(msg[0].message == p[2],
                                         'Assert getMessagesByReceiver')
예제 #13
0
class Test_sendMessage_VoiceCall():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']
        self.cluster = constant.config['cluster']

    def setup_method(self, method):
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, 'VOICECALL')
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        Logger.logMethodName(method.__name__)

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'tbpvoicecall'),
                                                   ('BULK', 'tbpvoicecall')])
    def est_sendMessage_VoiceCall_Sanity(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "VOICECALL",
            "priority": priority,
            "message": "test message with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(type(msgId) == int, 'sendMessage output')
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')
예제 #14
0
 def test_sendMessage_EMAIL_ValidSender(self, priority, gateway):
     self.nsadminHelper.configureGateway(priority, gateway)
     msgDict = {
         "messageClass": "EMAIL",
         "priority": priority,
         'sender': '*****@*****.**',
         "message": "test message with priority " + priority
     }
     msgId = self.nsadminHelper.createAndSendMessage(msgDict)
     resp = self.nsadminHelper.assertWithWaitUntil(
         msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
     currentMonthTable = NSAdminHelper.getDataTableName()
     query = 'select sender from ' + currentMonthTable + ' where nsadmin_id=' + str(
         msgId)
     resp = dbHelper.queryDB(query, 'nsadmin')
     Assertion.constructAssertion(resp[0][0] == '*****@*****.**', 'sender')
예제 #15
0
파일: irisHelper.py 프로젝트: anupsl/pyApps
 def updateCredit(credit=0,channel='EMAIL'):
     try:
         nsObj = NSAdminHelper.getMasterConnObj() if constant.config['cluster'] in ['nightly','staging','china'] else NSAdminHelper.getConnObj(newConnection=True)
         messageClass = 1 if channel == 'EMAIL' else 0
         creditDetails1 = {
             "orgId": int(constant.config['orgId']),
             "bulkCredits": int(credit),
             'messageClass': messageClass
         }
         creditDetails1 = NSAdminObject.OrgCreditDetails(creditDetails1)
         if credit == 0:
             currVal = nsObj.getCreditDetailsByOrgAndChannel(constant.config['orgId'], messageClass, 'test_{}'.format(int(time.time())))
             currVal = int(currVal.bulkCredits) * -1
             creditDetails1.bulkCredits = currVal
         nsObj.addCredits(creditDetails1)
     except Exception,exp:
         raise Exception('NotAbleToUpdateCreditTo:{}'.format(credit))
         Logger.log(exp)
예제 #16
0
파일: irisHelper.py 프로젝트: anupsl/pyApps
    def getDomainGatewayMapId(messageClass='SMS'):
        nsObj = NSAdminHelper.getConnObj(newConnection=True)
        domainGateway = nsObj.getDomainPropertiesGatewayMapByOrg(int(constant.config['orgId']),
                                                                 NSAdminObject.MessageClass[messageClass])[0]
        domainMap = {
            'mapId': domainGateway.id
        }
        if messageClass == 'SMS':
            for eachContactInfo in domainGateway.domainProperties.contactInfo:
                if eachContactInfo.type == 'cdma_sender_id': domainMap.update({'cdma_sender_id': eachContactInfo.value})
                if eachContactInfo.type == 'gsm_sender_id': domainMap.update({'gsm_sender_id': eachContactInfo.value})
        elif messageClass == 'EMAIL':
            for eachContactInfo in domainGateway.domainProperties.contactInfo:
                if eachContactInfo.type == 'reply_to_id': domainMap.update({'reply_to_id': eachContactInfo.value})
                if eachContactInfo.type == 'sender_id': domainMap.update({'sender_id': eachContactInfo.value})
        else:
            raise Exception('OtherChannelsNotSupportedForDomainMapping')

        return domainMap
예제 #17
0
 def test_sendMessage_EMAIL_withHTMLContentAndAttachment(self):
     filePath = constant.rootPath + '/src/modules/nsadmin/html'
     body = FileHelper.readFile(filePath)
     self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
     msgDict = {
         "messageClass": "EMAIL",
         "priority": "BULK",
         "receiver": "*****@*****.**",
         "message": "test message with html content",
         "body": body,
         "attachmentId": [23303]
     }
     msgObj = NSAdminObject.message(msgDict)
     msgId = self.nsObj.sendMessage(msgObj)
     resp = self.nsadminHelper.assertWithWaitUntil(
         msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
     currentMonthTable = NSAdminHelper.getDataTableName()
     query = 'select attachment_id from ' + currentMonthTable + ' where nsadmin_id=' + str(
         msgId)
     resp = dbHelper.queryDB(query, 'nsadmin')
     Assertion.constructAssertion(resp[0][0] == '23303',
                                  'Messages attachmentId')
예제 #18
0
class Test_sendMessage_LINE():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']
        self.cluster = constant.config['cluster']

    def setup_method(self, method):
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, 'LINE')
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        Logger.logMethodName(method.__name__)

    ## 2019-02-11-17:25:51.518 [Camel (camel-ce) thread #1258 - RabbitMQConsumer] [1619] [85e72289-d6c0-4458-a147-bdb2e82e3ea5] [-1] [-1] [LINE] [line] [1548959588713] in.capillary.service.impl.IntouchAPIService:105 ERROR - error during fetching channel configs from intouch :

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def est_sendMessage_LINE(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        message = {
            "to":
            receiver,
            "messages": [{
                "type": "text",
                "text": "Hi, this is a test bulk message"
            }]
        }
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message with priority " + priority,
            'receiver': 'U1895436c12d420347a53ce25a3b7fad5'
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(type(msgId) == int, 'sendMessage output')
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')
예제 #19
0
class Test_sendMessage_WECHAT():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.cluster = constant.config['cluster']

    def setup_method(self, method):
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        if self.cluster in ['nightly']:
            self.orgId = 780
        elif self.cluster == 'china':
            self.orgId = 200017
        self.nsadminHelper = NSAdminHelper(self.orgId, 'WECHAT')
        Logger.logMethodName(method.__name__)

    @pytest.mark.parametrize('priority, tags, gateway',
                             [('HIGH', ['transaction'], 'wecrmwechat_HIGH'),
                              ('BULK', ['campaign'], 'wecrmwechat_BULK')])
    def test_sendMessage_Wechat_China_Prod_Sanity(self, priority, tags,
                                                  gateway):
        if self.cluster in ['nightly']:
            wechatTemplateId = "L_9kbOkFR2MAwDgNL-KRcoCxea7E_dE0-vT44UwZKIQ"
            wechatOriginalId = "wxbfceb2b8ab553715"
            wechatUrl = "https://nightly.capillary.in/"
        elif self.cluster == 'china':
            wechatTemplateId = "Nc9fDFlKRMWdaoxZtjzSkNo_teR1Cw8CH1TNXhlf0jc"
            wechatOriginalId = "gh_923969206326"
            wechatUrl = "http://we.capillarytech-cn.com/"
        receiver = 'oduTN1Tn2q6x0IfpHEwbF8Znb1fI'
        message = json.dumps({
            "template_id": wechatTemplateId,
            "touser": receiver,
            "OriginalId": wechatOriginalId,
            "Title": "订阅模板消息",
            "BrandId": "eGdQY2VQTCUyYjUlMmJaSE1SN2hwWFNkdGRYMEtSbXJOSUFZ",
            "url": wechatUrl,
            "TopColor": "#000000",
            "data": {
                "first": {
                    "Value": "WeChatTest",
                    "color": "#00000"
                },
                "cardNumber": {
                    "Value": "Your customerId ",
                    "color": "#00000"
                },
                "type": {
                    "Value": "Your slab name End Tier",
                    "color": "#00000"
                },
                "address": {
                    "Value": "Your store address mgroad, ropenaagarasjdnf",
                    "color": "#00000"
                },
                "VIPName": {
                    "Value": "Your number ",
                    "color": "#00000"
                },
                "VIPPhone": {
                    "Value": "Your Number ",
                    "color": "#00000"
                },
                "expDate": {
                    "Value": "Your's slab expire date ",
                    "color": "#00000"
                },
                "remark": {
                    "Value": "Additional information provided",
                    "color": "#00000"
                }
            }
        })
        additionalHeaders = {
            "APP_ID":
            "wxc7bf989decc7e35b",
            "APP_SECRET":
            "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ6aG91cGluZyIsImlsIjp0cnVlLCJleHAiOjQ2NjU5ODI3MjksImlhdCI6MTUxMDMwOTEyOTAwOSwianRpIjozfQ.zGgmGaz89ReL1WgeuBj3sdgsHvkbvrXmSvggU-cm4UClnOObAhSlVQwMV9jjJRXkEA6MXjrHLtEFQdJgNQ424Q"
        }
        msgDict = {
            'messageClass': 'WECHAT',
            'sendingOrgId': self.orgId,
            'receiver': receiver,
            'priority': priority,
            'tags': tags,
            'message': message,
            'truncate': False,
            'additionalHeaders': additionalHeaders
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp > 0, 'sendMessage output')
        resp = self.nsObj.getMessagesById([resp])[0]
        Assertion.constructAssertion(
            resp.status in ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status')
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')
예제 #20
0
 def setup_method(self, method):
     self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
     self.nsadminHelper = NSAdminHelper(self.orgId, 'EMAIL')
     self.nsadminHelper.disableDomainPropertiesGatewayMap()
     Logger.logMethodName(method.__name__)
예제 #21
0
class Test_sendEMAIL():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']
        self.cluster = constant.config['cluster']

    def setup_method(self, method):
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, 'EMAIL')
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        Logger.logMethodName(method.__name__)

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'localmail_HIGH'),
                                                   ('BULK', 'localmail_BULK')])
    def test_sendMessage_EMAIL_Sanity(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "message": "test message with priority " + priority
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp > 0, 'sendMessage output')
        resp = self.nsadminHelper.assertWithWaitUntil(
            resp, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    @pytest.mark.parametrize('priority, gateway, status',
                             [('HIGH', 'localmail_HIGH', 'SENT'),
                              ('BULK', 'localmail_BULK', 'GTW_NOT_FOUND')])
    def test_sendMessage_EMAIL_withoutGateway(self, priority, gateway, status):
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "message": "test message with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, [status],
                                               'Messages status ACK', 10)

    @pytest.mark.parametrize(
        'priority, gateway, tags',
        [('HIGH', 'localmail_HIGH', ['transaction', 'otp']),
         ('BULK', 'localmail_BULK', ['campaign'])])
    def test_sendMessage_EMAIL_OrgGateway(self, priority, gateway, tags):
        domainPropertiesId = self.nsadminHelper.addDefaultDomain()
        orgName = constant.config['orgName']
        shortName = orgName + gateway
        connectionProperties = json.dumps({})
        properties = json.dumps({"scopes": tags})
        gatewayOrgConfigs = {
            "orgId": self.orgId,
            "hostName": "localmail",
            "shortName": shortName,
            "fullName": shortName,
            "username": "",
            "password": "",
            "connectionProperties": connectionProperties,
            "serviceIp": "",
            "serviceUrl": "",
            "statusCheckUrl": "",
            "messageClass": "EMAIL",
            "messagePriority": priority,
            "properties": properties
        }
        gatewayOrgConfigs = NSAdminObject.gatewayOrgConfigs(gatewayOrgConfigs)
        domainProperties = self.nsObj.getDomainPropertiesByID(
            domainPropertiesId)
        domainPropertiesGatewayMap = {
            "orgId": self.orgId,
            "subDomain": shortName,
            "gatewayOrgConfigs": gatewayOrgConfigs,
            "domainProperties": domainProperties,
            "domainPropertiesId": domainPropertiesId,
        }
        domainPropertiesGatewayMap = NSAdminObject.domainPropertiesGatewayMap(
            domainPropertiesGatewayMap)
        self.nsObj.saveDomainPropertiesGatewayMap(domainPropertiesGatewayMap)
        self.nsadminHelper.domainGatewayValidate()
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "message": "test message with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == shortName,
                                     'gateway used for sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    def test_sendMultipleMessageEmailWithBulkGateway(self):
        self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
        params = [[
            0, "BULK", "test message 1",
            "autoemail" + randValues.getRandomMobileNumber() + "@gmail.com",
            ['RECEIVED_IN_QUEUE', 'SENT']
        ],
                  [
                      1, "BULK", "test message 2", "autoemail" +
                      randValues.getRandomMobileNumber() + "@gmail.com",
                      ['RECEIVED_IN_QUEUE', 'SENT']
                  ],
                  [
                      2, "HIGH", "test message 3", "autoemail" +
                      randValues.getRandomMobileNumber() + "@gmail.com",
                      ['RECEIVED_IN_QUEUE', 'FAILED']
                  ]]
        self.nsObj.whitelistEmailIds(
            [params[0][3], params[1][3], params[2][3]])
        msgObjList = []
        for p in params:
            msgObj = NSAdminObject.message({
                "messageClass": "EMAIL",
                "inboxId": p[0],
                "priority": p[1],
                "message": p[2],
                "receiver": p[3],
                "body": "test body"
            })
            msgObjList.append(msgObj)
        resp = self.nsObj.sendMultipleMessages(msgObjList)
        for i in range(0, 3):
            msgId = resp[i]
            msgResp = self.nsObj.getMessagesById([msgId])[0]
            #inboxId = msgResp.inboxId
            msgParams = params[i]
            Assertion.constructAssertion(msgResp.status in msgParams[4],
                                         'Messages status')
            Assertion.constructAssertion(msgResp.priority == msgParams[1],
                                         'Messages priority')
            Assertion.constructAssertion(msgResp.message == msgParams[2],
                                         'Message')
            Assertion.constructAssertion(msgResp.receiver == msgParams[3],
                                         'Messages receiver')
            currentMonthTable = NSAdminHelper.getDataTableName()
            query = 'select nsadmin_id from ' + currentMonthTable + ' where nsadmin_id=' + str(
                msgId)
            dbResp = dbHelper.queryDB(query, 'nsadmin')
            Assertion.constructAssertion(dbResp[0][0] == msgId, 'Messages id')

        for p in params:
            msg = self.nsObj.getMessagesByReceiver(self.orgId, p[3])
            Assertion.constructAssertion(msg[0].message == p[2],
                                         'Assert getMessagesByReceiver')

    def test_sendMessage_EMAIL_withHTMLContentAndAttachment(self):
        filePath = constant.rootPath + '/src/modules/nsadmin/html'
        body = FileHelper.readFile(filePath)
        self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "BULK",
            "receiver": "*****@*****.**",
            "message": "test message with html content",
            "body": body,
            "attachmentId": [23303]
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        currentMonthTable = NSAdminHelper.getDataTableName()
        query = 'select attachment_id from ' + currentMonthTable + ' where nsadmin_id=' + str(
            msgId)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] == '23303',
                                     'Messages attachmentId')

    def test_sendMessasge_EMAIL_InvalidReceiver(self):
        self.nsadminHelper.configureGateway("BULK", "localmail_BULK")
        msgDict = {
            "receiver": "invalid",
            "messageClass": "EMAIL",
            "priority": "BULK",
            "message": "test message with receiver invalid"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['BLOCKED'],
                                               'Messages status ACK', 10)

        msgDict = {
            "receiver": "",
            "messageClass": "EMAIL",
            "priority": "BULK",
            "message": "test message with empty receiver"
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp == -1, 'sendMessage output')

        msgDict = {
            "messageClass": "EMAIL",
            "priority": "BULK",
            "message": "test message with empty receiver"
        }
        msgObj = NSAdminObject.message(msgDict)
        resp = self.nsObj.sendMessage(msgObj)
        Assertion.constructAssertion(resp == -1, 'sendMessage output')

    def test_sendMessage_EMAIL_without_Body(self):
        self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "BULK",
            "receiver": "*****@*****.**",
            "message": "test message without body"
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['EMAIL_BODY_EMPTY'],
                                               'Messages status ACK', 10)

    def test_sendMessage_EMAIL_without_Message(self):
        self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "BULK",
            "receiver": "*****@*****.**",
            "body": "test message without message"
        }
        msgObj = NSAdminObject.message(msgDict)
        resp = self.nsObj.sendMessage(msgObj)
        Assertion.constructAssertion(resp == -1, 'sendMessage output')

    def test_sendMessage_EMAIL_ScheduledTime(self):
        self.nsadminHelper.configureGateway('BULK', 'localmail_BULK')
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "BULK",
            "receiver": "*****@*****.**",
            "message": "test body",
            "body": "test message body",
            "scheduledTimestamp": int(time.time() + 600) * 1000
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['DELAYED_SCHEDULED'],
                                               'Messages status ACK', 10)

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'localmail_HIGH'),
                                                   ('BULK', 'localmail_BULK')])
    def test_sendMessage_EMAIL_HardSoftBounce_AfterWhitelisting(
            self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        emailH = "*****@*****.**"
        emailS = "*****@*****.**"
        self.nsObj.whitelistEmailIds([emailH, emailS])
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "receiver": emailH,
            "message": "test body",
            "body": "test message body",
            "tags": ["hb"]
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)

        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "receiver": emailS,
            "message": "test body",
            "body": "test message body",
            "tags": ["sb"]
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'localmail_HIGH'),
                                                   ('BULK', 'localmail_BULK')])
    def test_sendMessage_EMAIL_withSoftBounce_lastFailedOnMoreThanMonth(
            self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "receiver": "*****@*****.**",
            "message": "test body",
            "body": "test message body",
            "tags": ["sb"]
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'localmail_HIGH'),
                                                   ('BULK', 'localmail_BULK')])
    def test_sendMessage_EMAIL_ValidSender(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            'sender': '*****@*****.**',
            "message": "test message with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        currentMonthTable = NSAdminHelper.getDataTableName()
        query = 'select sender from ' + currentMonthTable + ' where nsadmin_id=' + str(
            msgId)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] == '*****@*****.**', 'sender')

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'localmail_HIGH'),
                                                   ('BULK', 'localmail_BULK')])
    def test_sendMessage_EMAIL_InvalidSender(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            'sender': '',
            "message": "test message with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.sender != '', 'sender is not empty')
        # msgObj without sender
        msgObj = {
            'inboxId': 1,
            'messageId': 1,
            'clientId': 111,
            'receiverId': 111,
            'campaignId': 222,
            'sendingOrgId': self.orgId,
            'messageClass': 'EMAIL',
            'receiver': '*****@*****.**',
            'priority': priority,
            'message': 'test message with priority ' + priority,
            'scheduledTimestamp': int(time.time()) * 1000,
            'body': 'test body'
        }
        msgObj = nsadmin.Message(**msgObj)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
        Assertion.constructAssertion(resp.sender != '', 'sender is not empty')

    @pytest.mark.parametrize(
        'priority, gateway, status',
        [('HIGH', 'localmail_HIGH', ['RECEIVED_IN_QUEUE', 'SENT']),
         ('BULK', 'localmail_BULK', ['GTW_NOT_FOUND', 'BLOCKED'])])
    def test_sendMessage_EMAIL_WhitelistStatus_UNKNOWN_INVALID(
            self, priority, gateway, status):
        # without gateway
        self.nsadminHelper.resetUnknowInvalidEmails()
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            'receiver': '*****@*****.**',
            "message": "test message unknown_email with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(msgId, status,
                                                      'Messages status ACK',
                                                      10)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            'receiver': '*****@*****.**',
            "message": "test message invalid_email with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(msgId, status,
                                                      'Messages status ACK',
                                                      10)

        # with gateway
        self.nsadminHelper.resetUnknowInvalidEmails()
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            'receiver': '*****@*****.**',
            "message": "test message unknown_email with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(msgId, status,
                                                      'Messages status ACK',
                                                      10)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            'receiver': '*****@*****.**',
            "message": "test message invalid_email with priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(msgId, status,
                                                      'Messages status ACK',
                                                      10)

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'sendgridmail'),
                                                   ('BULK', 'localmail_BULK')])
    def test_sendMessage_EMAIL_India_More_Eu_Prod_Sanity(
            self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "receiver": constant.config['prodEmail1'],
            "message":
            "test message for " + self.cluster + " cluster " + priority,
            "body": "test body"
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)

    def test_sendMultipleMessageEmail_India_More_Prod_Sanity(self):
        if self.cluster == 'india':
            self.nsadminHelper.configureGateway('BULK', 'sendgridmail_BULK')
        else:
            self.nsadminHelper.configureGateway('BULK', 'sendgridapac2_BULK')
        params = [[
            0, "BULK", "test message 1 for " + self.cluster,
            constant.config['prodEmail1'], ['RECEIVED_IN_QUEUE', 'SENT']
        ],
                  [
                      1, "BULK", "test message 2 for " + self.cluster,
                      constant.config['prodEmail1'],
                      ['RECEIVED_IN_QUEUE', 'SENT']
                  ]]
        msgObjList = []
        for p in params:
            msgObj = NSAdminObject.message({
                "messageClass": "EMAIL",
                "inboxId": p[0],
                "priority": p[1],
                "message": p[2],
                "receiver": p[3],
                "body": "test body"
            })
            msgObjList.append(msgObj)
        resp = self.nsObj.sendMultipleMessages(msgObjList)
        for i in range(0, 2):
            msgId = resp[i]
            msgResp = self.nsObj.getMessagesById([msgId])[0]
            msgParams = params[i]
            Assertion.constructAssertion(msgResp.status in msgParams[4],
                                         'Messages status')
            Assertion.constructAssertion(msgResp.priority == msgParams[1],
                                         'Messages priority')
            Assertion.constructAssertion(msgResp.message == msgParams[2],
                                         'Message')
            Assertion.constructAssertion(msgResp.receiver == msgParams[3],
                                         'Messages receiver')

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'sendgridcn'),
                              ('BULK', 'sendgridcn_BULK')])
    def test_sendMessage_EMAIL_China_Prod_Sanity(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "receiver": constant.config['prodEmail1'],
            "message": "test message for China cluster " + priority,
            "body": "test body"
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
예제 #22
0
파일: test_SMS.py 프로젝트: anupsl/pyApps
class Test_sendMessage_SMS():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = 1604  #constant.config['orgId']
        self.cluster = constant.config['cluster']

    def setup_method(self, method):
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, 'SMS')
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        Logger.logMethodName(method.__name__)

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def test_sendMessage_SMS_Sanity(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message with priority " + priority
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp > 0, 'sendMessage output')
        resp = self.nsadminHelper.assertWithWaitUntil(
            resp, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    def test_sendMessage_DefaultPriority(self):
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock")
        msgDict = {
            "messageClass": "SMS",
            "priority": "DEFAULT",
            "message": "test message with priority DEFAULT"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == "cardboardfishmock",
                                     'gateway used for sending')
        Assertion.constructAssertion(resp.priority == "HIGH", 'priority')

    @pytest.mark.parametrize('priority', [('HIGH'), ('BULK')])
    def test_sendMessage_withoutGateway(self, priority):
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message without gateway priority " + priority
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)
        resp = self.nsObj.getMessageSendError(msgId)
        Assertion.constructAssertion("no configs for" in resp,
                                     'Error message without gateway')

    def test_sendMessasge_SMS_InvalidReceiver(self):
        self.nsadminHelper.configureGateway("BULK", "valuefirstmock")
        msgDict = {
            "receiver": "invalid",
            "messageClass": "SMS",
            "priority": "BULK",
            "message": "test message with receiver invalid"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)
        resp = self.nsObj.getMessageSendError(msgId)
        Assertion.constructAssertion("no gw found after checking" in resp,
                                     'Error message without gateway')

        msgDict = {
            "receiver": "",
            "messageClass": "SMS",
            "priority": "BULK",
            "message": "test message with empty receiver"
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp == -1, 'sendMessage output')

        msgDict = {
            "messageClass": "SMS",
            "priority": "BULK",
            "message": "test message with empty receiver"
        }
        msgObj = NSAdminObject.message(msgDict)
        resp = self.nsObj.sendMessage(msgObj)
        Assertion.constructAssertion(resp == -1, 'sendMessage output')

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def test_sendMessage_delayScheduledMessage(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        scheduledTimestamp = int(time.time() + 180) * 1000  # 2 mins delay
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "scheduledTimestamp": scheduledTimestamp,
            "message": "test message with delayed schedule"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['DELAYED_SCHEDULED'],
                                               'Messages status', 10)
        Utils.sleep(180)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['READ', 'RECEIVED_IN_QUEUE', 'SENT'],
            'Messages status after delay', 10)

    def test_sendMultipleMessage(self):
        self.nsadminHelper.configureGateway('HIGH', 'cardboardfishmock')
        self.nsadminHelper.configureGateway('BULK', 'valuefirstmock')
        mobile1 = randValues.getRandomMobileNumber()
        mobile2 = randValues.getRandomMobileNumber()
        mobile3 = randValues.getRandomMobileNumber()
        params = [[0, "BULK", "test message 1", mobile1],
                  [1, "BULK", "test message 2", mobile2],
                  [2, "HIGH", "test message 3", mobile3]]
        msgObjList = []
        for p in params:
            msgObj = NSAdminObject.message({
                "messageClass": "SMS",
                "inboxId": p[0],
                "priority": p[1],
                "message": p[2],
                "receiver": p[3]
            })
            msgObjList.append(msgObj)
        resp = self.nsObj.sendMultipleMessages(msgObjList)
        for i in range(0, 3):
            msgId = resp[i]
            msgResp = self.nsObj.getMessagesById([msgId])[0]
            #inboxId = msgResp.inboxId
            msgParams = params[i]
            Assertion.constructAssertion(
                msgResp.status in ['RECEIVED_IN_QUEUE', 'SENT'],
                'Messages status')
            Assertion.constructAssertion(msgResp.priority == msgParams[1],
                                         'Messages priority')
            Assertion.constructAssertion(msgResp.message == msgParams[2],
                                         'Message')
            Assertion.constructAssertion(msgResp.receiver == msgParams[3],
                                         'Messages receiver')
        msg1 = self.nsObj.getMessagesByReceiver(self.orgId, mobile1)[0]
        msg2 = self.nsObj.getMessagesByReceiver(self.orgId, mobile2)[0]
        Assertion.constructAssertion(msg1.message == 'test message 1',
                                     'getMessagesByReceiver Message')
        Assertion.constructAssertion(msg2.message == 'test message 2',
                                     'getMessagesByReceiver Message')

    def test_sendMultipleMessageWithBulkGateway(self):
        self.nsadminHelper.configureGateway('BULK', 'valuefirstmock')
        params = [
            [
                0, "BULK", "test message 1",
                randValues.getRandomMobileNumber(),
                ['RECEIVED_IN_QUEUE', 'SENT']
            ],
            #[1, "BULK",  "test message 2", randValues.getRandomMobileNumber(), ['RECEIVED_IN_QUEUE', 'SENT']],
            #[2, "HIGH",  "test message 3", randValues.getRandomMobileNumber(), ['GTW_NOT_FOUND']]
        ]
        msgObjList = []
        for p in params:
            msgObj = NSAdminObject.message({
                "messageClass": "SMS",
                "inboxId": p[0],
                "priority": p[1],
                "message": p[2],
                "receiver": p[3]
            })
            msgObjList.append(msgObj)
        resp = self.nsObj.sendMultipleMessages(msgObjList)
        for i in range(0, 3):
            msgId = resp[i]
            msgResp = self.nsObj.getMessagesById([msgId])[0]
            #inboxId = msgResp.inboxId
            msgParams = params[i]
            Assertion.constructAssertion(msgResp.status in msgParams[4],
                                         'Messages status')
            Assertion.constructAssertion(msgResp.priority == msgParams[1],
                                         'Messages priority')
            Assertion.constructAssertion(msgResp.message == msgParams[2],
                                         'Message')
            Assertion.constructAssertion(msgResp.receiver == msgParams[3],
                                         'Messages receiver')

    def test_SMScharLimit(self):
        self.nsadminHelper.configureGateway('HIGH', 'cardboardfishmock')
        message160CharSize = "At Capillary, we continuously work to help our clients succeed in rapidly evolving markets through our world-class solutions, services and products -  combining"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": message160CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(resp[0][2] == message160CharSize,
                                     '160 Char limit')
        Assertion.constructAssertion(resp[0][1] == 1, 'Message count')

        message320CharSize = "At Capillary, we continuously work to help our clients succeed in rapidly evolving markets through our world-class solutions, services and products. By combining big data with a robust, cloud-based analytics engine, we optimize the relevance and profitability of discounts and personalized offers to consumers in real time, significantly increasing both loyalty and sales"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": message320CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(resp[0][1] == 1,
                                     'Message count without truncate')

        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "truncate": False,
            "message": message320CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(resp[0][2] == message320CharSize,
                                     '320 Char limit')
        Assertion.constructAssertion(resp[0][1] == 3, 'Message count')

    def test_SMSCharUTF8(self):
        self.nsadminHelper.configureGateway('HIGH', 'cardboardfishmock')
        messageArabic = "في شعري ، ونحن نعملمجمو باستمرار لمساعدة العملاء على تحقيق النجاح في الأسواق المتطورة بسرعة من خلال حلول عالمية"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "truncate": False,
            "message": messageArabic
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(
            resp[0][2].encode('utf8') == messageArabic, 'Arabic Char')
        Assertion.constructAssertion(resp[0][1] == 2, 'Message count')

        messageChinese = "在毛細管中,我們不斷努力,以幫助我們的客戶通過我們的世界級解決方案,服務和產品成功在快速發展的市場 - 將合併在毛細管中,我們不斷努力,以以- 將合併在毛細管中,我們不斷努力,以以"
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "truncate": False,
            "message": messageChinese
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        currentMonthTable = NSAdminHelper.getTableName()
        query = 'select status, message_count, message from ' + currentMonthTable + ' where id=' + str(
            resp)
        resp = dbHelper.queryDB(query, 'nsadmin')
        Assertion.constructAssertion(resp[0][0] in [7, 35], 'Messages status')
        Assertion.constructAssertion(
            resp[0][2].encode('utf8') == messageChinese, 'Chinese Char')
        Assertion.constructAssertion(resp[0][1] == 2, 'Message count')

    @pytest.mark.parametrize('mobileNumber',
                             [('917976762433'),
                              (randValues.getRandomMobileNumber())])
    def est_ratelimit(
        self, mobileNumber
    ):  # Same number if used will timeout within 24hrs # to be fixed
        self.nsadminHelper.configureGateway('BULK', 'valuefirstmock')
        msgObjList = []
        for i in range(1, 10):
            msgObj = NSAdminObject.message({
                "messageClass": "SMS",
                "inboxId": i,
                "clientId": 113,
                "priority": "BULK",
                "message": "test message " + str(i),
                "receiver": mobileNumber
            })
            msgObjList.append(msgObj)
        self.nsObj.sendMultipleMessages(msgObjList)
        msgObj = NSAdminObject.message({
            "messageClass": "SMS",
            "inboxId": 10,
            "clientId": 113,
            "priority": "BULK",
            "message": "test message 10",
            "receiver": mobileNumber
        })
        nsadminId = self.nsObj.sendMessage(msgObj)
        resp = self.nsadminHelper.waitUntil(nsadminId, ['SENT'])
        if resp:
            Assertion.constructAssertion(resp.requestId != '',
                                         'msg_ref_id is not generated')
        else:
            Assertion.constructAssertion(False, 'Failed to get status SENT')
        msgObj = NSAdminObject.message({
            "messageClass": "SMS",
            "inboxId": 11,
            "clientId": 113,
            "priority": "BULK",
            "message": "test message 11",
            "receiver": mobileNumber
        })
        nsadminId = self.nsObj.sendMessage(msgObj)
        resp = self.nsadminHelper.waitUntil(nsadminId, ['RATE_LIMIT_EXCEEDED'])
        if resp:
            Assertion.constructAssertion(resp.requestId == '',
                                         'msg_ref_id is generated')
        else:
            Assertion.constructAssertion(
                False, 'Failed to get status RATE_LIMIT_EXCEEDED')

    def test_getMessagesByUserOrReciever(self):
        mobile = randValues.getRandomMobileNumber()
        testMessage = "test message new"
        msgObj = NSAdminObject.message({
            "messageClass": "SMS",
            "inboxId": 1,
            "priority": "BULK",
            "message": testMessage,
            "receiver": mobile
        })
        nsadminId = self.nsObj.sendMessage(msgObj)
        resp = self.nsObj.getMessagesByReceiver(self.orgId, mobile)
        Assertion.constructAssertion(resp[0].message == testMessage,
                                     'getMessagesByReceiver response')
        resp = self.nsObj.getMessagesByUserOrReciever(self.orgId, '', mobile)
        Assertion.constructAssertion(resp[0].message == testMessage,
                                     'getMessagesByUserOrReciever response')

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def test_sendMessage_with_DomainGatewayMapID(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        dpgmId = self.nsadminHelper.getDomainGatewayMapId(gateway)
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message with priority " + priority,
            "additionalHeaders": {
                "domain_gateway_map_id": str(dpgmId)
            }
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def test_sendMessage_with_InvalidDomainGatewayMapID(
            self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        dpgmId = self.nsadminHelper.getDomainGatewayMapId(gateway)
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message with priority " + priority,
            "additionalHeaders": {
                "domain_gateway_map_id": "1"
            }
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def test_sendMessage_with_DomainID(self, priority, gateway):
        domainId = self.nsadminHelper.addDefaultDomain()
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message with priority " + priority,
            "additionalHeaders": {
                "domain_prop_id": str(domainId)
            }
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def test_sendMessage_with_InvalidDomainID(self, priority, gateway):
        domainId = self.nsadminHelper.addDefaultDomain()
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "message": "test message with priority " + priority,
            "additionalHeaders": {
                "domain_prop_id": "1"
            }
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    @pytest.mark.parametrize(
        'priority, gateway, status',
        [('HIGH', 'cardboardfishmock', ['RECEIVED_IN_QUEUE', 'SENT']),
         ('BULK', 'valuefirstmock', ['MOBILE_WHITELISTED_BLOCKED'])])
    def test_sendMessage_smsWhitelisting(self, priority, gateway, status):
        mobile = '919980142462'
        last_failed_on = datetime.now()
        DarknightHelper.getMongoConnection('whitelisting', 'mobile_status')
        domainId = self.nsadminHelper.addDefaultDomain()
        DarknightHelper.generateSmsWhitelistingData(
            {
                'not_delivered':
                4,
                'last_failed_on':
                last_failed_on,
                "monthly_stats": [{
                    "year": last_failed_on.year,
                    "month": last_failed_on.month,
                    "not_delivered": 4,
                    "total": 4
                }]
            }, mobile)
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "SMS",
            'receiver': mobile,
            "priority": priority,
            "message": "test message with is_whitelisting_enabled " + priority,
            "additionalHeaders": {
                "is_whitelisting_enabled": "true"
            }
        }
        msgId1 = self.nsadminHelper.createAndSendMessage(msgDict)
        msgDict = {
            "messageClass": "SMS",
            'receiver': mobile,
            "priority": priority,
            "message":
            "test message with is_whitelisting_enabled false" + priority,
            "additionalHeaders": {
                "is_whitelisting_enabled": "false"
            }
        }
        msgId2 = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId1, status,
                                               'Messages status ACK', 10)
        self.nsadminHelper.assertWithWaitUntil(msgId2,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)

    #### Prod ###
    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'solutionsinfinitrans'),
                              ('BULK', 'solutionsinfinibulk_BULK')])
    def test_sendMessage_SMS_UseSystemDefaultsGateway_India_More_Prod_Sanity(
            self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass":
            "SMS",
            "receiver":
            constant.config['prodMobile1'],
            "priority":
            priority,
            "message":
            "test message priority " + priority + " cluster:" + self.cluster
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == gateway,
                                     'gateway used for sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    @pytest.mark.parametrize(
        'priority, gateway, username, tags',
        [('HIGH', 'puxuntrans', '7171', ['transaction', 'otp']),
         ('BULK', 'puxunbulk', '7174', ['campaign'])])
    def test_sendMessage_SMS_China_Prod_Sanity(self, priority, gateway,
                                               username, tags):
        domainPropertiesId = self.nsadminHelper.addDefaultDomain()
        orgName = constant.config['orgName']
        shortName = orgName + gateway
        connectionProperties = json.dumps({
            "account":
            username,
            "apiKey":
            "203dfd2c4eb6f8eed0889bef5d7aa646",
            "factory":
            gateway,
            "dlrUrl":
            constant.config['dlrUrl'] + gateway
        })
        properties = json.dumps({"scopes": tags, "countries": ["86"]})
        gatewayOrgConfigs = {
            "orgId": self.orgId,
            "hostName": gateway,
            "shortName": shortName,
            "fullName": shortName,
            "username": username,
            "password": "******",
            "connectionProperties": connectionProperties,
            "serviceIp": "",
            "serviceUrl": "http://202.91.244.252:30001/yqx/v1/sms/multi_send",
            "statusCheckUrl":
            "http://202.91.244.252:30001/yqx/v1/sms/multi_send",
            "messageClass": "SMS",
            "messagePriority": priority,
            "properties": properties
        }
        gatewayOrgConfigs = NSAdminObject.gatewayOrgConfigs(gatewayOrgConfigs)
        domainProperties = self.nsObj.getDomainPropertiesByID(
            domainPropertiesId)
        domainPropertiesGatewayMap = {
            "orgId": self.orgId,
            "subDomain": shortName,
            "gatewayOrgConfigs": gatewayOrgConfigs,
            "domainProperties": domainProperties,
            "domainPropertiesId": domainPropertiesId,
        }
        domainPropertiesGatewayMap = NSAdminObject.domainPropertiesGatewayMap(
            domainPropertiesGatewayMap)
        self.nsObj.saveDomainPropertiesGatewayMap(domainPropertiesGatewayMap)
        self.nsadminHelper.domainGatewayValidate()
        msgDict = {
            "messageClass":
            "SMS",
            "receiver":
            constant.config['prodMobile3'],
            "priority":
            priority,
            "message":
            "test message priority " + priority + " cluster:" + self.cluster
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT', 'DELIVERED'],
            'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == shortName,
                                     'gateway used for sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')

    @pytest.mark.parametrize(
        'priority, gateway ,tags',
        [('HIGH', 'solutionsinfiniTrans', ['transaction', 'otp']),
         ('BULK', 'solutionsinfiniBulk', ['campaign'])])
    def test_sendMessage_SMS_Eu_Prod_Sanity(self, priority, gateway, tags):
        domainPropertiesId = self.nsadminHelper.addDefaultDomain()
        orgName = constant.config['orgName']
        shortName = orgName + gateway
        connectionProperties = json.dumps(
            {"dlrUrl": constant.config['dlrUrl'] + 'solutionsinfini'})
        properties = json.dumps({"scopes": tags, "countries": ["44"]})
        gatewayOrgConfigs = {
            "orgId": self.orgId,
            "hostName": "solutionsinfini",
            "shortName": shortName,
            "fullName": shortName,
            "username": "******",
            "password": "******",
            "connectionProperties": connectionProperties,
            "serviceIp": "",
            "serviceUrl": "http://global.sinfini.com/api/v0/xmlapi.php",
            "statusCheckUrl": "http://global.sinfini.com/api/v0/xmlapi.php",
            "messageClass": "SMS",
            "messagePriority": priority,
            "properties": properties
        }
        gatewayOrgConfigs = NSAdminObject.gatewayOrgConfigs(gatewayOrgConfigs)
        domainProperties = self.nsObj.getDomainPropertiesByID(
            domainPropertiesId)
        domainPropertiesGatewayMap = {
            "orgId": self.orgId,
            "subDomain": shortName,
            "gatewayOrgConfigs": gatewayOrgConfigs,
            "domainProperties": domainProperties,
            "domainPropertiesId": domainPropertiesId,
        }
        domainPropertiesGatewayMap = NSAdminObject.domainPropertiesGatewayMap(
            domainPropertiesGatewayMap)
        self.nsObj.saveDomainPropertiesGatewayMap(domainPropertiesGatewayMap)
        self.nsadminHelper.domainGatewayValidate()
        msgDict = {
            "messageClass":
            "SMS",
            "receiver":
            constant.config['prodMobile4'],
            "priority":
            priority,
            "message":
            "test message priority " + priority + " cluster:" + self.cluster
        }
        msgObj = NSAdminObject.message(msgDict)
        msgId = self.nsObj.sendMessage(msgObj)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT', 'DELIVERED'],
            'Messages status', 10)
        Assertion.constructAssertion(resp.gateway == shortName,
                                     'gateway used for sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')
예제 #23
0
class Test_DomainProperties():

    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']
        self.cluster = constant.config['cluster']

    def setup_method(self, method):      
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, 'SMS')
        self.nsadminHelper.disableDomainPropertiesGatewayMap()        
        Logger.logMethodName(method.__name__)


    @pytest.mark.parametrize('priority, gateway', [
                    ('HIGH', 'cardboardfishmock'),
                    ('BULK', 'valuefirstmock')])        
    def test_sendMessage_SMS_UseSystemDefaultsGateway_Sanity(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {"messageClass" : "SMS", "priority" : priority, "message" : "test message with priority "+priority}
        resp  = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp > 0, 'sendMessage output')
        resp = self.nsObj.getMessagesById([resp])[0]
        Assertion.constructAssertion(resp.status in ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status')
        Assertion.constructAssertion(resp.gateway == gateway, 'gateway used for  sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')


    def test_getDomainPropertiesByOrg_And_ID(self):
        resp = self.nsObj.getDomainPropertiesByOrg(self.orgId)[0]
        Assertion.constructAssertion(resp.orgId == self.orgId, 'orgId')
        dpgmID = resp.id 
        resp = self.nsObj.getDomainPropertiesByID(dpgmID)
        Assertion.constructAssertion(resp.orgId == self.orgId, 'orgId')


    def test_getDomainPropertiesGatewayMapByOrg_AND_ID(self):
        self.nsadminHelper.configureGateway("BULK", "valuefirstmock")
        resp = self.nsObj.getDomainPropertiesGatewayMapByOrg(self.orgId, 0)[0]
        Assertion.constructAssertion(resp.orgId == self.orgId, 'orgId')
        Assertion.constructAssertion(resp.gatewayOrgConfigs.shortName == 'valuefirstmock', 'gateway shortName')
        dpgmId = resp.id
        resp = self.nsObj.getDomainPropertiesGatewayMapByID(dpgmId)
        Assertion.constructAssertion(resp.orgId == self.orgId, 'orgId')
        Assertion.constructAssertion(resp.gatewayOrgConfigs.shortName == 'valuefirstmock', 'gateway shortName')



    @pytest.mark.parametrize('priority, gateway, tags', [
                    ('HIGH', 'cardboardfishmock', ['transaction', 'otp']),
                    ('BULK', 'valuefirstmock', ['campaign'])])
    def test_Create_And_Disable_DomainGatewayMap(self, priority, gateway, tags):
        dpgmID = self.nsadminHelper.configureGateway(priority, gateway, False, tags)
        dObj = self.nsObj.getDomainPropertiesGatewayMapByID(dpgmID)
        msgDict = {"messageClass" : "SMS", "priority" : priority, "message" : "test message with priority "+priority}
        resp  = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp > 0, 'sendMessage output')
        resp = self.nsObj.getMessagesById([resp])[0]
        Assertion.constructAssertion(resp.status in ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status')
        Assertion.constructAssertion(resp.gateway == dObj.gatewayOrgConfigs.shortName, 'gateway used for sending')
        Assertion.constructAssertion(resp.priority == priority, 'priority')  
        dpgmId = self.nsadminHelper.getDomainGatewayMapId(dObj.gatewayOrgConfigs.shortName)
        self.nsObj.disableDomainPropertiesGatewayMap(dpgmId)
        resp  = self.nsadminHelper.createAndSendMessage(msgDict)
        Assertion.constructAssertion(resp > 0, 'sendMessage output')
        resp = self.nsObj.getMessagesById([resp])[0]
        Assertion.constructAssertion(resp.status in ['GTW_NOT_FOUND'], 'Messages status')


    def test_Create_And_Disable_Domain(self):
        contactInfoList = self.nsadminHelper.getDefaultContactInfo('SMS')
        domainName = str(randValues.getRandomMobileNumber())+'_SMS_'+str(self.orgId)
        DomainProperties = {
            'orgId' : self.orgId,
            'domainName' : domainName,
            'description' : domainName,
            'contactInfo' : contactInfoList
        }      
        DomainProperties = NSAdminObject.domainProperties(DomainProperties)
        self.nsObj.insertDomainProperties(DomainProperties)
        domainPropertiesList = self.nsObj.getDomainPropertiesByOrg(self.orgId)
        for k in domainPropertiesList:
            if domainName == k.domainName and len(k.contactInfo) != 0:
                domainID = k.id
                contactInfoId0 = k.contactInfo[0].id
                contactInfoId1 = k.contactInfo[1].id
                break
        DomainProperties.contactInfo[0].value = '919845012346'
        DomainProperties.contactInfo[0].id = contactInfoId0
        DomainProperties.contactInfo[0].domainPropId = domainID
        DomainProperties.contactInfo[1].id = contactInfoId1  
        DomainProperties.contactInfo[1].domainPropId = domainID
        DomainProperties.id = domainID
        self.nsObj.updateDomainProperties(DomainProperties)          
        updatedDP = self.nsObj.getDomainPropertiesByID(domainID)
        Assertion.constructAssertion(updatedDP.contactInfo[0].value == '919845012346', 'updated value')
        self.nsObj.disableDomainProperties(domainID, self.orgId)
        deletedDP = self.nsObj.getDomainPropertiesByID(domainID)          
        Assertion.constructAssertion(deletedDP.domainName == None, 'Diasbled domain')            
예제 #24
0
파일: irisHelper.py 프로젝트: anupsl/pyApps
 def disableDomainGatewayMapId(channel):
     messageClass = 'SMS' if channel.lower() in ['mobile','sms'] else channel
     nsObj = NSAdminHelper.getConnObj(newConnection=True)
     nsadminHelper = NSAdminHelper(constant.config['orgId'], messageClass)
     nsadminHelper.disableDomainPropertiesGatewayMap()
예제 #25
0
파일: irisHelper.py 프로젝트: anupsl/pyApps
 def logCurrentCredit(messageClass):
     nsObj = NSAdminHelper.getConnObj(newConnection=True)
     currVal = nsObj.getCreditDetailsByOrgAndChannel(constant.config['orgId'], messageClass,
                                                     'test_{}'.format(int(time.time())))
     Logger.log('Current Credit :{}'.format(currVal.bulkCredits))
     return int(currVal.bulkCredits)
예제 #26
0
 def test_Count_Messages_DELAYED_SCHEDULED(self):
     currentMonth = NSAdminHelper.getTableName()
     query = 'SELECT COUNT( * ) FROM ' + currentMonth + ' where sent_time >= SUBDATE( current_date, 2) and sent_time < current_date and status in (33)'
     output = dbHelper.queryDB(query, 'nsadmin')
     Assertion.constructAssertion(output[0][0] == 0,
                                  'DELAYED_SCHEDULED count')
예제 #27
0
class Test_TagGateway():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']
        self.cluster = constant.config['cluster']

    def setup_method(self, method):
        messageClass = 'SMS'
        if 'EMAIL' in method.__name__:
            messageClass = 'EMAIL'
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, messageClass)
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        Logger.logMethodName(method.__name__)

    def test_sendMessage_SMS_HIGH_NoGateway(self):
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    def test_sendMessage_SMS_HIGH_DefaultNoTagGateway(self):
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock")
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    def test_sendMessage_SMS_HIGH_DefaultAndTagGateway(self):
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock")
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock", False,
                                            ["otp"])
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(
            resp.gateway == constant.config['orgName'] + "cardboardfishmock",
            'Messages gateway')

    def test_sendMessage_SMS_HIGH_DefaultAndMultipleTagGateway(self):
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock")
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock1",
                                            False, ["otp"], {}, 2)
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock2",
                                            False, ["otp"], {}, 3)
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock3",
                                            False, ["otp"], {}, 4)
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(
            resp.gateway == constant.config['orgName'] + "cardboardfishmock1",
            'Messages gateway')

    def test_sendMessage_SMS_HIGH_ExpiredTagGateway(self):
        self.nsadminHelper.configureGateway(
            "HIGH", "cardboardfishmock", False, ["otp"], {
                "startTimestamp": int(time.time() - 18000) * 1000,
                "endTimestamp": int(time.time() + 5) * 1000
            })
        time.sleep(5)
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    def test_sendMessage_SMS_HIGH_DifferentTag(self):
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock", False,
                                            ["otp"])
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message No gateway",
            "tags": ["highvolttrans"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    def test_sendMessage_EMAIL_HIGH_NoTagGateways(
            self):  # Should fall back to Capillary org Gateway
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "HIGH",
            "body": "test body",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == "localmail_HIGH",
                                     'Messages gateway')

    def test_sendMessage_Email_HIGH_DefaultAndTagGateway(
            self):  # Will go from Default gateway. Tag no effect in EMAIL
        self.nsadminHelper.configureGateway("HIGH", "localmail_HIGH")
        self.nsadminHelper.configureGateway("HIGH", "localmail_HIGH2", False,
                                            ["otp"])
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "HIGH",
            "body": "test body",
            "message": "test message No gateway",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == "localmail_HIGH",
                                     'Messages gateway')

    ## capillary tag
    @pytest.mark.parametrize(
        'priority, gateway, tags',
        [('HIGH', 'cardboardfishmock', ["capillary", "otp"]),
         ('BULK', 'valuefirstmock', ["capillary", "campaigns"])])
    def test_sendMessage_SMS_NoGateways_withCapillaryMsgTag(
            self, priority, gateway,
            tags):  # Should not fall back to Capillary org Gateway
        self.nsadminHelper.configureGateway(priority, gateway)
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "tags": tags,
            "message": "test message without tag gateway with capillary tag"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    def test_sendMessage_SMS_HIGH_CapillaryTag(self):
        self.nsadminHelper.configureGateway("HIGH", "cardboardfishmock1",
                                            False, ["capillary"], {}, 1)
        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message capillary tag",
            "tags": ["otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

        msgDict = {
            "messageClass": "SMS",
            "priority": "HIGH",
            "message": "test message and gateway with capillary tag",
            "tags": ["capillary"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)

    @pytest.mark.parametrize('priority, tags',
                             [('HIGH', ["capillary", "report"]),
                              ('BULK', ["capillary", "campaigns"])])
    def test_sendMessage_EMAIL_NoGateways_withCapillaryMsgTag(
            self, priority,
            tags):  # Should not fall back to Capillary org Gateway
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "body": "test body",
            "message": "test message No gateway",
            "tags": tags
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)

    @pytest.mark.parametrize(
        'priority, gateway, tags',
        [('HIGH', 'localmail_HIGH', ["capillary", "otp"]),
         ('BULK', 'localmail_BULK', ["capillary", "campaigns"])])
    def test_sendMessage_EMAIL_DefaultAndCapillaryTagGateway(
            self, priority, gateway,
            tags):  # Will go from capillary tag gateway.
        self.nsadminHelper.configureGateway(priority, gateway)
        self.nsadminHelper.configureGateway(priority, gateway + '_2', False,
                                            tags)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "body": "test body",
            "message": "test message No gateway",
            "tags": tags
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(gateway + '_2' in resp.gateway,
                                     'Messages gateway')

    @pytest.mark.parametrize(
        'priority, gateway, tags',
        [('HIGH', 'localmail_HIGH', ["capillary", "otp123"]),
         ('BULK', 'localmail_BULK', ["capillary", "campaigns123"])])
    def test_sendMessage_EMAIL_RandomTagDefaultAndCapillaryTagGateway(
            self, priority, gateway,
            tags):  # Will go from capillary tag gateway.
        self.nsadminHelper.configureGateway(priority, gateway)
        self.nsadminHelper.configureGateway(priority, gateway + '_2', False,
                                            tags)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "body": "test body",
            "message": "test message No gateway",
            "tags": tags
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(gateway + '_2' in resp.gateway,
                                     'Messages gateway')

    @pytest.mark.parametrize('priority, gateway, tags, msgTag', [
        ('HIGH', 'localmail_HIGH', ["capillary", "otp"], ["otp"]),
        ('BULK', 'localmail_BULK', ["capillary", "campaigns"], ["campaigns"])
    ])
    def test_sendMessage_EMAIL_OTPFromCapillaryTagGateway(
            self, priority, gateway, tags,
            msgTag):  # send regular messages from capillary tag gateway.
        self.nsadminHelper.configureGateway(priority, gateway + '_2', False,
                                            tags)
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "body": "test body",
            "message": "test message No gateway",
            "tags": msgTag
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(gateway + '_2' in resp.gateway,
                                     'Messages gateway')

    def test_sendMessage_EMAIL_HIGH_DefaultAndFallbackTagGateway(
            self):  # should fallback to Org 0 tag gateway
        self.nsadminHelper.configureGateway("HIGH", "localmail_HIGH")
        self.nsadminHelper.configureGateway("HIGH", "localmail_HIGH2", False,
                                            ["capillary", "report"])
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "HIGH",
            "body": "test body",
            "message": "test message No gateway",
            "tags": ["capillary", "otp"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        resp = self.nsadminHelper.assertWithWaitUntil(
            msgId, ['RECEIVED_IN_QUEUE', 'SENT'], 'Messages status ACK', 10)
        Assertion.constructAssertion(resp.gateway == "localmail_HIGH_OTP",
                                     'Messages gateway')

    def test_sendMessage_EMAIL_BULK_DefaultAndFallbackTagGateway(
            self):  # should not fallback to Org 0
        self.nsadminHelper.configureGateway("BULK", "localmail_BULK")
        self.nsadminHelper.configureGateway("BULK", "localmail_BULK2", False,
                                            ["capillary", "otp"])
        msgDict = {
            "messageClass": "EMAIL",
            "priority": "BULK",
            "body": "test body",
            "message": "test message No gateway",
            "tags": ["capillary", "report"]
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId, ['GTW_NOT_FOUND'],
                                               'Messages status', 10)
예제 #28
0
 def setup_method(self, method):
     self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
     self.nsadminHelper = NSAdminHelper(constant.config['orgId'], 'SMS')
     Logger.logMethodName(method.__name__)
예제 #29
0
class Test_DeliveryReceipt_EMAIL():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']
        self.cluster = constant.config['cluster']
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.nsadminHelper = NSAdminHelper(self.orgId, 'EMAIL')
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        self.nsadminHelper.configureGateway('HIGH', 'sendgrid_HIGH')
        self.nsadminHelper.configureGateway('BULK', 'sendgrid_BULK')
        self.DR = DeliveryReceipt()
        self.msgDict = {
            "messageClass": "EMAIL",
            "priority": 'HIGH',
            "message": "test message for DLR"
        }

    def setup_method(self, method):
        Logger.logMethodName(method.__name__)

    def getSendGridPayload(self, msgId, event):
        payload = {
            "event": event,
            "timestamp": Utils.getTime(),
            "oid": str(self.orgId),
            "nid": str(msgId),
            "email": "*****@*****.**",
            "cluster": "localcluster",
            "iid": "-1",
            "cid": "-1"
        }
        if event == 'DEFERRED':
            payload['response'] = ""
        if event == 'DROPPED':
            payload['reason'] = ""
        return payload

    @pytest.mark.parametrize('priority', [('HIGH'), ('BULK')])
    def test_sendMessage_Delivered(self, priority):
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "message": "test message for DLR"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'DELIVERED')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['DELIVERED'], 'Messages status after DLR update', 10)

    def test_sendMessage_NotDelivered(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'DROPPED')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['NOT_DELIVERED'], 'Messages status after DLR update', 10)
        resp = self.nsObj.isMessageDelivered(msgId)
        Assertion.constructAssertion(resp == False,
                                     'isMessageDelivered response')

    def test_sendMessage_PROCESSED(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'PROCESSED')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['GTW_PROCESSED'], 'Messages status after DLR update', 10)

    def test_sendMessage_IN_GTW(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'DEFERRED')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['IN_GTW'], 'Messages status after DLR update', 10)

    def test_sendMessage_OPEN(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'OPEN')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['OPENED'], 'Messages status after DLR update', 10)

    def test_sendMessage_CLICK(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'CLICK')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['CLICKED'], 'Messages status after DLR update', 10)

    def test_sendMessage_MARKED_SPAM(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'SPAMREPORT')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['MARKED_SPAM'], 'Messages status after DLR update', 10)

    def test_sendMessage_UNSUBSCRIBE(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        data = [self.getSendGridPayload(msgId, 'UNSUBSCRIBE')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['NOT_DELIVERED'], 'Messages status after DLR update', 10)

    def test_sendMessage_DELAYED_SCHEDULED_To_DELIVERED(self):
        scheduledTimestamp = int(time.time() + 180) * 1000  # 3 mins delay
        msgDict = {
            "messageClass": "EMAIL",
            "priority": 'HIGH',
            "scheduledTimestamp": scheduledTimestamp,
            "message": "test message for DLR"
        }
        msgId = self.nsadminHelper.createAndSendMessage(msgDict)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['DELAYED_SCHEDULED'], 'Messages status DELAYED_SCHEDULED',
            10)
        Utils.sleep(185)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
        data = [self.getSendGridPayload(msgId, 'DELIVERED')]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId, ['DELIVERED'], 'Messages status after DLR update', 10)

    def test_sendMessage_Batch(self):
        msgId1 = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId1,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        msgId2 = self.nsadminHelper.createAndSendMessage(self.msgDict)
        data = [
            self.getSendGridPayload(msgId1, 'DELIVERED'),
            self.getSendGridPayload(msgId2, 'DROPPED')
        ]
        self.DR.sendgrid(data)
        self.nsadminHelper.assertWithWaitUntil(
            msgId1, ['DELIVERED'], 'Messages status after DLR update', 10)
        self.nsadminHelper.assertWithWaitUntil(
            msgId2, ['NOT_DELIVERED'], 'Messages status after DLR update', 10)

    def test_sendMessage_GTWPROCESSED_INGWT_DELIVERED_OPEN_CLICK_MARKEDSPAM(
            self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
        statusDict = [('PROCESSED', 'GTW_PROCESSED'), ('DEFERRED', 'IN_GTW'),
                      ('DELIVERED', 'DELIVERED'), ('OPEN', 'OPENED'),
                      ('CLICK', 'CLICKED'), ('SPAMREPORT', 'MARKED_SPAM')]
        for event, status in statusDict:
            data = [self.getSendGridPayload(msgId, event)]
            self.DR.sendgrid(data)
            self.nsadminHelper.assertWithWaitUntil(
                msgId, [status], 'Messages status after DLR update', 10)

    def test_sendMessage_shouldNotUpdateAfter_INGWT(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
        statusDict = [('PROCESSED', 'GTW_PROCESSED'), ('DEFERRED', 'IN_GTW'),
                      ('PROCESSED', 'IN_GTW')]
        for event, status in statusDict:
            data = [self.getSendGridPayload(msgId, event)]
            self.DR.sendgrid(data)
            self.nsadminHelper.assertWithWaitUntil(
                msgId, [status], 'Messages status after DLR update', 10)

    def test_sendMessage_shouldNotUpdateAfter_NOTDELIVERED(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
        statusDict = [('PROCESSED', 'GTW_PROCESSED'), ('DEFERRED', 'IN_GTW'),
                      ('DROPPED', 'NOT_DELIVERED'),
                      ('PROCESSED', 'NOT_DELIVERED'),
                      ('DEFERRED', 'NOT_DELIVERED')]
        for event, status in statusDict:
            data = [self.getSendGridPayload(msgId, event)]
            self.DR.sendgrid(data)
            self.nsadminHelper.assertWithWaitUntil(
                msgId, [status], 'Messages status after DLR update', 10)

    def test_sendMessage_shouldNotUpdateAfter_DELIVERED(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status ACK', 10)
        statusDict = [('PROCESSED', 'GTW_PROCESSED'), ('DEFERRED', 'IN_GTW'),
                      ('DELIVERED', 'DELIVERED'), ('PROCESSED', 'DELIVERED'),
                      ('DEFERRED', 'DELIVERED')]
        for event, status in statusDict:
            data = [self.getSendGridPayload(msgId, event)]
            self.DR.sendgrid(data)
            self.nsadminHelper.assertWithWaitUntil(
                msgId, [status], 'Messages status after DLR update', 10)

    def test_sendMessage_shouldNotUpdateAfter_OPEN(self):
        msgId = self.nsadminHelper.createAndSendMessage(self.msgDict)
        self.nsadminHelper.assertWithWaitUntil(msgId,
                                               ['RECEIVED_IN_QUEUE', 'SENT'],
                                               'Messages status after ACK', 10)
        statusDict = [('OPEN', 'OPENED'), ('PROCESSED', 'OPENED'),
                      ('DEFERRED', 'OPENED'), ('DELIVERED', 'OPENED'),
                      ('DROPPED', 'OPENED')]
        for event, status in statusDict:
            data = [self.getSendGridPayload(msgId, event)]
            self.DR.sendgrid(data)
            self.nsadminHelper.assertWithWaitUntil(
                msgId, [status], 'Messages status after DLR update', 10)
예제 #30
0
class Test_CreditsManagement():
    def setup_class(self):
        Logger.logSuiteName(str(self).split('.')[-1])
        self.orgId = constant.config['orgId']

    def setup_method(self, method):
        messageClass = 'SMS'
        if 'EMAIL' in method.__name__:
            messageClass = 'EMAIL'
        self.nsObj = NSAdminHelper.getConnObj(newConnection=True)
        self.masterNsObj = NSAdminHelper.getMasterConnObj()
        self.nsadminHelper = NSAdminHelper(constant.config['orgId'],
                                           messageClass)
        self.nsadminHelper.disableDomainPropertiesGatewayMap()
        Logger.logMethodName(method.__name__)

    def test_addCreditsSMS(self):
        creditDetails1 = {"orgId": self.orgId, "bulkCredits": 200}
        creditDetails1 = NSAdminObject.OrgCreditDetails(creditDetails1)
        currVal = self.masterNsObj.getCreditDetails(self.orgId)
        resp1 = self.masterNsObj.addCredits(creditDetails1)
        afterAdd = self.masterNsObj.getCreditDetails(self.orgId)
        Assertion.constructAssertion(resp1 == True, 'addCredits response')
        Assertion.constructAssertion(
            afterAdd.bulkCredits == currVal.bulkCredits + 200,
            'increase in bulkCredits')
        creditDetails2 = {"orgId": self.orgId, "bulkCredits": -100}
        creditDetails2 = NSAdminObject.OrgCreditDetails(creditDetails2)
        resp2 = self.masterNsObj.addCredits(creditDetails2)
        afterDeduc = self.masterNsObj.getCreditDetails(self.orgId)
        Assertion.constructAssertion(resp2 == True, 'addCredits response')
        Assertion.constructAssertion(
            afterDeduc.bulkCredits == currVal.bulkCredits + 100,
            'decrease in bulkCredits')

    def test_addCreditsEmail(self):
        creditDetails1 = {
            "orgId": self.orgId,
            "bulkCredits": 200,
            'messageClass': 1
        }
        creditDetails1 = NSAdminObject.OrgCreditDetails(creditDetails1)
        currVal = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 1, 'test')
        resp1 = self.masterNsObj.addCredits(creditDetails1)
        afterAdd = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 1, 'test')
        Assertion.constructAssertion(resp1 == True, 'addCredits response')
        Assertion.constructAssertion(
            afterAdd.bulkCredits == currVal.bulkCredits + 200,
            'increase in bulkCredits')
        creditDetails2 = {
            "orgId": self.orgId,
            "bulkCredits": -100,
            'messageClass': 1
        }
        creditDetails2 = NSAdminObject.OrgCreditDetails(creditDetails2)
        resp2 = self.masterNsObj.addCredits(creditDetails2)
        afterDeduc = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 1, 'test')
        Assertion.constructAssertion(resp2 == True, 'addCredits response')
        Assertion.constructAssertion(
            afterDeduc.bulkCredits == currVal.bulkCredits + 100,
            'decrease in bulkCredits')

    def test_getCreditsLog(self):
        output = self.masterNsObj.getCreditsLog(self.orgId)
        Assertion.constructAssertion(len(output) > 0, 'count greater than 0')

    @pytest.mark.parametrize('priority, gateway',
                             [('HIGH', 'cardboardfishmock'),
                              ('BULK', 'valuefirstmock')])
    def est_CreditUseSMS(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        output = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 0, 'test')
        smsCreditsBefore = output.bulkCredits
        message320CharSize = "At Capillary, we continuously work to help our clients succeed in rapidly evolving markets through our world-class solutions, services and products. By combining big data with a robust, cloud-based analytics engine, we optimize the relevance and profitability of discounts and personalized offers to consumers in real time, significantly increasing both loyalty and sales"
        msgDict = {
            "messageClass": "SMS",
            "priority": priority,
            "truncate": False,
            "message": message320CharSize
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        time.sleep(10)
        output = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 0, 'test')
        smsCreditsAfter = output.bulkCredits
        Assertion.constructAssertion(smsCreditsBefore == smsCreditsAfter + 3,
                                     'sms usage count decrease by 3')

    @pytest.mark.parametrize('priority, gateway', [('HIGH', 'localmail_HIGH'),
                                                   ('BULK', 'localmail_BULK')])
    def est_CreditUseEMAIL(self, priority, gateway):
        self.nsadminHelper.configureGateway(priority, gateway)
        output = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 1, 'test')
        emailCreditsBefore = output.bulkCredits
        receiver = constant.config['prodEmail1'] + ',' + constant.config[
            'prodEmail2']
        msgDict = {
            "messageClass": "EMAIL",
            "priority": priority,
            "message": "test message with priority " + priority,
            'receiver': receiver
        }
        resp = self.nsadminHelper.createAndSendMessage(msgDict)
        time.sleep(5)
        output = self.masterNsObj.getCreditDetailsByOrgAndChannel(
            self.orgId, 1, 'test')
        emailCreditsAfter = output.bulkCredits
        Assertion.constructAssertion(
            emailCreditsBefore == emailCreditsAfter + 2,
            'eamil usage count decrease by 2 - count of receiver')