Verified Commit 2807ceb0 authored by Huste, Tobias (FWCC) - 111645's avatar Huste, Tobias (FWCC) - 111645
Browse files

tests: test init and delete in settings view

parent dfd9d738
Pipeline #6607 passed with stage
in 22 minutes and 5 seconds
......@@ -104,6 +104,10 @@ def delete_ssh_key(remote):
"""Delete SSH key from remote machine."""
# retrieve SSH key
key = SSHKey.get(current_user.id, remote.id)
if not key:
flash('Nothing deleted, connection was not setup before.',
category='warning')
return
pkey = current_app.config[
'UPLOADBYURL_KEY_DISPATCH_TABLE'][key.keytype].from_private_key(
StringIO(key.private_key))
......
......@@ -92,6 +92,7 @@ def base_app(instance_path):
UPLOADBYURL_SHORT_TIMEOUT=10,
FILES_REST_DEFAULT_QUOTA_SIZE=100 * 1024 * 1024,
MAIL_SUPPRESS_SEND=True,
WTF_CSRF_ENABLED=False,
)
FlaskCeleryExt(app_)
InvenioDB(app_)
......
......@@ -23,8 +23,10 @@ import os
from flask import url_for
from testutils import login_user
from invenio_uploadbyurl.models import SSHKey
def test_index(client, user, remote):
def test_index(client, db, user, remote):
"""Test the index view."""
url = url_for('invenio_uploadbyurl_settings.index')
resp = client.get(url)
......@@ -35,11 +37,22 @@ def test_index(client, user, remote):
login_user(client, user)
resp = client.get(url)
assert resp.status_code == 200
assert os.getenv('SFTP_SERVER') in str(resp.get_data())
assert os.getenv('SFTP_SERVER') in resp.get_data(as_text=True)
assert 'Disconnect' in resp.get_data(as_text=True)
SSHKey.delete(user.id, remote.id)
db.session.commit()
login_user(client, user)
resp = client.get(url)
assert resp.status_code == 200
assert 'Connect' in resp.get_data(as_text=True)
def test_init(client, user, remote):
def test_init(client, db, user, remote):
"""Test remote initialization view."""
SSHKey.delete(user.id, remote.id)
db.session.commit()
init_url = url_for('invenio_uploadbyurl_settings.init', remote_name='foo')
resp = client.get(init_url)
# expect redirect to login form
......@@ -49,10 +62,22 @@ def test_init(client, user, remote):
login_user(client, user)
resp = client.get(init_url)
assert resp.status_code == 200
assert 'Connect to foo server:' in str(resp.get_data())
assert 'Connect to foo server:' in resp.get_data(as_text=True)
# Test setup of connection
resp = client.post(
init_url,
data=dict(
username='foo',
password='pass',
),
follow_redirects=True,
)
assert resp.status_code == 200
assert 'Disconnect' in resp.get_data(as_text=True)
def test_delete(client, user, remote):
def test_delete(client, db, user, remote):
"""Test delete view."""
delete_url = url_for('invenio_uploadbyurl_settings.delete',
remote_name='foo')
......@@ -60,3 +85,13 @@ def test_delete(client, user, remote):
# expect redirect to login form
assert resp.status_code == 302
assert '/login' in resp.location
login_user(client, user)
resp = client.get(delete_url, follow_redirects=True)
assert resp.status_code == 200
assert 'Disconnect' not in resp.get_data(as_text=True)
# Just don't do anything if connection is not set up before deletion
resp = client.get(delete_url, follow_redirects=True)
assert resp.status_code == 200
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