kopia lustrzana https://gitlab.com/marnanel/chapeau
Check both following and followed views
rodzic
5ea5e6193f
commit
27c218e42b
|
@ -118,12 +118,20 @@ class CollectionView(ActivityObjectView):
|
||||||
def _stringify_object(self, obj):
|
def _stringify_object(self, obj):
|
||||||
return str(obj)
|
return str(obj)
|
||||||
|
|
||||||
|
class FollowingView(CollectionView):
|
||||||
|
|
||||||
|
def get_collection_items(self, *args, **kwargs):
|
||||||
|
return Following.objects.filter(follower__url=kwargs['url'])
|
||||||
|
|
||||||
|
def _stringify_object(self, obj):
|
||||||
|
return obj.following.url
|
||||||
|
|
||||||
class FollowersView(CollectionView):
|
class FollowersView(CollectionView):
|
||||||
|
|
||||||
def get_collection_items(self, *args, **kwargs):
|
def get_collection_items(self, *args, **kwargs):
|
||||||
return Following.objects.filter(following__url=kwargs['url'])
|
return Following.objects.filter(following__url=kwargs['url'])
|
||||||
|
|
||||||
def _stringify_object(self, obj):
|
def _stringify_object(self, obj):
|
||||||
return obj.follower.name
|
return obj.follower.url
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,6 @@ urlpatterns = [
|
||||||
path('obj/<id>', ActivityObjectView.as_view()),
|
path('obj/<id>', ActivityObjectView.as_view()),
|
||||||
path('thing-users', ThingUserCollection.as_view()),
|
path('thing-users', ThingUserCollection.as_view()),
|
||||||
path('users/<name>/followers', ThingUserFollowersView.as_view()),
|
path('users/<name>/followers', ThingUserFollowersView.as_view()),
|
||||||
|
path('users/<name>/following', ThingUserFollowingView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ class CollectionTests(TestCase):
|
||||||
expectedOnPage=EXPECTED_SERIALIZATION,
|
expectedOnPage=EXPECTED_SERIALIZATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_followers(self):
|
def test_followers_and_following(self):
|
||||||
|
|
||||||
people = {}
|
people = {}
|
||||||
|
|
||||||
|
@ -145,14 +145,39 @@ class CollectionTests(TestCase):
|
||||||
people[name].save()
|
people[name].save()
|
||||||
|
|
||||||
reln = Following(
|
reln = Following(
|
||||||
follower = people[name].get_actor(),
|
follower = people[name].actor,
|
||||||
following = people['alice'].get_actor(),
|
following = people['alice'].actor,
|
||||||
)
|
)
|
||||||
reln.save()
|
reln.save()
|
||||||
|
|
||||||
|
path = '/users/alice/followers'
|
||||||
|
|
||||||
self.check_collection(
|
self.check_collection(
|
||||||
path='/users/alice/followers',
|
path=path,
|
||||||
expectedTotalItems=3,
|
expectedTotalItems=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.check_collection_page(
|
||||||
|
path=path,
|
||||||
|
page_number=1,
|
||||||
|
expectedTotalItems=3,
|
||||||
|
expectedOnPage=['alice', 'bob', 'carol'],
|
||||||
|
)
|
||||||
|
|
||||||
|
for name in ['alice', 'bob', 'carol']:
|
||||||
|
|
||||||
|
path='/users/{}/following'.format(name)
|
||||||
|
|
||||||
|
self.check_collection(
|
||||||
|
path=path,
|
||||||
|
expectedTotalItems=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.check_collection_page(
|
||||||
|
path=path,
|
||||||
|
page_number=1,
|
||||||
|
expectedTotalItems=1,
|
||||||
|
expectedOnPage=['alice'],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 2.1 on 2018-09-01 16:46
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('django_kepi', '0008_auto_20180830_1354'),
|
||||||
|
('things_for_testing', '0003_auto_20180829_1541'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='thinguser',
|
||||||
|
name='id',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='thinguser',
|
||||||
|
name='actor',
|
||||||
|
field=models.OneToOneField(default=1, on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='django_kepi.Actor'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,5 +1,5 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django_kepi.views import CollectionView, FollowersView
|
from django_kepi.views import *
|
||||||
from django_kepi.models import Following
|
from django_kepi.models import Following
|
||||||
from things_for_testing.models import *
|
from things_for_testing.models import *
|
||||||
|
|
||||||
|
@ -10,6 +10,16 @@ class ThingUserCollection(CollectionView):
|
||||||
def _stringify_object(self, obj):
|
def _stringify_object(self, obj):
|
||||||
return obj.serialize()
|
return obj.serialize()
|
||||||
|
|
||||||
|
class ThingUserFollowingView(FollowingView):
|
||||||
|
|
||||||
|
def get_collection_items(self, *args, **kwargs):
|
||||||
|
kwargs['url'] = 'https://example.com/user/{}'.format(kwargs['name'])
|
||||||
|
|
||||||
|
return super().get_collection_items(*args, **kwargs)
|
||||||
|
|
||||||
|
def _stringify_object(self, obj):
|
||||||
|
return ThingUser.objects.get(actor=obj.following).name
|
||||||
|
|
||||||
class ThingUserFollowersView(FollowersView):
|
class ThingUserFollowersView(FollowersView):
|
||||||
|
|
||||||
def get_collection_items(self, *args, **kwargs):
|
def get_collection_items(self, *args, **kwargs):
|
||||||
|
@ -17,3 +27,7 @@ class ThingUserFollowersView(FollowersView):
|
||||||
|
|
||||||
return super().get_collection_items(*args, **kwargs)
|
return super().get_collection_items(*args, **kwargs)
|
||||||
|
|
||||||
|
def _stringify_object(self, obj):
|
||||||
|
return ThingUser.objects.get(actor=obj.follower).name
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue