@@ -81,6 +81,7 @@ class AnnouncementViewSetTestCase(BaseAPITestCase):
8181 "test_events.yaml" ,
8282 "test_companies.yaml" ,
8383 "test_announcements.yaml" ,
84+ "test_meetings.yaml" ,
8485 ]
8586
8687 def setUp (self ):
@@ -238,3 +239,59 @@ def test_send_announcement_unauthorized(self):
238239 self .client .force_authenticate (self .unauthorized_user )
239240 response = self .client .post (f"{ self .url } { self .unsent_announcement .id } /send/" )
240241 self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
242+
243+ def test_send_announcement_twice (self ):
244+ """
245+ An announcement can not be sent twice
246+ """
247+
248+ self .client .force_authenticate (self .authorized_user )
249+ response = self .client .post (f"{ self .url } { self .unsent_announcement .id } /send/" )
250+ self .assertEqual (response .status_code , status .HTTP_202_ACCEPTED )
251+ response = self .client .post (f"{ self .url } { self .unsent_announcement .id } /send/" )
252+ self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
253+
254+ def test_recipients_lookup_to_users (self ):
255+ """
256+ An announcement should be sent to the specified users
257+ """
258+
259+ announcement = Announcement .objects .get (pk = 4 )
260+ recipients = announcement .lookup_recipients ()
261+ self .assertEqual (len (recipients ), 3 )
262+
263+ def test_recipients_lookup_for_event (self ):
264+ """
265+ Everyone registered to an event should receive the announcement
266+ """
267+ announcement = Announcement .objects .get (pk = 7 )
268+ recipients = announcement .lookup_recipients ()
269+ self .assertEqual (len (recipients ), 3 )
270+
271+ def test_recipients_lookup_for_event_exclude_waiting_list (self ):
272+ """
273+ Everyone registered to an event, except those on waiting list,
274+ should receive the announcement
275+ """
276+
277+ announcement = Announcement .objects .get (pk = 8 )
278+ recipients = announcement .lookup_recipients ()
279+ self .assertEqual (len (recipients ), 2 )
280+
281+ def test_recipients_lookup_for_meeting (self ):
282+ """
283+ Everyone invited to a meeting should receive the announcement
284+ """
285+
286+ announcement = Announcement .objects .get (pk = 9 )
287+ recipients = announcement .lookup_recipients ()
288+ self .assertEqual (len (recipients ), 2 )
289+
290+ def test_recipients_lookup_for_only_meeting_attendees (self ):
291+ """
292+ Only those invited to a meeting and accepted should receive the announcement
293+ """
294+
295+ announcement = Announcement .objects .get (pk = 10 )
296+ recipients = announcement .lookup_recipients ()
297+ self .assertEqual (len (recipients ), 1 )
0 commit comments