Skip to content

Commit 67bb4ad

Browse files
committed
add campaign related testing
1 parent bd89622 commit 67bb4ad

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

mailsnake/tests/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@
389389
<table border="0" cellpadding="10" cellspacing="0" width="100%">
390390
<tr>
391391
<td valign="top">
392-
<div mc:edit="std_content00"></div>
392+
<div mc:edit="std_content00">default content</div>
393393
</td>
394394
</tr>
395395
</table>

mailsnake/tests/tests.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from collections import MutableSequence
44
from mailsnake import MailSnake
5+
from random import random
6+
57
from .secret_keys import MAILCHIMP_API_KEY, MAILCHIMP_LIST_ID
68

79
"""
@@ -36,6 +38,35 @@ def test_chimpChatter(self):
3638
assert 'message' in chimp_chatter[0].keys()
3739
assert chimp_chatter[0]['url'].find('mailchimp') > -1
3840

41+
# Campaign Related Methods
42+
43+
def test_campaignCreateDelete(self):
44+
template_id = self._add_test_template()
45+
from_email = self.mcapi.getAccountDetails()['contact']['email']
46+
options = {
47+
'list_id': MAILCHIMP_LIST_ID, 'subject': 'testing',
48+
'from_email': from_email, 'from_name': 'Test From',
49+
'to_name': 'Test To', 'template_id': template_id,
50+
'inline_css': True, 'generate_text': True, 'title': 'testing'
51+
}
52+
test_content = '%f' % random()
53+
content = {'html_std_content00': test_content}
54+
campaign_id = self.mcapi.campaignCreate(
55+
type='regular', options=options, content=content)
56+
assert isinstance(campaign_id, unicode)
57+
campaign_content = self.mcapi.campaignContent(cid=campaign_id)
58+
assert 'html' in campaign_content
59+
assert 'text' in campaign_content
60+
assert test_content in campaign_content['html']
61+
assert test_content in campaign_content['text']
62+
default_content = 'default content'
63+
assert not default_content in campaign_content['html']
64+
assert not default_content in campaign_content['text']
65+
66+
# Clean up
67+
assert self.mcapi.campaignDelete(cid=campaign_id)
68+
assert self.mcapi.templateDel(id=template_id)
69+
3970
# List Related Methods
4071

4172
def test_lists(self):
@@ -57,15 +88,18 @@ def test_templates(self):
5788
assert t_type in self.mcapi.templates(types=new_types)
5889

5990
def test_templateAddDel(self):
91+
template_id = self._add_test_template()
92+
assert isinstance(template_id, int)
93+
assert self.mcapi.templateDel(id=template_id)
94+
95+
def _add_test_template(self):
96+
html = open('mailsnake/tests/template.html', 'r').read()
6097
templates = self.mcapi.templates(inactives={'include': True})
6198
template_names = [t['name'] for t in templates['user']]
62-
html = open('mailsnake/tests/template.html', 'r').read()
6399
index = 0
64100
base_name = 'mailsnake_test_template'
65101
template_name = '%s%i' % (base_name, index)
66102
while template_name in template_names:
67103
index += 1
68104
template_name = '%s%i' % (base_name, index)
69-
template_id = self.mcapi.templateAdd(name=template_name, html=html)
70-
assert isinstance(template_id, int)
71-
assert self.mcapi.templateDel(id=template_id)
105+
return self.mcapi.templateAdd(name=template_name, html=html)

0 commit comments

Comments
 (0)