Add test for following a user through the web UI

Esse commit está contido em:
Gergely Polonkai 2018-07-12 08:12:42 +02:00
commit 36c2f0fd77
2 arquivos alterados com 34 adições e 13 exclusões

Ver arquivo

@ -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()

Ver arquivo

@ -18,9 +18,9 @@
"""
import calsocial
from calsocial.models import db, Notification, NotificationAction, Profile, User
from calsocial.models import db, Notification, NotificationAction, Profile, User, UserFollow
from helpers import database
from helpers import client, database, login
def test_profile_follow(database):
@ -53,3 +53,32 @@ def test_profile_follow(database):
assert follower in followed.follower_list
assert followed in follower.followed_list
def test_follow_ui(client):
"""Test following on the web interface
"""
with calsocial.app.app_context():
follower_user = User(username='follower',
email='follower@example.com',
password='passworder',
active=True)
followed_user = User(username='followed', email='followed@example.com')
follower = Profile(display_name='Follower', user=follower_user)
followed = Profile(display_name='Followed', user=followed_user)
db.session.add_all([follower, followed])
db.session.commit()
login(client, 'follower', 'passworder')
page = client.get('/profile/@followed/follow')
assert page.status_code == 302
assert page.location == 'http://localhost/profile/%40followed'
with calsocial.app.app_context():
db.session.add_all([follower, followed])
follow = UserFollow.query.one()
assert follow.follower == follower
assert follow.followed == followed
assert follow.accepted_at is not None