Beispiel #1
0
    def activity_create(self, activity, **kwargs):
        """
        Creates an activity. You can provide objects for activities as dictionaries or as ids for already
        existing objects.

        If you provide a dictionary for an object, it is saved as a new object.

        If you provide an object id and the object does not exist, it is saved anyway, and returned as an empty
        dictionary when retriving the activity later.
        """
        activity = Activity(activity, backend=self)

        activity.validate()
        activity_dict = activity.get_parsed_dict()

        key = self._extract_id(activity_dict)

        riak_obj = self._activities.new(key=key)
        riak_obj.data = activity_dict
        riak_obj = self.set_activity_indexes(self.set_general_indexes(riak_obj))
        if activity_dict['verb'] in SUB_ACTIVITY_MAP:
            riak_obj = self.set_sub_item_indexes(riak_obj, **kwargs)

        riak_obj.store()

        return self.dehydrate_activities([riak_obj.data])[0]
Beispiel #2
0
    def activity_create(self, activity, **kwargs):
        """
        Creates an activity. This assumes the activity is already dehydrated (ie has refrences
        to the objects and not the actual objects itself)
        """
        activity = Activity(activity, backend=self)

        activity.validate()
        activity_dict = activity.get_parsed_dict()

        activity_db_schema_dict = self._activity_dict_to_db_schema(activity_dict)

        self.engine.execute(self.activities_table.insert(), [activity_db_schema_dict])

        return self.get_activity(activity_dict, include_public=True)
    def test_parse_data_with_audience_targeting(self):
        act = Activity({
                'id': '4213',
                'to': [{'objectType': 'user1', 'id': 'user:id:1', 'published': '2012-07-05T12:00:00Z'}, {'objectType': 'user2', 'id': 'user:id:2', 'published': '2012-07-05T12:00:00Z'}],
                'bto': [{'objectType': 'user3', 'id': 'user:id:3', 'published': '2012-07-05T12:00:00Z'}, {'objectType': 'user4', 'id': 'user:id:4', 'published': '2012-07-05T12:00:00Z'}, {'objectType': 'user5', 'id': 'user:id:5', 'published': '2012-07-05T12:00:00Z'}],
                'cc': [{'objectType': 'user6', 'id': 'user:id:6', 'published': '2012-07-05T12:00:00Z'}],
                'bcc': [],
            }, backend=MagicMock())

        act_dict = act.parse_data(act._dict)
        eq_({
            'cc': [{'published': '2012-07-05T12:00:00Z', 'id': 'user:id:6', 'objectType': 'user6'}],
            'bcc': [],
            'to': [{'published': '2012-07-05T12:00:00Z', 'id': 'user:id:1', 'objectType': 'user1'}, {'published': '2012-07-05T12:00:00Z', 'id': 'user:id:2', 'objectType': 'user2'}],
            'bto': [{'published': '2012-07-05T12:00:00Z', 'id': 'user:id:3', 'objectType': 'user3'}, {'published': '2012-07-05T12:00:00Z', 'id': 'user:id:4', 'objectType': 'user4'}, {'published': '2012-07-05T12:00:00Z', 'id': 'user:id:5', 'objectType': 'user5'}], 'id': '4213'
        }, act_dict)
    def test_parse_data(self):

        act = Activity({"id": 5, "verb": "post", \
            "actor": {"objectType": "actor", "id": 1232, "published": '2012-07-05T12:00:00Z'}, \
            "target": {"objectType": "target", "id": 4325, "published": '2012-07-05T12:00:00Z'}, \
            "object": {"objectType": "something", "id": 4353, "published": '2012-07-05T12:00:00Z'},
            "icon": {'url': "http://example.org/something"}}, backend=MagicMock())

        act_dict = act.parse_data(act._dict)

        eq_({
            'target': {'objectType': 'target', 'id': 4325, 'published': '2012-07-05T12:00:00Z'},
            'object': {'objectType': 'something', 'id': 4353, 'published': '2012-07-05T12:00:00Z'},
            'actor': {'objectType': 'actor', 'id': 1232, 'published': '2012-07-05T12:00:00Z'},
            'verb': 'post',
            'id': '5',
            'icon': {'url': 'http://example.org/something'}
        }, act_dict)
Beispiel #5
0
    def test_parse_data_with_audience_targeting(self):
        act = Activity(
            {
                'id':
                '4213',
                'to': [{
                    'objectType': 'user1',
                    'id': 'user:id:1',
                    'published': '2012-07-05T12:00:00Z'
                }, {
                    'objectType': 'user2',
                    'id': 'user:id:2',
                    'published': '2012-07-05T12:00:00Z'
                }],
                'bto': [{
                    'objectType': 'user3',
                    'id': 'user:id:3',
                    'published': '2012-07-05T12:00:00Z'
                }, {
                    'objectType': 'user4',
                    'id': 'user:id:4',
                    'published': '2012-07-05T12:00:00Z'
                }, {
                    'objectType': 'user5',
                    'id': 'user:id:5',
                    'published': '2012-07-05T12:00:00Z'
                }],
                'cc': [{
                    'objectType': 'user6',
                    'id': 'user:id:6',
                    'published': '2012-07-05T12:00:00Z'
                }],
                'bcc': [],
            },
            backend=MagicMock())

        act_dict = act.parse_data(act._dict)
        eq_(
            {
                'cc': [{
                    'published': '2012-07-05T12:00:00Z',
                    'id': 'user:id:6',
                    'objectType': 'user6'
                }],
                'bcc': [],
                'to': [{
                    'published': '2012-07-05T12:00:00Z',
                    'id': 'user:id:1',
                    'objectType': 'user1'
                }, {
                    'published': '2012-07-05T12:00:00Z',
                    'id': 'user:id:2',
                    'objectType': 'user2'
                }],
                'bto': [{
                    'published': '2012-07-05T12:00:00Z',
                    'id': 'user:id:3',
                    'objectType': 'user3'
                }, {
                    'published': '2012-07-05T12:00:00Z',
                    'id': 'user:id:4',
                    'objectType': 'user4'
                }, {
                    'published': '2012-07-05T12:00:00Z',
                    'id': 'user:id:5',
                    'objectType': 'user5'
                }],
                'id':
                '4213'
            }, act_dict)
 def test_required_fields_no_id(self):
     act = Activity({"title": "Stream Item", "verb": "post", \
         "actor": {"objectType": "something", "id": 1232, "published": "today"}, \
         "object": {"objectType": "something", "id": 4353, "published": "today"}}, backend=MagicMock())
     act.validate()
     ok_(act.get_dict()["id"])