From 1dcb6663285ad27ce191ce9b38ff34d9ae5be8a7 Mon Sep 17 00:00:00 2001 From: echoduck Date: Oct 26 2018 21:01:58 +0000 Subject: Changed styling to be consistent with the rest of the sidebar, added tests, and added read messages to the counter. --- diff --git a/happinesspackets/messaging/context_processors.py b/happinesspackets/messaging/context_processors.py index 1c4672e..29eff6a 100644 --- a/happinesspackets/messaging/context_processors.py +++ b/happinesspackets/messaging/context_processors.py @@ -1,5 +1,5 @@ from .models import Message def packets_sent_processor(request): - packets_sent = Message.objects.filter(status="sent").count() + packets_sent = Message.objects.exclude(status="pending_sender_confirmation").count() return {'packets_sent': packets_sent} diff --git a/happinesspackets/messaging/tests/test_views.py b/happinesspackets/messaging/tests/test_views.py index e5db934..e104640 100644 --- a/happinesspackets/messaging/tests/test_views.py +++ b/happinesspackets/messaging/tests/test_views.py @@ -11,6 +11,25 @@ from .test_models import MessageModelFactory, BlacklistedEmailFactory from ..models import Message, BLACKLIST_HMAC_SALT, BlacklistedEmail +class MessageCounterTest(TestCase): + url = reverse('messaging:start') + + def test_message_sent_included(self): + msg = MessageModelFactory(status="sent") + response = self.client.get(self.url) + self.assertContains(response,"Packets sent: 1") + + def test_message_read_included(self): + msg = MessageModelFactory(status="read") + response = self.client.get(self.url) + self.assertContains(response,"Packets sent: 1") + + def test_message_to_be_confirmed_excluded(self): + msg = MessageModelFactory(status="pending_sender_confirmation") + response = self.client.get(self.url) + self.assertContains(response,"Packets sent: 0") + + class StartViewTest(TestCase): url = reverse('messaging:start') diff --git a/templates/base.html b/templates/base.html index 8752223..ad8a9a7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -26,6 +26,7 @@ {% url 'messaging:start' as url %} -

Packets sent: {{ packets_sent }}