示例#1
0
    def test_sync_lead_wrap(self):
        # with empty attribute set
        self.assertEqual(
            sync_lead.wrap(email="*****@*****.**", attributes=()),
            u"<mkt:paramsSyncLead>"
            u"<leadRecord>"
            u"<Email>[email protected]</Email>"
            u"<leadAttributeList></leadAttributeList>"
            u"</leadRecord>"
            u"<returnLead>true</returnLead>"
            u"<marketoCookie></marketoCookie>"
            u"</mkt:paramsSyncLead>")

        # with 1 attribute
        self.assertEqual(
            sync_lead.wrap(email="*****@*****.**",
                           attributes=(("Name", "string",
                                        u"John Do, a hős"), )),
            u"<mkt:paramsSyncLead>"
            u"<leadRecord>"
            u"<Email>[email protected]</Email>"
            u"<leadAttributeList>"
            u"<attribute>"
            u"<attrName>Name</attrName>"
            u"<attrType>string</attrType>"
            u"<attrValue>John Do, a hős</attrValue>"
            u"</attribute>"
            u"</leadAttributeList>"
            u"</leadRecord>"
            u"<returnLead>true</returnLead>"
            u"<marketoCookie></marketoCookie>"
            u"</mkt:paramsSyncLead>")

        # with more attributes
        self.assertEqual(
            sync_lead.wrap(email="*****@*****.**",
                           attributes=(
                               ("Name", "string", "John Do"),
                               ("Age", "integer", "20"),
                           )), u"<mkt:paramsSyncLead>"
            u"<leadRecord>"
            u"<Email>[email protected]</Email>"
            u"<leadAttributeList>"
            u"<attribute>"
            u"<attrName>Name</attrName>"
            u"<attrType>string</attrType>"
            u"<attrValue>John Do</attrValue>"
            u"</attribute>"
            u"<attribute>"
            u"<attrName>Age</attrName>"
            u"<attrType>integer</attrType>"
            u"<attrValue>20</attrValue>"
            u"</attribute>"
            u"</leadAttributeList>"
            u"</leadRecord>"
            u"<returnLead>true</returnLead>"
            u"<marketoCookie></marketoCookie>"
            u"</mkt:paramsSyncLead>")
示例#2
0
    def test_sync_lead_wrap(self):
        # with empty attribute set
        self.assertEqual(sync_lead.wrap(email="*****@*****.**", attributes=()),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Email>[email protected]</Email>"
                         u"<leadAttributeList></leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"<marketoCookie></marketoCookie>"
                         u"</mkt:paramsSyncLead>")

        # with 1 attribute
        self.assertEqual(sync_lead.wrap(email="*****@*****.**", attributes=(("Name", "string", u"John Do, a hős"),)),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Email>[email protected]</Email>"
                         u"<leadAttributeList>"
                         u"<attribute>"
                         u"<attrName>Name</attrName>"
                         u"<attrType>string</attrType>"
                         u"<attrValue>John Do, a hős</attrValue>"
                         u"</attribute>"
                         u"</leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"<marketoCookie></marketoCookie>"
                         u"</mkt:paramsSyncLead>")

        # with more attributes
        self.assertEqual(sync_lead.wrap(email="*****@*****.**", attributes=(("Name", "string", "John Do"),
                                                                         ("Age", "integer", "20"),)),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Email>[email protected]</Email>"
                         u"<leadAttributeList>"
                         u"<attribute>"
                         u"<attrName>Name</attrName>"
                         u"<attrType>string</attrType>"
                         u"<attrValue>John Do</attrValue>"
                         u"</attribute>"
                         u"<attribute>"
                         u"<attrName>Age</attrName>"
                         u"<attrType>integer</attrType>"
                         u"<attrValue>20</attrValue>"
                         u"</attribute>"
                         u"</leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"<marketoCookie></marketoCookie>"
                         u"</mkt:paramsSyncLead>")
示例#3
0
    def sync_lead(self, marketo_id=None, email=None, marketo_cookie=None, foreign_id=None, attributes=None):
        """
        This function will insert or update a single lead record.
                When updating an existing lead, the lead can be identified with one of the following keys:

        If an existing match is found, the call will perform an update.
        If not, it will insert and create a new lead.
        Anonymous leads can be updated using the Marketo Cookie ID.
        http://developers.marketo.com/documentation/soap/synclead/

        :param marketo_id:
        :param email:
        :param marketo_cookie:
        :param foreign_id:
        :param attributes:
        :return: :raise exceptions.unwrap:
        """
        if not (marketo_id or email or marketo_cookie or foreign_id):
            raise ValueError('Must supply at least one id for the lead.')

        if not attributes:
            raise ValueError('Must supply attributes as a non empty iterable object.')

        body = sync_lead.wrap(marketo_id=marketo_id,
                              email=email,
                              marketo_cookie=marketo_cookie,
                              foreign_id=foreign_id,
                              attributes=attributes)

        response = self.request(body)

        if response.status_code == 200:
            return sync_lead.unwrap(response.text.encode("utf-8"))
        else:
            raise exceptions.unwrap(response.text)
示例#4
0
    def sync_lead(self, email=None, attributes=None):

        if not email or not isinstance(email, (str, unicode)):
            raise ValueError('Must supply lead id as a non empty string.')

        if not attributes or not (isinstance(attributes, tuple) or isinstance(attributes, dict)):
            raise ValueError('Must supply attributes as a non empty tuple or dict.')

        body = sync_lead.wrap(email, attributes)

        response = self.request(body)
        if response.status_code == 200:
            return sync_lead.unwrap(response)
        else:
            raise Exception(response.text)
示例#5
0
    def sync_lead(self, email=None, attributes=None):

        if not email or not isinstance(email, (str, unicode)):
            raise ValueError('Must supply lead id as a non empty string.')

        if not attributes or not isinstance(attributes, tuple):
            raise ValueError('Must supply attributes as a non empty tuple.')

        body = sync_lead.wrap(email, attributes)

        response = self.request(body)
        if response.status_code == 200:
            return sync_lead.unwrap(response)
        else:
            raise Exception(response.text)
示例#6
0
    def sync_lead(self,
                  email=None,
                  marketo_id=None,
                  marketo_cookie=None,
                  foreign_system_id=None,
                  foreign_system_type=None,
                  attributes=None):
        """
        Push information about a lead to Marketo. Lead must be identified by one or more of email, marketo_id,
        marketo_cookie, or foriegn_system_id. See http://developers.marketo.com/documentation/soap/synclead/ for more
        details.

        :type email: str
        :param email: the email address of the lead

        :type marketo_id: str
        :param marketo_id: the marketo generated id for a lead

        :type marketo_cookie: str
        :param marketo_cookie: a marketo cookie generated for a lead by Marketo's munchkin.js

        :type foreign_system_id: str
        :param foreign_system_id: a foriegn system identifier for a lead

        :type foreign_system_type: str
        :param foreign_system_type: the type of foreign system for foreign_system_id. Required if foreign_system_id
        is passed. Possible values are 'CUSTOM', 'SFDC', 'NETSUITE'

        :type attributes: tuple, dict
        :param attributes: the information about the lead to be pushed to marketo either in the form of tuples or a
        dictionary

        :returns: a lead object for the lead that was sync'ed
        """
        if (not email or not isinstance(email, (str, unicode))) \
                and (not marketo_id or not isinstance(marketo_id, (str, unicode))) \
                and (not marketo_cookie or not isinstance(marketo_cookie, (str, unicode))) \
                and (not foreign_system_id or not isinstance(foreign_system_id, (str, unicode))):
            raise ValueError('Must supply lead identification in email, marketo_id, '
                             'marketo_cookie, or foreign_system_id as a non empty string.')

        if foreign_system_id and not foreign_system_type:
            raise ValueError('foreign_system_type must be specified with foreign_system_id')

        if foreign_system_id and foreign_system_type and foreign_system_type not in ['CUSTOM', 'SFDC', 'NETSUITE']:
            raise ValueError('foreign_system_type must be \'CUSTOM\', \'SFDC\', or \'NETSUITE\'')

        if not attributes or (not isinstance(attributes, tuple) and not isinstance(attributes, dict)):
            raise ValueError('Must supply attributes as a non empty tuple or dict.')

        body = sync_lead.wrap(
            email=email,
            marketo_id=marketo_id,
            marketo_cookie=marketo_cookie,
            foreign_system_id=foreign_system_id,
            attributes=attributes)

        response = self.request(body)
        if response.status_code == 200:
            return sync_lead.unwrap(response)
        else:
            raise Exception(response.text)
示例#7
0
    def test_sync_lead_wrap(self):
        # with marketo_id as id field
        self.assertEqual(sync_lead.wrap(marketo_id=101, attributes=()),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Id>101</Id>"
                         u"<leadAttributeList></leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"</mkt:paramsSyncLead>")

        # with email as id field
        self.assertEqual(sync_lead.wrap(email="john@doe", attributes=()),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Email>john@doe</Email>"
                         u"<leadAttributeList></leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"</mkt:paramsSyncLead>")

        # with marketo_cookie as id field
        self.assertEqual(sync_lead.wrap(marketo_cookie="__marketo_cookie__", attributes=()),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<leadAttributeList></leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"<marketoCookie>__marketo_cookie__</marketoCookie>"
                         u"</mkt:paramsSyncLead>")

        # with foreign_id as id field
        self.assertEqual(sync_lead.wrap(foreign_id="__foreign_id__", attributes=()),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<ForeignSysPersonId>__foreign_id__</ForeignSysPersonId>"
                         u"<ForeignSysType>CUSTOM</ForeignSysType>"
                         u"<leadAttributeList></leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"</mkt:paramsSyncLead>")

        # with all id fields
        self.assertEqual(sync_lead.wrap(marketo_id=101,
                                        email="john@doe",
                                        foreign_id="__foreign_id__",
                                        marketo_cookie="__marketo_cookie__",
                                        attributes=()),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Id>101</Id>"
                         u"<Email>john@doe</Email>"
                         u"<ForeignSysPersonId>__foreign_id__</ForeignSysPersonId>"
                         u"<ForeignSysType>CUSTOM</ForeignSysType>"
                         u"<leadAttributeList></leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"<marketoCookie>__marketo_cookie__</marketoCookie>"
                         u"</mkt:paramsSyncLead>")

        # with 1 attribute
        self.assertEqual(sync_lead.wrap(marketo_id=101, attributes=(("Name", "string", u"John Doe, a hős"),)),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Id>101</Id>"
                         u"<leadAttributeList>"
                         u"<attribute>"
                         u"<attrName>Name</attrName>"
                         u"<attrType>string</attrType>"
                         u"<attrValue>John Doe, a hős</attrValue>"
                         u"</attribute>"
                         u"</leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"</mkt:paramsSyncLead>")

        # with more attributes
        self.assertEqual(sync_lead.wrap(email="john@doe", attributes=(("Name", "string", "John Do"),
                                                                      ("Age", "integer", "20"),)),
                         u"<mkt:paramsSyncLead>"
                         u"<leadRecord>"
                         u"<Email>john@doe</Email>"
                         u"<leadAttributeList>"
                         u"<attribute>"
                         u"<attrName>Name</attrName>"
                         u"<attrType>string</attrType>"
                         u"<attrValue>John Do</attrValue>"
                         u"</attribute>"
                         u"<attribute>"
                         u"<attrName>Age</attrName>"
                         u"<attrType>integer</attrType>"
                         u"<attrValue>20</attrValue>"
                         u"</attribute>"
                         u"</leadAttributeList>"
                         u"</leadRecord>"
                         u"<returnLead>true</returnLead>"
                         u"</mkt:paramsSyncLead>")