diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-26 20:57:57 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-26 20:57:57 +0100 |
commit | ab83194ae6b0aeadd57237d32eb08d7c09e703b3 (patch) | |
tree | c4488f77d24a94ab075b6b6f33173734c1ab626e /ctrack | |
parent | 4c96bc3475ba0c97f815a050e79d7983d76233cf (diff) |
when user logs in - now redirects to home page - func and unit tests passing
Diffstat (limited to '')
-rw-r--r-- | ctrack/templates/base.html | 2 | ||||
-rw-r--r-- | ctrack/templates/pages/home.html | 2 | ||||
-rw-r--r-- | ctrack/users/tests/test_functional.py | 7 | ||||
-rw-r--r-- | ctrack/users/tests/test_views.py | 18 | ||||
-rw-r--r-- | ctrack/users/views.py | 6 |
5 files changed, 25 insertions, 10 deletions
diff --git a/ctrack/templates/base.html b/ctrack/templates/base.html index 4398926..c0ee4cd 100644 --- a/ctrack/templates/base.html +++ b/ctrack/templates/base.html @@ -3,7 +3,7 @@ <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> - <title>{% block title %}ctrack{% endblock title %}</title> + <title>{% block title %}ctrack - Department for Transport{% endblock title %}</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> diff --git a/ctrack/templates/pages/home.html b/ctrack/templates/pages/home.html index fbce9ff..bc70c17 100644 --- a/ctrack/templates/pages/home.html +++ b/ctrack/templates/pages/home.html @@ -2,7 +2,7 @@ {% block content %} - <h1>User profile page</h1> + <h1>Welcome to ctrack - Department for Transport</h1> <p>User: {{ object }}</p> diff --git a/ctrack/users/tests/test_functional.py b/ctrack/users/tests/test_functional.py index 8fcc285..18dd477 100644 --- a/ctrack/users/tests/test_functional.py +++ b/ctrack/users/tests/test_functional.py @@ -30,10 +30,11 @@ def test_user_can_log_in(browser, person, live_server): browser.find_element_by_id("sign_in_button").submit() time.sleep(1) current_url = browser.current_url - assert current_url == live_server + "/users/toss/" + assert current_url == live_server + "/" # On the other side, he sees some basic details about himself. - assert "User: toss" in browser.title + assert "ctrack - Department for Transport" in browser.title # Such as his own name in an H1 tag! - assert browser.find_element_by_tag_name("H1") == "Toss McBride" + h1 = browser.find_element_by_tag_name("h1") + assert h1.text == "Welcome to ctrack - Department for Transport" diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py index 2aa463e..da00a0d 100644 --- a/ctrack/users/tests/test_views.py +++ b/ctrack/users/tests/test_views.py @@ -1,8 +1,10 @@ import pytest from django.contrib.auth import get_user_model +from django.http import HttpRequest from django.test import RequestFactory from django.urls import resolve +from ctrack.core.views import home_page from ctrack.organisations.models import Stakeholder from ctrack.users.models import User from ctrack.users.views import UserDetailView, UserRedirectView, UserUpdateView @@ -82,7 +84,15 @@ def test_profile_view_contains_organisation_information(person, user): assert response.context_data["user"].stakeholder.person.first_name == "Toss" -def test_user_page_has_h1_with_their_name_in_it(person, user): - """Test""" - # TODO - write this test; it will make part of func test pass. - found = resolve("/") +def test_home_page_h1_tag_with_client(person, client, django_user_model): + """ + Basic test of HTML from the home page. + """ + django_user_model.objects.create_user(username="toss", password="knob") + client.login(username="toss", password="knob") + response = client.get("/") + assert response.status_code == 200 + assert response.content[:15] == b"<!DOCTYPE html>" + assert b"<title>ctrack - Department for Transport</title>" in response.content + assert b"<h1>Welcome to ctrack - Department for Transport</h1>" in response.content + assert b"</html>" in response.content diff --git a/ctrack/users/views.py b/ctrack/users/views.py index ed29ea1..8e504e4 100644 --- a/ctrack/users/views.py +++ b/ctrack/users/views.py @@ -50,7 +50,11 @@ class UserRedirectView(LoginRequiredMixin, RedirectView): permanent = False def get_redirect_url(self): - return reverse("users:detail", kwargs={"username": self.request.user.username}) + return reverse("core:home") + + +# def get_redirect_url(self): +# return reverse("users:detail", kwargs={"username": self.request.user.username}) user_redirect_view = UserRedirectView.as_view() |