Skip to content

Commit 829b854

Browse files
committed
Add test.
1 parent 82aaf37 commit 829b854

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tests/tests.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from django.contrib import auth
2+
from django.contrib.auth.models import User
3+
from django.contrib.messages import constants
14
from django.test import TestCase
25
from django.test.client import Client
3-
from django.contrib.auth.models import User
4-
from django.contrib.messages import constants, set_level
56

6-
from async_messages import message_user, message_users, messages
7+
from async_messages import (
8+
message_user, message_users, messages, AsyncMessageException,
9+
)
710

811

912
class MiddlewareTests(TestCase):
@@ -44,6 +47,16 @@ def test_anonymous(self):
4447
msgs = list(response.context['messages'])
4548
self.assertEqual(0, len((msgs)))
4649

50+
def test_anonymous_message(self):
51+
client = Client()
52+
user = auth.get_user(client)
53+
54+
with self.assertRaises(AsyncMessageException) as e:
55+
message_user(user, "Second Message")
56+
57+
self.assertEqual(str(e.exception),
58+
'Anonymous users cannot send messages.')
59+
4760

4861
class TestMessagesApi(TestCase):
4962
def setUp(self):

0 commit comments

Comments
 (0)