def test_create_delete_campaign():
    uid = md5.new(str(random.random())).hexdigest()
    subject = uid % 'chimpy campaign test %s'
    options = {'list_id': list_id(),
           'subject': subject,
           'from_email': EMAIL_ADDRESS,
           'from_name': 'chimpy',
           'generate_text': True
           }

    #this just to be sure flatten utility is working
    segment_opts = {'match': 'any', 
            'conditions':[{'field': 'date', 'op': 'gt', 'value': '2000-01-01'},
                          {'field': 'email', 'op': 'like', 'value': '@'}]}

    html = """ <html><body><h1>My test newsletter</h1><p>Just testing</p>
               <a href="*|UNSUB|*">Unsubscribe</a>*|REWARDS|*</body>"""


    content = {'html': html}
    cid = chimp.campaign_create('regular', options, content, segment_opts=segment_opts)
    assert isinstance(cid, basestring)

    # check if the new campaign really is there
    campaigns = chimp.campaigns(filter_subject=subject)
    assert len(campaigns['data'])==1
    assert campaigns['data'][0]['id'] == cid

    # our content properly addd?
    final_content = chimp.campaign_content(cid)
    assert '<h1>My test newsletter</h1>' in final_content['html']
    assert 'My test newsletter' in final_content['text']

    # clean up
    chimp.campaign_delete(cid)
dataset/ETHPy150Open divio/django-mailchimp/mailchimp/chimpy/test_chimpy.py/test_create_delete_campaign/swapped operands of `%`