示例#1
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')
示例#2
0
 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))
示例#3
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')
示例#4
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)
示例#5
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')
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)
示例#7
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)
示例#8
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')            
示例#9
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')