示例#1
0
    def test_get_newsletter_statistics_division_by_zero(self):
        """Try to have a ZeroDivisionError by unsubscribing all contacts,
        and creating a ContactMailingStatus for more code coverage.
        Bug : http://github.com/Fantomas42/emencia-django-newsletter/issues#issue/9"""
        get_newsletter_statistics(self.newsletter)

        self.mailinglist.unsubscribers.add(*self.contacts)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.OPENED)
        get_newsletter_statistics(self.newsletter)
示例#2
0
 def test_get_newsletter_statistics_division_by_zero(self):
     """Try to have a ZeroDivisionError by unsubscribing all contacts,
     and creating a ContactMailingStatus for more code coverage.
     Bug : http://github.com/Fantomas42/emencia-django-newsletter/issues#issue/9"""
     stats = get_newsletter_statistics(self.newsletter)
     
     self.mailinglist.unsubscribers.add(*self.contacts)
     ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                         contact=self.contacts[0],
                                         status=ContactMailingStatus.OPENED)
     stats = get_newsletter_statistics(self.newsletter)
def view_newsletter_statistics(request, slug):
    """Display the statistics of a newsletters"""
    opts = Newsletter._meta
    newsletter = get_object_or_404(Newsletter, slug=slug)

    context = {'title': _('Statistics of %s') % newsletter.__unicode__(),
               'object': newsletter,
               'opts': opts,
               'object_id': newsletter.pk,
               'app_label': opts.app_label,
               'stats': get_newsletter_statistics(newsletter),
               'period': get_statistics_period(newsletter),}

    return render_to_response('newsletter/newsletter_statistics.html',
                              context, context_instance=RequestContext(request))
示例#4
0
def view_newsletter_statistics(request, slug):
    """Display the statistics of a newsletters"""
    opts = Newsletter._meta
    newsletter = get_object_or_404(Newsletter, slug=slug)

    context = {
        'title': _('Statistics of %s') % newsletter.__str__(),
        'object': newsletter,
        'opts': opts,
        'object_id': newsletter.pk,
        'app_label': opts.app_label,
        'stats': get_newsletter_statistics(newsletter),
        'period': get_statistics_period(newsletter),
    }

    return render(request, 'newsletter/newsletter_statistics.html', context)
def view_newsletter_statistics(request, slug):
    """Display the statistics of a newsletters"""
    opts = Newsletter._meta
    newsletter = get_object_or_404(Newsletter, slug=slug)

    context = {
        "title": _("Statistics of %s") % newsletter.__unicode__(),
        "object": newsletter,
        "opts": opts,
        "object_id": newsletter.pk,
        "app_label": opts.app_label,
        "stats": get_newsletter_statistics(newsletter),
        "period": get_statistics_period(newsletter),
    }

    return render_to_response(
        "newsletter/newsletter_statistics.html", context, context_instance=RequestContext(request)
    )
def view_newsletter_statistics(request, slug, mailing_list_pk=None):
    """Display the statistics of a newsletters"""
    opts = Newsletter._meta
    newsletter = get_object_or_404(Newsletter, slug=slug)

    context = {'title': _('Statistics of %s') % newsletter.__unicode__(),
               'object': newsletter,
               'opts': opts,
               'object_id': newsletter.pk,
               'app_label': opts.app_label,
               'stats': get_newsletter_statistics(newsletter, mailing_list_pk),
               'period': get_statistics_period(newsletter),}
               
    if mailing_list_pk:
        mailing_list = get_object_or_404(MailingList, pk=mailing_list_pk)
        context['mailing_list'] = mailing_list
        context['title'] = _('Statistics of %s / %s') % (newsletter.__unicode__(), mailing_list.__unicode__())

    return render_to_response('newsletter/newsletter_statistics.html',
                              context, context_instance=RequestContext(request))
示例#7
0
    def test_get_newsletter_statistics(self):
        stats = get_newsletter_statistics(self.newsletter)

        self.assertEquals(stats['clicked_links_average'], 0.0)
        self.assertEquals(stats['clicked_links_by_openings'], 0.0)
        self.assertEquals(stats['double_clicked_links'], 0)
        self.assertEquals(stats['double_clicked_links_percent'], 00.0)
        self.assertEquals(stats['double_openings'], 0)
        self.assertEquals(stats['mails_sent'], 4)
        self.assertEquals(stats['mails_to_send'], 4)
        self.assertEquals(stats['opening_average'], 0)
        self.assertEquals(stats['remaining_mails'], 0)
        self.assertEquals(stats['tests_sent'], 1)
        self.assertEquals(stats['top_links'], [])
        self.assertEquals(stats['total_clicked_links'], 0)
        self.assertEquals(stats['total_clicked_links_percent'], 0.0)
        self.assertEquals(stats['total_on_site_openings'], 0)
        self.assertEquals(stats['total_openings'], 0)
        self.assertEquals(stats['total_unsubscriptions'], 0)
        self.assertEquals(stats['total_unsubscriptions_percent'], 0.0)
        self.assertEquals(stats['unique_clicked_links'], 0)
        self.assertEquals(stats['unique_clicked_links_percent'], 0.0)
        self.assertEquals(stats['unique_on_site_openings'], 0)
        self.assertEquals(stats['unique_openings'], 0)
        self.assertEquals(stats['unique_openings_percent'], 0)
        self.assertEquals(stats['unknow_openings'], 0)
        self.assertEquals(stats['unknow_openings_percent'], 0.0)

        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            status=ContactMailingStatus.OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.OPENED_ON_SITE)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[2],
                                            status=ContactMailingStatus.OPENED_ON_SITE)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[1],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            link=self.links[1],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[2],
                                            link=self.links[0],
                                            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.UNSUBSCRIPTION)

        stats = get_newsletter_statistics(self.newsletter)

        self.assertEquals(stats['clicked_links_average'], 1.6666666666666667)
        self.assertEquals(stats['clicked_links_by_openings'], 100.0)
        self.assertEquals(stats['double_clicked_links'], 2)
        self.assertEquals(stats['double_clicked_links_percent'], 50.0)
        self.assertEquals(stats['double_openings'], 2)
        self.assertEquals(stats['mails_sent'], 4)
        self.assertEquals(stats['mails_to_send'], 4)
        self.assertEquals(stats['opening_average'], 1.6666666666666667)
        self.assertEquals(stats['remaining_mails'], 0)
        self.assertEquals(stats['tests_sent'], 1)
        self.assertEquals(stats['total_clicked_links'], 5)
        self.assertEquals(stats['total_clicked_links_percent'], 125.0)
        self.assertEquals(stats['total_on_site_openings'], 2)
        self.assertEquals(stats['total_openings'], 5)
        self.assertEquals(stats['total_unsubscriptions'], 1)
        self.assertEquals(stats['total_unsubscriptions_percent'], 25.0)
        self.assertEquals(stats['unique_clicked_links'], 3)
        self.assertEquals(stats['unique_clicked_links_percent'], 75.0)
        self.assertEquals(stats['unique_on_site_openings'], 2)
        self.assertEquals(stats['unique_openings'], 3)
        self.assertEquals(stats['unique_openings_percent'], 75)
        self.assertEquals(stats['unknow_openings'], 1)
        self.assertEquals(stats['unknow_openings_percent'], 25.0)
