Fakultas Ilmu Komputer UI

Commit 958c8066 authored by Yumna Pratista Tastaftian's avatar Yumna Pratista Tastaftian
Browse files

Testinggoat/ex9

parent c59bb733
# Created by https://www.gitignore.io
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Sphinx documentation
docs/_build/
# PyBuilder
target/
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
.env
db.sqlite3
\ No newline at end of file
from django.conf.urls import url
from accounts import views
from django.contrib.auth import logout
urlpatterns = [
url(r'^send_login_email$', views.send_login_email, name='send_login_email'),
url(r'^login$', views.login, name='login'),
url(r'^logout$', logout, {'next_page':'/'}, name='logout'),
url(r'^logout$', views.logout, name='logout'),
]
\ No newline at end of file
......@@ -33,3 +33,7 @@ def send_login_email(request):
"Check your email, we've sent you a link you can use to log in."
)
return redirect('/')
def logout(request):
auth.logout(request)
return redirect('/')
......@@ -18,7 +18,7 @@
{% 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>
<li><a href="{% url 'logout' %}">Log out</a></li>
</ul>
{% else %}
<form class="navbar-form navbar-right"
......
No preview for this file type
......@@ -25,38 +25,68 @@ class FunctionalTest(StaticLiveServerTestCase):
def tearDown(self):
self.browser.quit()
def wait(fn):
def modified_fn(*args, **kwargs):
start_time = time.time()
while True:
try:
return fn(*args, **kwargs)
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
time.sleep(0.5)
return modified_fn
@wait
def wait_for_row_in_list_table(self, row_text):
start_time = time.time()
while True:
try:
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
if len(rows) == 0:
self.assertIn(table.text, "You can't have an empty list item")
else :
self.assertIn(row_text, [row.text for row in rows])
return
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
time.sleep(0.5)
# def test_can_start_a_list_for_one_user(self):
# # Edith has heard about a cool new online to-do app. She goes
# # The page updates again, and now shows both items on her list
# self.wait_for_row_in_list_table('1: Buy peacock feathers')
# self.wait_for_row_in_list_table('2: Use peacock feathers to make a fly')
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertIn(row_text, [row.text for row in rows])
@wait
def wait_to_be_logged_in(self, email):
self.browser.find_element_by_link_text('Log out')
# # Satisfied, she goes back to sleep
@wait
def wait_to_be_logged_out(self, email):
self.browser.find_element_by_name('email')
navbar = self.browser.find_element_by_css_selector('.navbar')
self.assertNotIn(email, navbar.text)
@wait
def wait_for(self, fn):
start_time = time.time()
while True:
try:
return fn()
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
time.sleep(0.5)
\ No newline at end of file
return fn()
# def wait_for_row_in_list_table(self, row_text):
# start_time = time.time()
# while True:
# try:
# table = self.browser.find_element_by_id('id_list_table')
# rows = table.find_elements_by_tag_name('tr')
# if len(rows) == 0:
# self.assertIn(table.text, "You can't have an empty list item")
# else :
# self.assertIn(row_text, [row.text for row in rows])
# return
# except (AssertionError, WebDriverException) as e:
# if time.time() - start_time > MAX_WAIT:
# raise e
# time.sleep(0.5)
# def wait_to_be_logged_in(self, email):
# self.wait_for(
# lambda: self.browser.find_element_by_link_text('Log out')
# )
# navbar = self.browser.find_element_by_css_selector('.navbar')
# self.assertIn(email, navbar.text)
# def wait_to_be_logged_out(self, email):
# self.wait_for(
# lambda: self.browser.find_element_by_name('email')
# )
# navbar = self.browser.find_element_by_css_selector('.navbar')
# self.assertNotIn(email, navbar.text)
\ No newline at end of file
......@@ -45,4 +45,13 @@ class LoginTest(FunctionalTest):
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
self.assertIn(TEST_EMAIL, navbar.text)
# she is logged in!
self.wait_to_be_logged_in(email=TEST_EMAIL)
# Now she logs out
self.browser.find_element_by_link_text('Log out').click()
# She is logged out
self.wait_to_be_logged_out(email=TEST_EMAIL)
\ No newline at end of file
from django.conf import settings
from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, get_user_model
from django.contrib.sessions.backends.db import SessionStore
from .base import FunctionalTest
User = get_user_model()
class MyListsTest(FunctionalTest):
def create_pre_authenticated_session(self, email):
user = User.objects.create(email=email)
session = SessionStore()
session[SESSION_KEY] = user.pk
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
session.save()
## to set a cookie we need to first visit the domain.
## 404 pages load the quickest!
self.browser.get(self.live_server_url + "/404_no_such_url/")
self.browser.add_cookie(dict(
name=settings.SESSION_COOKIE_NAME,
value=session.session_key,
path='/',
))
def test_logged_in_users_lists_are_saved_as_my_lists(self):
email = 'edith@example.com'
self.browser.get(self.live_server_url)
self.wait_to_be_logged_out(email)
# Edith is logged in user
self.create_pre_authenticated_session(email)
self.browser.get(self.live_server_url)
self.wait_to_be_logged_in(email)
\ No newline at end of file
......@@ -340,3 +340,24 @@ Exiting due to channel error.
1574828124034 Marionette INFO Listening on port 49865
1574828124302 Marionette WARN TLS certificate errors will be ignored for this session
1574828127804 Marionette INFO Stopped listening on port 49865
1574831546664 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilegqCpep"
*** You are running in headless mode.
1574831547542 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1574831547542 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1574831547542 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1574831547542 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1574831550894 Marionette INFO Listening on port 50321
1574831550909 Marionette WARN TLS certificate errors will be ignored for this session
1574831553687 Marionette WARN TimedPromise timed out after 500 ms: stacktrace:
bail@chrome://marionette/content/sync.js:237:64
1574831573902 Marionette INFO Stopped listening on port 50321
1574832092543 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileSKNyUs"
*** You are running in headless mode.
1574832093475 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1574832093475 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1574832093475 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1574832093475 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1574832096606 Marionette INFO Listening on port 59203
1574832096635 Marionette WARN TLS certificate errors will be ignored for this session
1574832100832 Marionette INFO Stopped listening on port 59203
JavaScript error: resource://gre/modules/UrlClassifierListManager.jsm, line 680: TypeError: this.tablesData[table] is undefined
Markdown is supported
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