'Test the task the create sailthru lists.'

@patch('email_marketing.tasks.SailthruClient')
def test_get_or_create_sailthru_list(self, mock_sailthru_client):

    mock_sailthru_client.api_get.return_value = SailthruResponse(JsonResponse({'lists': []}))
    _get_or_create_user_list(mock_sailthru_client, 'test1_user_list')
    mock_sailthru_client.api_get.assert_called_with('list', {})
    mock_sailthru_client.api_post.assert_called_with('list', {'list': 'test1_user_list', 'primary': 0, 'public_name': 'test1_user_list'})
    mock_sailthru_client.api_get.return_value = SailthruResponse(JsonResponse({'lists': [{'name': 'test1_user_list'}]}))
    _get_or_create_user_list(mock_sailthru_client, 'test2_user_list')
    mock_sailthru_client.api_get.assert_called_with('list', {})
    mock_sailthru_client.api_post.assert_called_with('list', {'list': 'test2_user_list', 'primary': 0, 'public_name': 'test2_user_list'})
    mock_sailthru_client.api_get.return_value = SailthruResponse(JsonResponse({'error': 43, 'errormsg': 'Got    an    error'}))
    self.assertEqual(_get_or_create_user_list(mock_sailthru_client, 'test1_user_list'), None)
    mock_sailthru_client.api_post.return_value = SailthruResponse(JsonResponse({'error': 43, 'errormsg': 'Got    an    error'}))
    mock_sailthru_client.api_get.return_value = SailthruResponse(JsonResponse({'lists': []}))
    self.assertEqual(_get_or_create_user_list(mock_sailthru_client, 'test2_user_list'), None)
