def test_get_newsletter_top_links(self):
        stats = get_newsletter_top_links(self.status)
        self.assertEquals(stats['top_links'], [])

        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[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[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)
        status = ContactMailingStatus.objects.filter(newsletter=self.newsletter)

        stats = get_newsletter_top_links(status)
        self.assertEquals(len(stats['top_links']), 2)
        self.assertEquals(stats['top_links'][0]['link'], self.links[0])
        self.assertEquals(stats['top_links'][0]['total_clicks'], 4)
        self.assertEquals(stats['top_links'][0]['unique_clicks'], 3)
        self.assertEquals(stats['top_links'][1]['link'], self.links[1])
        self.assertEquals(stats['top_links'][1]['total_clicks'], 1)
        self.assertEquals(stats['top_links'][1]['unique_clicks'], 1)
def view_newsletter_density(request, slug):
    newsletter = get_object_or_404(Newsletter, slug=slug)
    status = ContactMailingStatus.objects.filter(newsletter=newsletter,
                                                 creation_date__gte=newsletter.sending_date)
    context = {'object': newsletter,
               'top_links': get_newsletter_top_links(status)['top_links']}

    return render_to_response('newsletter/newsletter_density.html',
                              context, context_instance=RequestContext(request))
Exemple #3
0
def view_newsletter_density(request, slug):
    newsletter = get_object_or_404(Newsletter, slug=slug)
    status = ContactMailingStatus.objects.filter(
        newsletter=newsletter, creation_date__gte=newsletter.sending_date)
    context = {
        'object': newsletter,
        'top_links': get_newsletter_top_links(status)['top_links']
    }

    return render_to_response('newsletter/newsletter_density.html',
                              context,
                              context_instance=RequestContext(request))
    def test_get_newsletter_top_links(self):
        stats = get_newsletter_top_links(self.status)
        self.assertEquals(stats['top_links'], [])

        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[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[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)
        status = ContactMailingStatus.objects.filter(
            newsletter=self.newsletter)

        stats = get_newsletter_top_links(status)
        self.assertEquals(len(stats['top_links']), 2)
        self.assertEquals(stats['top_links'][0]['link'], self.links[0])
        self.assertEquals(stats['top_links'][0]['total_clicks'], 4)
        self.assertEquals(stats['top_links'][0]['unique_clicks'], 3)
        self.assertEquals(stats['top_links'][1]['link'], self.links[1])
        self.assertEquals(stats['top_links'][1]['total_clicks'], 1)
        self.assertEquals(stats['top_links'][1]['unique_clicks'], 1)