def test_add(self): header = SMTPAPIHeader() header.add_to('*****@*****.**') header.add_substitution('subKey', 'subValue') header.add_section('testSection', 'sectionValue') header.add_category('testCategory') header.add_unique_arg('testUnique', 'uniqueValue') header.add_filter('testFilter', 'filter', 'filterValue') self.assertEqual(self.validHeader, json.loads(header.json_string()))
def _prepare_payload(self, recipients=None): def namestr(rec): if not rec.get('name'): return rec.get('email') return '"{}" <{}>'.format(rec['name'].replace('"', ''), rec['email'].replace(',', '')) if not recipients: recipients = self.solidify_recipients() num_rec = len(recipients) payload = SMTPAPIHeader() merge_vars = {} for key, val in self.global_merge_vars.items(): keystr = ':{}'.format(key) new_key = '{1}{0}{2}'.format(key, *self.delimiters) merge_vars[new_key] = [keystr] * num_rec payload.add_section(keystr, val) for index, recip in enumerate(recipients): payload.add_to(recip if isinstance(recip, str) else namestr(recip)) for rkey, rvalue in recip.get('merge_vars', {}).items(): new_key = '{1}{0}{2}'.format(rkey, *self.delimiters) if not merge_vars.get(new_key): merge_vars[new_key] = [None] * num_rec merge_vars[new_key][index] = rvalue if self.webhook_data: payload.set_unique_args(self.webhook_data) if self.ip_pool: payload.set_ip_pool(self.ip_pool) if self.template_name: payload.add_filter('templates', 'enabled', 1) payload.add_filter('templates', 'template_id', self.template_name) payload.set_substitutions(merge_vars) payload.add_filter('clicktrack', 'enable', self.track_clicks and 1 or 0) payload.add_filter('opentrack', 'enable', self.track_opens and 1 or 0) payload.set_categories(self.tags) return payload
def test_add(self): header = SMTPAPIHeader() header.add_to('*****@*****.**') header.add_to(['*****@*****.**', '*****@*****.**']) header.add_substitution('subKey', 'subValue') header.add_section('testSection', 'sectionValue') header.add_category('testCategory') header.add_unique_arg('testUnique', 'uniqueValue') header.set_asm_group_id(42) header.add_send_each_at(1409348513) header.add_send_each_at(1409348514) header.set_send_at(1409348515) header.add_filter('testFilter', 'filter', 'filterValue') self.assertEqual(self.validHeader, json.loads(header.json_string()))