Check if current_user exists in template

Fixes #4
master
Steven Loria 11 years ago
parent aca9b39329
commit 070eb9e54f
  1. 2
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/templates/nav.html
  2. 16
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/webtest_tests.py

@ -22,7 +22,7 @@
<li><a href="{{ url_for('public.home') }}">Home</a></li>
<li><a href="{{ url_for('public.about') }}">About</a></li>
</ul>
{% if current_user.is_authenticated() %}
{% if current_user and current_user.is_authenticated() %}
<ul class="nav navbar-nav navbar-right">
<li>
<p class="navbar-text"><a class="navbar-link" href="{{ url_for('user.members') }}">Logged in as {{ current_user.username }}</a></p>

@ -30,6 +30,22 @@ class TestLoggingIn(DbTestCase):
res = form.submit().maybe_follow()
assert_equal(res.status_code, 200)
def _login(self, username, password):
res = self.w.get("/")
# Fills out login form in navbar
form = res.forms['loginForm']
form['username'] = username
form['password'] = password
# Submits
res = form.submit().maybe_follow()
return res
def test_sees_alert_on_log_out(self):
res = self._login(self.user.username, 'myprecious')
res = self.w.get(url_for('public.logout')).maybe_follow()
# sees alert
assert_in('You are logged out.', res)
def test_sees_error_message_if_password_is_incorrect(self):
# Goes to homepage
res = self.w.get("/")

Loading…
Cancel
Save