Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (77 sloc) 3.09 KB
import unittest
import tempfile
import os
import circles.main
import circles
from circles.main import db, app
from circles.main import *
from werkzeug import generate_password_hash
from flaskext.testing import TestCase
class FlaskTestCase(unittest.TestCase):
def setUp(self): = app.test_client()
# fixtures
joe = User()
cred = PasswordCredentials(user=joe, login='joe')
circle = Circle(name="Circle of Joe")
member = Member(circle=circle, user=joe, nickname='Not Joe')
invitation = Invitation(inviter=member, circle=circle)
db.session.commit() = circle
self.invitation = invitation
def tearDown(self):
def register(self, *args):
return self.login(*args, action='register')
def login(self, login, password, action='login'):
return'/login', data=dict(
), follow_redirects=True)
def logout(self):
return'/logout', follow_redirects=True)
class TestLogins(FlaskTestCase):
def test_front_page(self):
rv ='/')
assert 'Circles' in
assert 'Create a circle' not in
def test_register_logout_login(self):
rv = self.register('fred','fred')
assert 'Create a circle' in
rv = self.logout()
assert 'Create a circle' not in
class TestInvitations(FlaskTestCase):
def test_visiting_your_circle(self):
rv ='/circles/%s' %
assert rv.status_code == 200
rv ='/circles/%s/invite' %
assert rv.status_code == 200
def test_inviting_someone(self):
with app.test_request_context():
url = self.invitation.url[len('http://localhost'):]
# Invite should give you access to joe's circle
rv =, follow_redirects=True)
assert in
#assert 'form' not in # not logged in, so no forms
# See that this invitation is listed on the front page
rv ='/')
assert 'invited you' in
# Try to join the group. It makes you register
rv ='/circles/%s/join' %, follow_redirects=True)
assert 'Login or Register' in
rv = self.register('bob','bob')
rv ='/circles/%s/join' %, follow_redirects=True)
assert '<h1>Join' in
rv ='/circles/%s/join' %, follow_redirects=True, data=dict(nickname='Bob'))
assert rv.status_code == 200
# make sure the invitation is cleared away
rv ='/')
assert 'invited you' not in
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.