Add test for following a user through the web UI

This commit is contained in:
2018-07-12 08:12:42 +02:00
parent 27c78ff36f
commit 36c2f0fd77
2 changed files with 34 additions and 13 deletions

View File

@@ -300,11 +300,12 @@ class CalendarSocialApp(Flask):
@staticmethod
@route('/profile/@<string:username>/follow')
@login_required
def follow_user(username):
"""View for following a user
"""
from .models import db, Profile, User, UserFollow, Notification, NotificationAction
from .models import db, Profile, User
try:
profile = Profile.query.join(User).filter(User.username == username).one()
@@ -312,16 +313,7 @@ class CalendarSocialApp(Flask):
abort(404)
if profile.user != current_user:
follow = UserFollow(follower=current_user.profile,
followed=profile,
accepted_at=datetime.utcnow())
db.session.add(follow)
notification = Notification(profile=profile,
actor=current_user.profile,
item=profile,
action=NotificationAction.follow)
db.session.add(notification)
profile.follow(follower=current_user.profile)
db.session.commit()