forked from gergely/calendar-social
Add test for following a user through the web UI
This commit is contained in:
parent
27c78ff36f
commit
36c2f0fd77
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user