Exemple #1
0
 def test_raises_recipient_mismatch_error_if_user_is_not_recipient_of_notification(
         self):
     self.base_set_up(create_user=True)
     self.notification = Notification.objects.create_new_challenge_notification(
         recipient=self.auth_user, challenge=self.challenge)
     self.user_obj_mock.id = 111
     with patch('notifications.handlers.ws_connections',
                {111: self.user_connection_mock}) as mock_conn:
         with self.assertRaises(RecipientMismatchError):
             _read_notification('notification_token', 111,
                                self.notification.id)
             self.user_connection_mock.user.notification_token_is_valid.assert_called_once_with(
                 'notification_token')
Exemple #2
0
    def test_sets_notif_is_read(self):
        self.base_set_up(create_user=True)
        self.notification = Notification.objects.create_new_challenge_notification(
            recipient=self.auth_user, challenge=self.challenge)
        self.user_obj_mock.id = self.auth_user.id
        with patch(
                'notifications.handlers.ws_connections',
            {self.auth_user.id: self.user_connection_mock}) as mock_conn:
            _read_notification('notification_token', self.auth_user.id,
                               self.notification.id)

            self.user_connection_mock.user.notification_token_is_valid.assert_called_once_with(
                'notification_token')

            self.notification.refresh_from_db()
            self.assertTrue(self.notification.is_read)
Exemple #3
0
 def test_invalid_token_raises_invalid_notification_token(self):
     self.user_obj_mock.notification_token_is_valid.return_value = False
     with patch('notifications.handlers.ws_connections',
                self.ws_connections_mock):
         with self.assertRaises(InvalidNotificationToken):
             _read_notification('', self.user_id, 1)
Exemple #4
0
 def test_raises_offline_recipient_error_if_user_not_connected(self):
     self.user_connection_mock.is_valid = False
     with patch('notifications.handlers.ws_connections',
                self.ws_connections_mock):
         with self.assertRaises(OfflineRecipientError):
             _read_notification('', self.user_id, 1)
Exemple #5
0
 def test_raises_offline_recipient_error_if_user_not_authenticated(self):
     with patch('notifications.handlers.ws_connections',
                self.ws_connections_mock):
         with self.assertRaises(OfflineRecipientError):
             _read_notification('', self.user_id + 1, 1)