Esempio n. 1
0
 def test_create_tables(self):
     """Test that model.create_tables correctly creates all database tables."""
     self.assertRaises(OperationalError, User.by_user_name, u'test')
     create_tables()
     assert _create_test_user()
     create_tables()
     assert User.by_user_name(u'creosote')
     create_tables(drop_all=True)
     user = User.by_user_name(u'creosote')
     assert user is None
Esempio n. 2
0
 def test_create_tables(self):
     """Test that model.create_tables correctly creates all database tables."""
     self.assertRaises(OperationalError, User.by_user_name, u'test')
     create_tables()
     assert _create_test_user()
     create_tables()
     assert User.by_user_name(u'creosote')
     create_tables(drop_all=True)
     user = User.by_user_name(u'creosote')
     assert user is None
Esempio n. 3
0
def _create_test_user():
    obj = User()
    obj.user_name = u"creosote"
    obj.email_address = u"*****@*****.**"
    obj.display_name = u"Mr Creosote"
    obj.password = u"Wafer-thin Mint"
    # mark object as 'to be saved'
    session.add(obj)
    # flush marked object to database
    session.flush()
    return obj
Esempio n. 4
0
 def test_user_creation(self):
     """Object creation should set the name."""
     obj = _create_test_user()
     retrieved_user = User.by_email_address(u'*****@*****.**')
     assert retrieved_user, \
         'User should have been found by email address'
     assert retrieved_user.user_name == u'creosote', \
         "User name should have been creosote, not '%s'" % retrieved_user.user_name
     assert obj.display_name == u"Mr Creosote"
Esempio n. 5
0
 def test_create_default_user(self):
     "Test that the default user is created correctly"
     create_tables()
     create_default_user(u'creosote', u'secret')
     retrieved_user = User.by_email_address(u'*****@*****.**' % u'creosote')
     assert retrieved_user
     assert retrieved_user.user_name == u'creosote'
     assert retrieved_user.display_name == u'Default User'
     assert retrieved_user.password
Esempio n. 6
0
 def test_user_creation(self):
     """Object creation should set the name."""
     obj = _create_test_user()
     retrieved_user = User.by_email_address(u'*****@*****.**')
     assert retrieved_user, \
         'User should have been found by email address'
     assert retrieved_user.user_name == u'creosote', \
         "User name should have been creosote, not '%s'" % retrieved_user.user_name
     assert obj.display_name == u"Mr Creosote"
Esempio n. 7
0
 def test_create_default_user(self):
     "Test that the default user is created correctly"
     create_tables()
     create_default_user(u'creosote', u'secret')
     retrieved_user = User.by_email_address(u'*****@*****.**' %
                                            u'creosote')
     assert retrieved_user
     assert retrieved_user.user_name == u'creosote'
     assert retrieved_user.display_name == u'Default User'
     assert retrieved_user.password
Esempio n. 8
0
def _create_test_user():
    obj = User()
    obj.user_name = u"creosote"
    obj.email_address = u"*****@*****.**"
    obj.display_name = u"Mr Creosote"
    obj.password = u"Wafer-thin Mint"
    # mark object as 'to be saved'
    session.add(obj)
    # flush marked object to database
    session.flush()
    return obj
Esempio n. 9
0
 def setUp(self):
     super(JsonifyTest, self).setUp()
     self.test_user = u = User()
     u.user_name = u'test'
     u.display_name = u'Test User'
     u.email_address = u'*****@*****.**'
     u.password = u'test'
     self.test_group = g = Group()
     g.group_name = u'test'
     g.display_name = u'Test Group'
     u.groups.append(g)
     self.test_perm = p = Permission()
     p.permission_name = u'test'
     p.description = u'Test Permission'
     p.groups.append(g)
     session.add(u)
     session.add(g)
     session.add(p)
     session.flush()
Esempio n. 10
0
 def test_login_and_logout(self):
     """Login with correct credentials and then logout."""
     u = User()
     u.user_name = u"scott"
     u.password = u"tiger"
     u.display_name = u"Bruce Scott"
     u.email_address = u"*****@*****.**"
     session.add(u)
     session.flush()
     response = self.app.get('/')
     assert "<title>Welcome to TurboGears</title>" in response
     assert 'href="/login"' in response
     assert 'href="/logout"' not in response
     response = self.app.get('/login')
     assert "<title>Login</title>" in response
     assert 'Please log in.' in response
     cookie = ', '.join(map(str, response.cookies_set.values()))
     login = '******'
     headers = dict(Cookie=cookie)
     response = self.app.get(login, headers=headers, status=302)
     location = response.headers['Location']
     response = self.app.get(location, headers=headers)
     assert "<title>Welcome to TurboGears</title>" in response
     assert "Welcome Bruce Scott" in response
     assert 'href="/login"' not in response
     assert 'href="/logout"' in response
     response = self.app.get('/', headers=headers)
     assert "<title>Welcome to TurboGears</title>" in response
     assert "Welcome Bruce Scott" in response
     assert 'href="/login"' not in response
     assert 'href="/logout"' in response
     response = self.app.get('/logout', headers=headers, status=302)
     location = response.headers['Location']
     response = self.app.get(location, headers=headers)
     assert "<title>Welcome to TurboGears</title>" in response
     assert 'href="/login"' in response
     assert 'href="/logout"' not in response