Beispiel #1
0
    def _build_activity_data(self, stream_activity, activity_data):
        from stream_django.activity import create_reference
        data = activity_data.copy()
        data.update({
            'original_foreign_id': data['foreign_id'],
            'original_object': data['object']
        })
        data['foreign_id'] = create_reference(stream_activity)
        data['object'] = create_reference(stream_activity)

        return data
Beispiel #2
0
    def _build_activity_data(self, stream_activity, activity_data):
        from stream_django.activity import create_reference
        data = activity_data.copy()
        data.update({
            'original_foreign_id': data['foreign_id'],
            'original_object': data['object']
        })
        data['foreign_id'] = create_reference(stream_activity)
        data['object'] = create_reference(stream_activity)

        return data
    def test_update_or_create_activity_returns_updated_existing_activity(self):
        time = datetime.datetime.now()
        activity_data = {
            'actor': 'auth.User:42',
            'foo': 'Foobar',
            'baz': ['foo', 'bar'],
            'foreign_id': 'foos.Foo:42',
            'object': 'foos.Foo:42',
            'time': time,
            'verb': 'fooed'
        }

        stream_activity = StreamActivity.objects.create_activity(activity_data)

        new_time = datetime.datetime.now()

        new_activity_data = {
            'actor': 'auth.User:42',
            'foo': 'Foobar',
            'baz': ['foo', 'bar', 'baz'],
            'foreign_id': 'foos.Foo:42',
            'object': 'foos.Foo:42',
            'time': new_time,
            'verb': 'fooed'
        }

        updated_stream_activity = StreamActivity.objects.update_or_create_activity(
            new_activity_data)

        self.assertEqual(stream_activity.pk, updated_stream_activity.pk)
        self.assertEqual(
            updated_stream_activity.data, {
                'actor': 'auth.User:42',
                'foo': 'Foobar',
                'baz': ['foo', 'bar', 'baz'],
                'original_foreign_id': 'foos.Foo:42',
                'original_object': 'foos.Foo:42',
                'foreign_id': create_reference(updated_stream_activity),
                'object': create_reference(updated_stream_activity),
                'time': new_time,
                'verb': 'fooed'
            })
    def test_create_activity(self):
        pin = models.Pin.objects.create(author=self.user)
        time = datetime.datetime.now()
        activity_data = {
            'actor': 'auth.User:{}'.format(self.user.pk),
            'foo': 'Foobar',
            'baz': ['foo', 'bar'],
            'foreign_id': 'test_app.Pin:{}'.format(pin.pk),
            'object': 'test_app.Pin:{}'.format(pin.pk),
            'time': time,
            'verb': 'fooed'
        }

        stream_activity = StreamActivity.objects.create_activity(activity_data)

        self.assertEqual(
            stream_activity.data, {
                'actor': 'auth.User:{}'.format(self.user.pk),
                'foo': 'Foobar',
                'baz': ['foo', 'bar'],
                'original_foreign_id': 'test_app.Pin:{}'.format(pin.pk),
                'original_object': 'test_app.Pin:{}'.format(pin.pk),
                'foreign_id': create_reference(stream_activity),
                'object': create_reference(stream_activity),
                'time': time,
                'verb': 'fooed'
            })

        self.assertEqual(stream_activity.actor,
                         'auth.User:{}'.format(self.user.pk))
        self.assertEqual(stream_activity.verb, 'fooed')
        self.assertEqual(stream_activity.original_foreign_id,
                         'test_app.Pin:{}'.format(pin.pk))
        self.assertEqual(stream_activity.content_object, pin)
        self.assertEqual(StreamActivity.objects.get_for_original_object(pin),
                         stream_activity)
Beispiel #5
0
 def test_create_reference_to_model(self):
     data = 'not-a-model'
     ref = create_reference(data)
     self.assertEqual(ref, data)
 def test_create_reference_to_model(self):
     data = 'not-a-model'
     ref = create_reference(data)
     self.assertEqual(ref, data)
Beispiel #7
0
 def activity_foreign_id(self):
     return create_reference(self)