Improve code coverage by adding tests

Bug #1414352 reported by Terri on 2015-01-24
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
GNU Mailman
Undecided
Unassigned
Postorius
High
nilmadhab mondal

Bug Description

Mailman Core and Postorius have sets of tests, but could use more extensive test coverage. This bug is meant to be a repeatable bug suitable for new contributors (e.g. prospective Google Summer of Code Students). In short: find a piece of Postorius or Mailman Core that isn't yet tested and write a test (or set of tests) for it.

Contributors wishing to work on Mailman Core should look at START.rst and DATABASE.rst for more information about setting up tests.

For Postorius, Florian is working on vcrpy test integration, so new tests can use that format.

Links to documentation and examples much appreciated to update this bug!

Related branches

Terri (terriko) on 2015-01-24
tags: added: easy mailman3
description: updated
tags: added: repeatable
Florian Fuchs (flo-fuchs) wrote :

vcrpy is now integrated into Postorius.

I updated the documentation, instructions on how to run the tests can be found in (from Postorius' root directory):

src/postorius/docs/development.rst

Changed in postorius:
status: New → Confirmed
importance: Undecided → High
Florian Fuchs (flo-fuchs) wrote :

This is the current coverage report. We can clearly do better! :-)

Name Stmts Miss Cover Missing
------------------------------------------------------------------
postorius 1 1 0% 19
postorius.auth 0 0 100%
postorius.auth.decorators 68 25 63% 30-43, 83, 85, 100-105, 113-116
postorius.context_processors 7 1 86% 30
postorius.doc 0 0 100%
postorius.fieldset_forms 37 19 49% 50-59, 68, 74-95
postorius.forms 187 43 77% 52-53, 139, 149-150, 598-599, 602-625, 632-638, 830-836, 849-850
postorius.management 0 0 100%
postorius.management.commands 0 0 100%
postorius.models 149 42 72% 66-69, 75-83, 90-93, 96-107, 113, 124-127, 135, 138-143, 153, 159, 253
postorius.templatetags 0 0 100%
postorius.templatetags.nav_helpers 24 8 67% 29, 38-40, 48-50, 57
postorius.urls 8 0 100%
postorius.utils 14 4 71% 32-34, 47
postorius.views 4 0 100%
postorius.views.api 28 3 89% 56-58
postorius.views.generic 78 41 47% 35-37, 71-72, 79, 92-93, 96-106, 109-113, 116-126, 130-144
postorius.views.list 354 237 33% 67-68, 78-79, 104-126, 136-148, 182, 197-212, 221-231, 240-241, 246-268, 274-275, 316-326, 337, 341-342, 345, 366-446, 459-470, 481-485, 494-503, 510-519, 526-535, 542-551, 568-613, 628-658
postorius.views.settings 58 33 43% 50, 57-61, 69-87, 95-109
postorius.views.user 222 161 27% 51-68, 72-80, 91-111, 115-134, 148-167, 171-191, 207-209, 222-223, 249-250, 263-269, 282-300, 306-307, 312-318, 325, 335-345, 356-375, 382-386, 400-401
------------------------------------------------------------------
TOTAL 1239 618 50%
----------------------------------------------------------------------

Aanand (aanand0071) wrote :

Hi florian, I modified it a bit.Can you look into it and review it, as I am still getting errors while running it.

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')

Changed in postorius:
assignee: nobody → nilmadhab mondal (nilmadhab1994)
Pranjal Yadav (godricglow) wrote :

Hi florain

I modified tests for forms and currently at 52% coverage. I'm testing on views and I'll try to move it up to 55% soon. Will be sending a pull req soon

Changed in mailman:
assignee: nobody → Yash (yashmehrotra95)
Changed in mailman:
status: New → In Progress
Abhilash Raj (raj-abhilash1) wrote :

This bug has been moved to the new gitlab repo here: https://gitlab.com/mailman/postorius/issues/2

Changed in mailman:
assignee: Yash (yashmehrotra95) → nobody
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers