Comment 4 for bug 1414352

Aanand (aanand0071) wrote :

from __future__ import (
    absolute_import, division, print_function, unicode_literals)

import six
import logging

from django.core.urlresolvers import reverse
from django.test import Client, SimpleTestCase
from django.test.utils import override_settings
from urllib2 import HTTPError
from django.contrib.auth.models import User
from postorius.utils import get_client
from postorius.tests import MM_VCR

logger = logging.getLogger(__name__)
vcr_log = logging.getLogger('vcr')
vcr_log.setLevel(logging.WARNING)

API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001',
                   'MAILMAN_USER': 'restadmin',
                   'MAILMAN_PASS': 'restpass'}

@override_settings(**API_CREDENTIALS)
class ListDeletePageTest(SimpleTestCase):
    """Tests for the list index page."""

    @MM_VCR.use_cassette('test_list_index.yaml')
    def setUp(self):
        self.mm_client = get_client()
        self.client = Client()
        try:
            self.domain = self.mm_client.create_domain('example.com')
        except HTTPError:
            self.domain = self.mm_client.get_domain('example.com')
        self.foo_list = self.mm_client.get_list('<email address hidden>')
        self.superuser=User.objects.create_superuser('sup','<email address hidden>','pswd')

    @MM_VCR.use_cassette('test_list_index.yaml')
    def test_list_delete_contains_no_list(self):
        self.client.login(username='sup',password='pswd')
        response1 = self.client.get(reverse('list_delete',args=['<email address hidden>']),follow=True)
        self.assertEqual(response1.status_code,200)
        self.client.post(reverse('list_delete',args=['<email address hidden>']),follow=True)
        self.assertRedirects(response1,reverse('list_index'),status_code=302)
        response2=self.client.get(reverse('list_delete'))
        self.asserEqual(len(response2.context['lists']), 0)

    @MM_VCR.use_cassette('test_list_index.yaml')
    def tearDown(self):
        self.superuser.delete()
        self.client.delete_domain('example.org')