Esempio n. 1
0
def test_from_dict_missing_keys():
    d = {
        "actor": actor
    }
    with pytest.raises(InvalidNotificationError) as e:
        Notification.from_dict(d)
    assert "Missing keys" in str(e.value)

    with pytest.raises(InvalidNotificationError) as e:
        Notification.from_dict(None)
    assert "Can only run 'from_dict' on a dict" in str(e.value)
Esempio n. 2
0
 def get_activities(self,
                    count=10,
                    include_seen=False,
                    level=None,
                    verb=None,
                    reverse=False,
                    user_view=False) -> List[Notification]:
     """
     Returns a selection of activities.
     :param count: Maximum number of Notifications to return (default 10)
     """
     # steps.
     # 0. If in cache, return them.  <-- later
     # 1. Get storage adapter.
     # 2. Query it for recent activities from this user.
     # 3. Cache them here.
     # 4. Return them.
     if count < 1 or not isinstance(count, int):
         raise ValueError("Count must be an integer > 0")
     serial_notes = self.timeline_storage.get_timeline(
         count=count,
         include_seen=include_seen,
         level=level,
         verb=verb,
         reverse=reverse)
     note_list = list()
     user_dict = self.user.to_dict()
     for note in serial_notes:
         if user_dict in note["unseen"]:
             note["seen"] = False
         else:
             note["seen"] = True
         note_list.append(Notification.from_dict(note, self.token))
     return note_list
Esempio n. 3
0
 def get_notification(self, note_id):
     """
     Returns a single notification.
     If it doesn't exist (either the user can't see it, or it's really not there), raises
     a NotificationNotFoundError.
     """
     note = self.timeline_storage.get_single_activity_from_timeline(note_id)
     if note is None:
         raise NotificationNotFoundError(
             "Cannot find notification with id {}.".format(note_id))
     else:
         return Notification.from_dict(note, self.token)
Esempio n. 4
0
def test_from_dict():
    act_id = str(uuid.uuid4())
    verb = [verb_id, str(verb_id), verb_inf, verb_past]
    level = [level_id, level_name, str(level_id)]
    d = {
        "actor": actor_d,
        "object": object_d,
        "source": source,
        "expires": 1234567890111,
        "created": 1234567890000,
        "target": [target_d],
        "context": context,
        "external_key": external_key,
        "id": act_id,
        "users": [user_d]
    }
    # just being lazy and putting in the real Entity objects
    d_cmp = {
        "actor": actor,
        "object": note_object,
        "source": source,
        "expires": 1234567890111,
        "created": 1234567890000,
        "target": target,
        "context": context,
        "external_key": external_key,
        "id": act_id,
        "users": users
    }
    for v in verb:
        for l in level:
            note_d = d.copy()
            note_d_cmp = d_cmp.copy()
            note_d.update({'level': l, 'verb': v})
            note_d_cmp.update({'level': l, 'verb': v})
            note = Notification.from_dict(note_d)
            assert_note_ok(note, **note_d_cmp)