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 68 69 70 71 72 73 74 75
|
# Copyright (c) 2018-2019 David Steele <dsteele@gmail.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# License-Filename: LICENSE
import pytest
import urllib
from mock import patch, call, Mock
from web import comitupweb
ssid_list = [
'simple',
'simple+',
'simplé',
'simple 2',
]
@pytest.fixture
def app():
app = comitupweb.create_app(Mock())
app.debug = True
app.testing = True
return app
@pytest.mark.parametrize('ssid', ssid_list)
def test_webapp_null(app, ssid):
assert 'simpl' in ssid
@pytest.mark.parametrize('ssid', ssid_list)
def test_webapp_index(app, ssid, monkeypatch):
point = {
'ssid': ssid,
}
client_mock = Mock()
client_mock.ciu_points.return_value = [point]
comitupweb.ciu_client = client_mock
response = app.test_client().get('/')
index_text = response.get_data().decode()
assert ssid + "</button>" in index_text
assert "ssid=" + urllib.parse.quote(ssid) in index_text
@pytest.mark.parametrize('ssid', ssid_list)
def test_webapp_confirm(app, ssid, monkeypatch):
quoted_ssid = urllib.parse.quote(ssid)
url = "confirm?ssid={}&encrypted=encrypted".format(quoted_ssid)
response = app.test_client().get(url)
index_text = response.get_data().decode()
assert "to " + ssid in index_text
assert "value=\"" + urllib.parse.quote(ssid) in index_text
@pytest.mark.parametrize('ssid', ssid_list)
def test_webapp_confirm(app, ssid, monkeypatch):
monkeypatch.setattr('web.comitupweb.Process', Mock())
data = {
'ssid': urllib.parse.quote(ssid),
'password': urllib.parse.quote('password'),
}
response = app.test_client().post('connect', data=data)
index_text = response.get_data().decode()
assert "to " + ssid in index_text
|