Fakultas Ilmu Komputer UI

Commit c59bb733 authored by Yumna Pratista Tastaftian's avatar Yumna Pratista Tastaftian
Browse files

Merge branch 'testinggoat/ex8' into 'master'

Testinggoat/ex8

See merge request !8
parents efa00ed2 02842153
Pipeline #26090 passed with stages
in 5 minutes and 52 seconds
from django.db import models
from django.contrib import auth
class List(models.Model):
pass
......
......@@ -15,13 +15,36 @@
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="/">Superlists</a>
<form class="navbar-form navbar-right" method="POST" action="#">
<span>Enter email to log in:</span>
<input class="form-control" name="email" type="text" />
{% csrf_token %}
</form>
{% if user.is_authenticated %}
<ul class="nav navbar-nav navbar-right">
<li class="navbar-text">Logged in as {{ user.email }}</li>
<li><a href="#">Log out</a></li>
</ul>
{% else %}
<form class="navbar-form navbar-right"
method="POST"
action="{% url 'send_login_email' %}">
<span>Enter email to log in:</span>
<input class="form-control" name="email" type="text" />
{% csrf_token %}
</form>
{% endif %}
</div>
</nav>
{% if messages %}
<div class="row">
<div class="col-md-8">
{% for message in messages %}
{% if message.level_tag == 'success' %}
<div class="alert alert-success">{{ message }}</div>
{% else %}
<div class="alert alert-warning">{{ message }}</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endif %}
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3 jumbotron">
......
No preview for this file type
......@@ -3,6 +3,7 @@ from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.firefox.options import Options as firefox_opt
import time
MAX_WAIT = 10
......@@ -16,7 +17,9 @@ class FunctionalTest(StaticLiveServerTestCase):
chrome_options.add_argument('--disable-gpu')
self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
# self.browser = webdriver.Firefox()
# firefox_options = firefox_opt()
# firefox_options.headless = True
# self.browser = webdriver.Firefox(options=firefox_options)
# self.browser.implicitly_wait(20)
def tearDown(self):
......
# from django.core import mail
# from selenium.webdriver.common.keys import Keys
# import re
# from .base import FunctionalTest
# TEST_EMAIL = 'yumnanaruto@gmail.com'
# SUBJECT = 'Your login link for Superlists'
# class LoginTest(FunctionalTest):
# def test_can_get_email_link_to_log_in(self):
# # Edith goes to the awesome superlists site
# # and notices a "Log in" section in the navbar for the first time
# # It's telling her to enter her email address, so she does
# self.browser.get(self.live_server_url)
# self.browser.find_element_by_name('email').send_keys(TEST_EMAIL)
# self.browser.find_element_by_name('email').send_keys(Keys.ENTER)
# # A message appears telling her an email has been sent
# self.wait_for(lambda: self.assertIn(
# 'Check your email',
# self.browser.find_element_by_tag_name('body').text
# ))
# # She checks her email and finds a message
# email = mail.outbox[0]
# self.assertIn(TEST_EMAIL, email.to)
# self.assertEqual(email.subject, SUBJECT)
# # It has a url link in it
# self.assertIn('Use this link to log in', email.body)
# url_search = re.search(r'http://.+/.+$', email.body)
# if not url_search:
# self.fail(f'Could not find url in email body:\n{email.body}')
# url = url_search.group(0)
# self.assertIn(self.live_server_url, url)
# # she clicks it
# self.browser.get(url)
# # she is logged in!
# self.wait_for(
# lambda: self.browser.find_element_by_link_text('Log out')
# )
# navbar = self.browser.find_element_by_css_selector('.navbar')
# self.assertIn(TEST_EMAIL, navbar.text)
\ No newline at end of file
from django.core import mail
from selenium.webdriver.common.keys import Keys
import re
from .base import FunctionalTest
TEST_EMAIL = 'yumnanaruto@gmail.com'
SUBJECT = 'Your login link for Superlists'
class LoginTest(FunctionalTest):
def test_can_get_email_link_to_log_in(self):
# Edith goes to the awesome superlists site
# and notices a "Log in" section in the navbar for the first time
# It's telling her to enter her email address, so she does
self.browser.get(self.live_server_url)
self.browser.find_element_by_name('email').send_keys(TEST_EMAIL)
self.browser.find_element_by_name('email').send_keys(Keys.ENTER)
# A message appears telling her an email has been sent
self.wait_for(lambda: self.assertIn(
'Check your email',
self.browser.find_element_by_tag_name('body').text
))
# She checks her email and finds a message
email = mail.outbox[0]
self.assertIn(TEST_EMAIL, email.to)
self.assertEqual(email.subject, SUBJECT)
# It has a url link in it
self.assertIn('Use this link to log in', email.body)
url_search = re.search(r'http://.+/.+$', email.body)
if not url_search:
self.fail(f'Could not find url in email body:\n{email.body}')
url = url_search.group(0)
self.assertIn(self.live_server_url, url)
# she clicks it
self.browser.get(url)
# she is logged in!
self.wait_for(
lambda: self.browser.find_element_by_link_text('Log out')
)
navbar = self.browser.find_element_by_css_selector('.navbar')
self.assertIn(TEST_EMAIL, navbar.text)
\ No newline at end of file
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment