예제 #1
0
 def test_send(self):
   m = Mail()
   m.add_to('John, Doe <*****@*****.**>')
   m.set_subject('test')
   m.set_html('WIN')
   m.set_text('WIN')
   m.set_from('*****@*****.**')
   m.add_substitution('subKey', 'subValue')
   m.add_section('testSection', 'sectionValue')
   m.add_category('testCategory')
   m.add_unique_arg('testUnique', 'uniqueValue')
   m.add_filter('testFilter', 'filter', 'filterValue')
   m.add_attachment_stream('testFile', 'fileValue')
   self.sg.send(m)
   url = self.sg._build_body(m)
   url.pop('api_key', None)
   url.pop('api_user', None)
   url.pop('date', None)
   testUrl = json.loads('''{"to[]": ["*****@*****.**"],
   "toname[]": ["John Doe"],
   "html": "WIN",
   "text": "WIN",
   "subject": "test",
   "files[testFile]": "fileValue",
   "from": "*****@*****.**",
   "headers": "",
   "fromname": "",
   "replyto": ""}''')
   testUrl['x-smtpapi'] = json.dumps(json.loads('''{"sub":{"subKey":["subValue"]},
     "section":{"testSection":"sectionValue"},
     "category":["testCategory"],
     "unique_args":{"testUnique":"uniqueValue"},
     "filters":{"testFilter":{"settings":{"filter":"filterValue"}}}}'''))
   self.assertEqual(url, testUrl)
 def test_send(self):
     m = Mail()
     m.add_to('John, Doe <*****@*****.**>')
     m.set_subject('test')
     m.set_html('WIN')
     m.set_text('WIN')
     m.set_from('*****@*****.**')
     m.set_asm_group_id(42)
     m.add_cc('*****@*****.**')
     m.add_bcc('*****@*****.**')
     m.add_substitution('subKey', 'subValue')
     m.add_section('testSection', 'sectionValue')
     m.add_category('testCategory')
     m.add_unique_arg('testUnique', 'uniqueValue')
     m.add_filter('testFilter', 'filter', 'filterValue')
     m.add_attachment_stream('testFile', 'fileValue')
     url = self.sg._build_body(m)
     url.pop('api_key', None)
     url.pop('api_user', None)
     url.pop('date', None)
     test_url = json.loads('''
         {
             "to[]": ["*****@*****.**"],
             "toname[]": ["John Doe"],
             "html": "WIN",
             "text": "WIN",
             "subject": "test",
             "files[testFile]": "fileValue",
             "from": "*****@*****.**",
             "cc[]": ["*****@*****.**"],
             "bcc[]": ["*****@*****.**"]
         }
         ''')
     test_url['x-smtpapi'] = json.dumps(json.loads('''
         {
             "sub": {
                 "subKey": ["subValue"]
             },
             "section": {
                 "testSection":"sectionValue"
             },
             "category": ["testCategory"],
             "unique_args": {
                 "testUnique":"uniqueValue"
             },
             "filters": {
                 "testFilter": {
                     "settings": {
                         "filter": "filterValue"
                     }
                 }
             },
             "asm_group_id": 42
         }
         '''))
     
     try:
         self.assertItemsEqual(url, test_url)
     except: # Python 3+
         self.assertCountEqual(url, test_url)
예제 #3
0
    def test_send(self):
        m = Mail()
        m.add_to('John, Doe <*****@*****.**>')
        m.set_subject('test')
        m.set_html('WIN')
        m.set_text('WIN')
        m.set_from('*****@*****.**')
        m.set_asm_group_id(42)
        m.add_cc('*****@*****.**')
        m.add_bcc('*****@*****.**')
        m.add_substitution('subKey', 'subValue')
        m.add_section('testSection', 'sectionValue')
        m.add_category('testCategory')
        m.add_unique_arg('testUnique', 'uniqueValue')
        m.add_filter('testFilter', 'filter', 'filterValue')
        m.add_attachment_stream('testFile', 'fileValue')
        url = self.sg._build_body(m)
        url.pop('api_key', None)
        url.pop('api_user', None)
        url.pop('date', None)
        test_url = json.loads('''
            {
                "to[]": ["*****@*****.**"],
                "toname[]": ["John Doe"],
                "html": "WIN",
                "text": "WIN",
                "subject": "test",
                "files[testFile]": "fileValue",
                "from": "*****@*****.**",
                "cc[]": ["*****@*****.**"],
                "bcc[]": ["*****@*****.**"]
            }
            ''')
        test_url['x-smtpapi'] = json.dumps(
            json.loads('''
            {
                "sub": {
                    "subKey": ["subValue"]
                },
                "section": {
                    "testSection":"sectionValue"
                },
                "category": ["testCategory"],
                "unique_args": {
                    "testUnique":"uniqueValue"
                },
                "filters": {
                    "testFilter": {
                        "settings": {
                            "filter": "filterValue"
                        }
                    }
                },
                "asm_group_id": 42
            }
            '''))

        self.assertEqual(url, test_url)
예제 #4
0
 def test_send(self):
     m = Mail()
     m.add_to("John, Doe <*****@*****.**>")
     m.set_subject("test")
     m.set_html("WIN")
     m.set_text("WIN")
     m.set_from("*****@*****.**")
     m.add_substitution("subKey", "subValue")
     m.add_section("testSection", "sectionValue")
     m.add_category("testCategory")
     m.add_unique_arg("testUnique", "uniqueValue")
     m.add_filter("testFilter", "filter", "filterValue")
     m.add_attachment_stream("testFile", "fileValue")
     url = self.sg._build_body(m)
     url.pop("api_key", None)
     url.pop("api_user", None)
     url.pop("date", None)
     test_url = json.loads(
         """
         {
             "to[]": ["*****@*****.**"],
             "toname[]": ["John Doe"],
             "html": "WIN",
             "text": "WIN",
             "subject": "test",
             "files[testFile]": "fileValue",
             "from": "*****@*****.**"
         }
         """
     )
     test_url["x-smtpapi"] = json.dumps(
         json.loads(
             """
         {
             "to" : ["John, Doe <*****@*****.**>"],
             "sub": {
                 "subKey": ["subValue"]
             },
             "section": {
                 "testSection":"sectionValue"
             },
             "category": ["testCategory"],
             "unique_args": {
                 "testUnique":"uniqueValue"
             },
             "filters": {
                 "testFilter": {
                     "settings": {
                         "filter": "filterValue"
                     }
                 }
             }
         }
         """
         )
     )
     self.assertEqual(url, test_url)
예제 #5
0
        templates = t_group['versions']
        for template in templates:
            if template['name'] == template_name:
                return t_group['id']


template_id = get_template_id_by_name(template_name)

message = Mail()
message.add_filter('templates', 'enable', '1')
message.add_filter('templates', 'template_id', template_id)
message.set_subject(None)
for to_addr in to_addrs:
    message.add_to(to_addr)
for key, value in context.items():
    message.add_substitution("%{}%".format(key), value)
message.set_from('Foo <*****@*****.**>')
message.set_html('  ')
message.set_text('  ')
message.set_subject('  ')










예제 #6
0
        templates = t_group['versions']
        for template in templates:
            if template['name'] == template_name:
                return t_group['id']


template_id = get_template_id_by_name(template_name)

message = Mail()
message.add_filter('templates', 'enable', '1')
message.add_filter('templates', 'template_id', template_id)
message.set_subject(None)
for to_addr in to_addrs:
    message.add_to(to_addr)
for key, value in context.items():
    message.add_substitution("%{}%".format(key), value)
message.set_from('Foo <*****@*****.**>')
message.set_html('  ')
message.set_text('  ')
message.set_subject('  ')

# scrapy

# xpath selection

# find td with `dc.identifier.uri` as text and get text of its sibling
url = response.xpath(
    '//td[contains(., "dc.identifier.uri")]/following-sibling::td/text()')

# find element with class `file-link` and get `href` of `a` inside it
pdf = response.xpath('//*[contains(@class, "file-link")]//a/@href')