'test async method in tasks that actually updates Sailthru and send Welcome template.'

@patch('email_marketing.tasks.log.error')
@patch('email_marketing.tasks.SailthruClient.api_post')
@patch('email_marketing.tasks.SailthruClient.api_get')
def test_add_user(self, mock_sailthru_get, mock_sailthru_post, mock_log_error):

    site_dict = {'id': self.site.id, 'domain': self.site.domain, 'name': self.site.name}
    mock_sailthru_post.return_value = SailthruResponse(JsonResponse({'ok': True}))
    mock_sailthru_get.return_value = SailthruResponse(JsonResponse({'lists': [{'name': 'new    list'}], 'ok': True}))
    update_user.delay({'gender': 'm', 'username': 'test', 'activated': 1}, TEST_EMAIL, site_dict, new_user=True)
    expected_schedule = (datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
    self.assertFalse(mock_log_error.called)
    self.assertEquals(mock_sailthru_post.call_args[0][0], 'send')
    userparms = mock_sailthru_post.call_args[0][1]
    self.assertEquals(userparms['email'], TEST_EMAIL)
    self.assertEquals(userparms['template'], 'Welcome')
    self.assertEquals(userparms['schedule_time'], expected_schedule.strftime('%Y-%m-%dT%H:%M:%SZ'))
