Esempio n. 1
0
 def test_is_similar_default(self):
     notification = mod.Notification('uid',
                                     'msg',
                                     'now',
                                     category='content',
                                     read_at='now',
                                     username='******',
                                     db=mock.Mock())
     group = mod.NotificationGroup([notification])
     similar = mod.Notification('uid',
                                'msg',
                                'now',
                                category='content',
                                read_at='now',
                                username='******',
                                db=mock.Mock())
     different1 = mod.Notification('uid',
                                   'msg',
                                   'now',
                                   category='other',
                                   read_at='now',
                                   username='******',
                                   db=mock.Mock())
     different2 = mod.Notification('uid',
                                   'msg',
                                   'now',
                                   category='content',
                                   read_at='yesterday',
                                   username='******',
                                   db=mock.Mock())
     assert group.is_similar(similar, attrs=('category', 'read_at'))
     assert not group.is_similar(different1, attrs=('category', 'read_at'))
     assert not group.is_similar(different2, attrs=('category', 'read_at'))
Esempio n. 2
0
    def test_is_shared(self):
        notification = mod.Notification('id',
                                        'msg',
                                        'created_at',
                                        db=mock.Mock())
        assert notification.is_shared

        notification = mod.Notification('id',
                                        'msg',
                                        'created_at',
                                        username='******',
                                        db=mock.Mock())
        assert not notification.is_shared
Esempio n. 3
0
 def test_group_by(self):
     notifications = []
     fixtures = [
         dict(category='content'),
         dict(category='content'),
         dict(category='content', groupable=False),
         dict(),
         dict(),
         dict(category='alarm'),
         dict(category='alarm')
     ]
     for idx, options in enumerate(fixtures):
         notifications.append(
             mod.Notification('uid' + str(idx),
                              'msg',
                              'now',
                              username='******',
                              db=mock.Mock(),
                              **options))
     groups = mod.NotificationGroup.group_by(iter(notifications),
                                             by=('category', 'read_at'))
     assert len(groups) == 5
     assert groups[0].count == 2  # content
     assert groups[1].count == 1  # content - not groupable
     assert groups[2].count == 1  # empty
     assert groups[3].count == 1  # empty
     assert groups[4].count == 2  # alarm
Esempio n. 4
0
 def test_is_read_false(self, read_at):
     read_at.__get__ = mock.Mock(return_value=None)
     notification = mod.Notification('unique_id',
                                     'msg',
                                     'today',
                                     db=mock.Mock())
     assert not notification.is_read
Esempio n. 5
0
 def test__mark_shared_read_creates(self, request):
     request.user.options = {}
     notification = mod.Notification('unique_id',
                                     'msg',
                                     'today',
                                     db=mock.Mock())
     notification._mark_shared_read('now')
     assert request.user.options == {'notifications': {'unique_id': 'now'}}
Esempio n. 6
0
 def test_read_at_private(self, is_shared):
     is_shared.__get__ = mock.Mock(return_value=False)
     notification = mod.Notification('id',
                                     'msg',
                                     'today',
                                     read_at='now',
                                     db=mock.Mock())
     assert notification.read_at == 'now'
Esempio n. 7
0
 def test_read_at_shared(self, is_shared, request):
     is_shared.__get__ = mock.Mock(return_value=True)
     request.user.options.get.return_value = {'unique_id': 'sometime'}
     notification = mod.Notification('unique_id',
                                     'msg',
                                     'today',
                                     db=mock.Mock())
     assert notification.read_at == 'sometime'
Esempio n. 8
0
 def test_mark_read_already_read(self, is_read, _mark_shared_read,
                                 _mark_private_read):
     is_read.__get__ = mock.Mock(return_value=True)
     notification = mod.Notification('unique_id',
                                     'msg',
                                     'today',
                                     db=mock.Mock())
     notification.mark_read()
     assert not _mark_private_read.called
     assert not _mark_shared_read.called
