I would like to test a Django project:
template news.html:
{% if user.is_authentication %}
<a href=#>Logout ({{user.username}})</a>
{% else %}
<a href=#>Login</a>
{% endif %}
How do I create the situation that the user is already logged in (the accounts app, responsible for user login, has not implemented yet) such that the template will display the Logout link?
(a) Functional test:
def test_logged_in_user_can_see_logout_link(self):
# A logged-in user arrives at the main page
## How to mock a logged-in user here?
self.browser.get(self.live_server_url)
self.assertTrue(self.browser.find_element_by_link_text('Logout'))
(b) Unit test:
def test_logged_in_user_can_see_logout_link**(self):
# How to login the user here?
request = self.factory.get('/news/')
response = news(request)
self.assertContains(response, 'Logout')