示例#8
0
    def test_get_newsletter_statistics(self):
        stats = get_newsletter_statistics(self.newsletter)

        self.assertEquals(stats['clicked_links_average'], 0.0)
        self.assertEquals(stats['clicked_links_by_openings'], 0.0)
        self.assertEquals(stats['double_clicked_links'], 0)
        self.assertEquals(stats['double_clicked_links_percent'], 00.0)
        self.assertEquals(stats['double_openings'], 0)
        self.assertEquals(stats['mails_sent'], 4)
        self.assertEquals(stats['mails_to_send'], 4)
        self.assertEquals(stats['opening_average'], 0)
        self.assertEquals(stats['remaining_mails'], 0)
        self.assertEquals(stats['tests_sent'], 1)
        self.assertEquals(stats['top_links'], [])
        self.assertEquals(stats['total_clicked_links'], 0)
        self.assertEquals(stats['total_clicked_links_percent'], 0.0)
        self.assertEquals(stats['total_on_site_openings'], 0)
        self.assertEquals(stats['total_openings'], 0)
        self.assertEquals(stats['total_unsubscriptions'], 0)
        self.assertEquals(stats['total_unsubscriptions_percent'], 0.0)
        self.assertEquals(stats['unique_clicked_links'], 0)
        self.assertEquals(stats['unique_clicked_links_percent'], 0.0)
        self.assertEquals(stats['unique_on_site_openings'], 0)
        self.assertEquals(stats['unique_openings'], 0)
        self.assertEquals(stats['unique_openings_percent'], 0)
        self.assertEquals(stats['unknow_openings'], 0)
        self.assertEquals(stats['unknow_openings_percent'], 0.0)

        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.OPENED)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            status=ContactMailingStatus.OPENED)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[0],
            status=ContactMailingStatus.OPENED_ON_SITE)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[2],
            status=ContactMailingStatus.OPENED_ON_SITE)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[0],
            link=self.links[0],
            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[0],
            link=self.links[1],
            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[0],
            link=self.links[1],
            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[1],
            link=self.links[0],
            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[2],
            link=self.links[0],
            status=ContactMailingStatus.LINK_OPENED)
        ContactMailingStatus.objects.create(
            newsletter=self.newsletter,
            contact=self.contacts[0],
            status=ContactMailingStatus.UNSUBSCRIPTION)

        stats = get_newsletter_statistics(self.newsletter)

        self.assertEquals(stats['clicked_links_average'], 1.6666666666666667)
        self.assertEquals(stats['clicked_links_by_openings'], 100.0)
        self.assertEquals(stats['double_clicked_links'], 2)
        self.assertEquals(stats['double_clicked_links_percent'], 50.0)
        self.assertEquals(stats['double_openings'], 2)
        self.assertEquals(stats['mails_sent'], 4)
        self.assertEquals(stats['mails_to_send'], 4)
        self.assertEquals(stats['opening_average'], 1.6666666666666667)
        self.assertEquals(stats['remaining_mails'], 0)
        self.assertEquals(stats['tests_sent'], 1)
        self.assertEquals(stats['total_clicked_links'], 5)
        self.assertEquals(stats['total_clicked_links_percent'], 125.0)
        self.assertEquals(stats['total_on_site_openings'], 2)
        self.assertEquals(stats['total_openings'], 5)
        self.assertEquals(stats['total_unsubscriptions'], 1)
        self.assertEquals(stats['total_unsubscriptions_percent'], 25.0)
        self.assertEquals(stats['unique_clicked_links'], 3)
        self.assertEquals(stats['unique_clicked_links_percent'], 75.0)
        self.assertEquals(stats['unique_on_site_openings'], 2)
        self.assertEquals(stats['unique_openings'], 3)
        self.assertEquals(stats['unique_openings_percent'], 75)
        self.assertEquals(stats['unknow_openings'], 1)
        self.assertEquals(stats['unknow_openings_percent'], 25.0)