Esempio n. 9
0
    def test_has_expired(self):
        notification = mod.Notification('id',
                                        'msg',
                                        'created_at',
                                        db=mock.Mock())
        assert not notification.has_expired

        expires_at = mod.utcnow() + datetime.timedelta(days=1)
        notification = mod.Notification('id',
                                        'msg',
                                        'created_at',
                                        expires_at=expires_at,
                                        db=mock.Mock())
        assert not notification.has_expired

        expires_at = mod.utcnow() - datetime.timedelta(days=1)
        notification = mod.Notification('id',
                                        'msg',
                                        'created_at',
                                        expires_at=expires_at,
                                        db=mock.Mock())
        assert notification.has_expired
Esempio n. 10
0
 def test__mark_shared_read_updates(self, request):
     request.user.options = {'notifications': {'previous': 'yesterday'}}
     notification = mod.Notification('unique_id',
                                     'msg',
                                     'today',
                                     db=mock.Mock())
     notification._mark_shared_read('now')
     expected = {
         'notifications': {
             'previous': 'yesterday',
             'unique_id': 'now'
         }
     }
     assert request.user.options == expected
Esempio n. 11
0
 def test_delete(self):
     db = mock.Mock()
     transaction = mock.Mock()
     ctx_manager = mock.MagicMock()
     ctx_manager.__enter__.return_value = transaction
     db.transaction.return_value = ctx_manager
     notification = mod.Notification('unique_id', 'msg', 'today', db=db)
     notification.delete()
     transaction.execute.assert_has_calls([
         mock.call(db.Delete.return_value.serialize.return_value,
                   ('unique_id', )),
         mock.call(db.Delete.return_value.serialize.return_value,
                   ('unique_id', ))
     ])
Esempio n. 12
0
 def test_save(self):
     db = mock.Mock()
     notification = mod.Notification('unique_id', 'msg', 'today', db=db)
     notification.save()
     data = dict(category=None,
                 notification_id='unique_id',
                 read_at=None,
                 created_at='today',
                 expires_at=None,
                 dismissable=True,
                 groupable=True,
                 priority=mod.Notification.NORMAL,
                 username=None,
                 message='msg',
                 icon=None)
     db.execute.assert_called_once_with(db.Replace.return_value, data)
Esempio n. 13
0
    def test_mark_read_private(self, is_read, is_shared, _mark_private_read,
                               utcnow):
        is_read.__get__ = mock.Mock(return_value=False)
        is_shared.__get__ = mock.Mock(return_value=False)
        notification = mod.Notification('unique_id',
                                        'msg',
                                        'today',
                                        db=mock.Mock())
        notification.mark_read('now')
        _mark_private_read.assert_called_once_with('now')

        _mark_private_read.reset_mock()

        utcnow.return_value = 'proper date'
        notification.mark_read()
        _mark_private_read.assert_called_once_with('proper date')
Esempio n. 14
0
 def test__mark_private_read(self, request):
     db = mock.Mock()
     notification = mod.Notification('unique_id', 'msg', 'today', db=db)
     notification._mark_private_read('now')
     data = dict(notification_id='unique_id', read_at='now')
     db.execute.assert_called_once_with(db.Update.return_value, data)
Esempio n. 15
0
 def test_add(self):
     notification = mod.Notification('uid', 'msg', 'now', db=mock.Mock())
     group = mod.NotificationGroup()
     group.add(notification)
     assert group.notifications == [notification]
Esempio n. 16
0
 def test_count(self):
     notification = mod.Notification('uid', 'msg', 'now', db=mock.Mock())
     notification2 = mod.Notification('uid2', 'msg', 'now', db=mock.Mock())
     group = mod.NotificationGroup([notification, notification2])
     assert group.count == 2
Esempio n. 17
0
 def test_notification_attrs(self, request):
     notification = mod.Notification('uid', 'msg', 'now', db=mock.Mock())
     group = mod.NotificationGroup([notification])
     for attr in mod.NotificationGroup.proxied_attrs:
         assert getattr(group, attr) == getattr(notification, attr)