forked from plotly/dash-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_basic_auth_integration.py
67 lines (55 loc) · 1.84 KB
/
test_basic_auth_integration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from dash.dependencies import Input, Output, State, Event
import dash
import dash_html_components as html
import dash_core_components as dcc
from multiprocessing import Value
import os
import time
import re
import itertools
import plotly.plotly as py
import requests
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from .IntegrationTests import IntegrationTests
from .utils import assert_clean_console, switch_windows
from dash_auth import basic_auth
TEST_USERS = {
'valid': [
['hello', 'world']
],
'invalid': [
['hello', 'password']
],
}
class Tests(IntegrationTests):
def test_basic_auth_login_flow(self):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(
id='input',
value='initial value'
),
html.Div(id='output')
])
@app.callback(Output('output', 'children'), [Input('input', 'value')])
def update_output(new_value):
return new_value
auth = basic_auth.BasicAuth(
app,
TEST_USERS['valid']
)
self.startServer(app, skip_visit=True)
self.assertEqual(
requests.get('http://localhost:8050').status_code,
401
)
# login using the URL instead of the alert popup
# selenium has no way of accessing the alert popup
self.driver.get('http://hello:world@localhost:8050')
# the username:password@host url doesn't work right now for dash
# routes, but it saves the credentials as part of the browser.
# visiting the page again will use the saved credentials
self.driver.get('http://localhost:8050')
el = self.wait_for_element_by_css_selector('#output')
self.wait_for_text_to_equal('#output', 'initial value')