Skip to content

Commit

Permalink
Merge pull request #537 from grycap/devel
Browse files Browse the repository at this point in the history
Increase vers in reqs
  • Loading branch information
micafer authored May 7, 2024
2 parents 1679a76 + af993a0 commit cc5fd4e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 65 deletions.
9 changes: 5 additions & 4 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
from app.vault_info import VaultInfo
from oauthlib.oauth2.rfc6749.errors import InvalidTokenError, TokenExpiredError, InvalidGrantError
from werkzeug.exceptions import Forbidden
from flask import Flask, json, render_template, request, redirect, url_for, flash, session, Markup, g, make_response
from flask import Flask, json, render_template, request, redirect, url_for, flash, session, g, make_response
from markupsafe import Markup
from functools import wraps
from urllib.parse import urlparse
from radl import radl_parse
Expand Down Expand Up @@ -1230,7 +1231,7 @@ def addresources(infid=None):
images = [(image['uri'], image['name'], image['uri'] == image_url_str)
for image in response.json()["images"]]
except Exception as ex:
app.logger.warn('Error getting site images: %s', (ex))
app.logger.warning('Error getting site images: %s', (ex))

return render_template('addresource.html', infid=infid, systems=systems,
image_url=image_url, images=images)
Expand Down Expand Up @@ -1504,7 +1505,7 @@ def reconfigure(infid=None):
raise Exception(response.text)
template = response.text
except Exception as ex:
app.logger.warn("Error getting infrastructure template: %s" % ex)
app.logger.warning("Error getting infrastructure template: %s" % ex)

infra_name = ""
inputs = utils.getReconfigureInputs(template)
Expand All @@ -1523,7 +1524,7 @@ def logout(next_url=None):
try:
oidc_blueprint.session.get("/logout")
except Exception as ex:
app.logger.warn("Error in OIDC logout: %s" % ex)
app.logger.warning("Error in OIDC logout: %s" % ex)
return redirect(url_for('login', next_url=next_url))

@app.errorhandler(403)
Expand Down
56 changes: 28 additions & 28 deletions app/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def test_manageinf_stop(self, flash, avatar, put, user_data):
res = self.client.post('/manage_inf/infid/stop')
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0],
("Operation 'stop' successfully made on Infrastructure ID: infid", 'success'))
self.assertEqual(flash.call_args_list[0][0],
("Operation 'stop' successfully made on Infrastructure ID: infid", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.post')
Expand All @@ -268,8 +268,8 @@ def test_manageinf_change_user(self, flash, avatar, post, user_data):
res = self.client.post('/manage_inf/infid/change_user', data=params)
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0],
("Infrastructure owner successfully changed.", 'success'))
self.assertEqual(flash.call_args_list[0][0],
("Infrastructure owner successfully changed.", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.put')
Expand All @@ -284,9 +284,9 @@ def test_manageinf_migrate(self, flash, avatar, get, put, user_data):
res = self.client.post('/manage_inf/infid/migrate', data={"new_im_url": "http://newim.com/im"})
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0],
("Infrastructure successfully migrated to http://server.com/im/infrastructures/infid.",
'success'))
self.assertEqual(flash.call_args_list[0][0],
("Infrastructure successfully migrated to http://server.com/im/infrastructures/infid.",
'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.get')
Expand All @@ -311,7 +311,7 @@ def test_managevm_stop(self, flash, avatar, put, user_data):
res = self.client.post('/managevm/stop/infid/0')
self.assertEqual(302, res.status_code)
self.assertIn('/vminfo?infId=infid&vmId=0', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Operation 'stop' successfully made on VM ID: 0", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("Operation 'stop' successfully made on VM ID: 0", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.delete')
Expand All @@ -324,8 +324,8 @@ def test_managevm_delete(self, flash, avatar, delete, user_data):
res = self.client.post('/managevm/terminate/infid/0')
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Operation 'terminate' successfully made on VM ID: 0",
'success'))
self.assertEqual(flash.call_args_list[0][0], ("Operation 'terminate' successfully made on VM ID: 0",
'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.get')
Expand All @@ -344,7 +344,7 @@ def test_managevm_resize(self, flash, avatar, put, get, user_data):
res = self.client.post('/managevm/resize/infid/0', data=params)
self.assertEqual(302, res.status_code)
self.assertIn('/vminfo?infId=infid&vmId=0', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Operation 'resize' successfully made on VM ID: 0", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("Operation 'resize' successfully made on VM ID: 0", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.put')
Expand All @@ -357,7 +357,7 @@ def test_reconfigure(self, flash, avatar, put, user_data):
res = self.client.post('/manage_inf/infid/reconfigure')
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Reconfiguration process successfuly started.", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("Reconfiguration process successfuly started.", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.get')
Expand Down Expand Up @@ -418,7 +418,7 @@ def test_delete(self, flash, avatar, delete, user_data):
res = self.client.post('/manage_inf/infid/delete')
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Infrastructure 'infid' successfuly deleted.", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("Infrastructure 'infid' successfuly deleted.", 'success'))

@patch("app.utils.avatar")
@patch("app.db_cred.DBCredentials.get_creds")
Expand Down Expand Up @@ -506,7 +506,7 @@ def test_submit(self, flash, get_ssh_keys, get_cred, get_site_info, avatar, post
res = self.client.post('/submit?template=simple-node-disk.yml', data=params)
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_count, 0)
self.assertEqual(flash.call_count, 0)

@patch('app.utils.get_site_info')
@patch("app.utils.getUserAuthData")
Expand All @@ -532,7 +532,7 @@ def test_submit2(self, flash, get_cred, avatar, post, user_data, get_site_info):
res = self.client.post('/submit?template=simple-node-disk.yml', data=params)
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_count, 0)
self.assertEqual(flash.call_count, 0)

@patch("app.utils.getUserAuthData")
@patch('requests.post')
Expand All @@ -556,7 +556,7 @@ def test_submit_tosca(self, flash, get_cred, get_site_info, avatar, post, user_d
res = self.client.post('/submit?template=tosca.yml', data=params)
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_count, 0)
self.assertEqual(flash.call_count, 0)

@patch("app.utils.avatar")
@patch("app.db_cred.DBCredentials.get_creds")
Expand Down Expand Up @@ -596,19 +596,19 @@ def test_write_creds(self, flash, write_creds, get_cred, avatar):
"type": "OpenNebula"})
self.assertEqual(302, res.status_code)
self.assertIn('/manage_creds', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Credentials successfully written!", 'success'))
self.assertEquals(write_creds.call_args_list[0][0], ('credid', 'userid', {'host': 'SITE_URL2',
'id': 'credid', 'type': "OpenNebula"}, False))
self.assertEqual(flash.call_args_list[0][0], ("Credentials successfully written!", 'success'))
self.assertEqual(write_creds.call_args_list[0][0], ('credid', 'userid', {'host': 'SITE_URL2',
'id': 'credid', 'type': "OpenNebula"}, False))

res = self.client.post('/write_creds?cred_id=&cred_type=OpenNebula', data={"host": "SITE_URL3",
"id": "credid",
"type": "OpenNebula"})
self.assertEqual(302, res.status_code)
self.assertIn('/manage_creds', res.headers['location'])
self.assertEquals(flash.call_args_list[1][0], ("Credentials successfully written!", 'success'))
self.assertEquals(write_creds.call_args_list[1][0], ('credid', 'userid', {'host': 'SITE_URL3',
'id': 'credid',
'type': 'OpenNebula'}, True))
self.assertEqual(flash.call_args_list[1][0], ("Credentials successfully written!", 'success'))
self.assertEqual(write_creds.call_args_list[1][0], ('credid', 'userid', {'host': 'SITE_URL3',
'id': 'credid',
'type': 'OpenNebula'}, True))

@patch("app.utils.avatar")
@patch("app.db_cred.DBCredentials.delete_cred")
Expand All @@ -619,7 +619,7 @@ def test_delete_creds(self, flash, delete_cred, avatar):
res = self.client.get('/delete_creds?service_id=SERVICE_ID')
self.assertEqual(302, res.status_code)
self.assertIn('/manage_creds', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("Credentials successfully deleted!", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("Credentials successfully deleted!", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.get')
Expand All @@ -645,7 +645,7 @@ def test_addresources(self, flash, avatar, post, get, user_data):
self.login(avatar)
res = self.client.post('/addresources/infid', data={"wn_num": "1"})
self.assertEqual(302, res.status_code)
self.assertEquals(flash.call_args_list[0][0], ("1 nodes added successfully", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("1 nodes added successfully", 'success'))

@patch("app.utils.avatar")
@patch("app.utils.getUserAuthData")
Expand All @@ -662,7 +662,7 @@ def test_quotas(self, get, user_data, avatar):
"instances": {"used": 1, "limit": 10},
"floating_ips": {"used": 1, "limit": 10},
"security_groups": {"used": 1, "limit": 10}}
self.assertEquals(expected_res, json.loads(res.data))
self.assertEqual(expected_res, json.loads(res.data))

@patch("app.utils.avatar")
@patch("app.ssh_key.SSHKey.get_ssh_keys")
Expand Down Expand Up @@ -697,7 +697,7 @@ def test_delete_ssh_key(self, flash, delete_ssh_key, avatar):
res = self.client.get('/delete_ssh_key?ssh_id=1')
self.assertEqual(302, res.status_code)
self.assertIn('/ssh_key', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("SSH Key successfully deleted!", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("SSH Key successfully deleted!", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.delete')
Expand All @@ -710,7 +710,7 @@ def test_removeresources(self, flash, avatar, delete, user_data):
res = self.client.post('/manage_inf/infid/removeresources', data={'vm_list': '1,2'})
self.assertEqual(302, res.status_code)
self.assertIn('/infrastructures', res.headers['location'])
self.assertEquals(flash.call_args_list[0][0], ("VMs 1,2 successfully deleted.", 'success'))
self.assertEqual(flash.call_args_list[0][0], ("VMs 1,2 successfully deleted.", 'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.get')
Expand Down
20 changes: 10 additions & 10 deletions app/tests/test_appdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ def requests_response(method, url, **kwargs):
def test_appdb_call(self, requests):
requests.side_effect = self.requests_response
res = appdb.appdb_call('/rest/1.0/vos')
self.assertEquals(res["vo:vo"]["@name"], "acc-comp.egi.eu")
self.assertEqual(res["vo:vo"]["@name"], "acc-comp.egi.eu")

@patch('app.appdb.appdb_call')
def test_vo_list(self, appdb_call):
appdb.VO_LIST = []
vos = '<vo:vo id="15551" name="acc-comp.egi.eu"></vo:vo>'
appdb_call.return_value = xmltodict.parse(vos.replace('\n', ''))
res = appdb.get_vo_list()
self.assertEquals(res, ['acc-comp.egi.eu'])
self.assertEqual(res, ['acc-comp.egi.eu'])
appdb.VO_LIST = []

vos = '<appdb:appdb><vo:vo id="15551" name="acc-comp.egi.eu"></vo:vo>'
vos += '<vo:vo id="15527" name="vo.access.egi.eu"></vo:vo></appdb:appdb>'
appdb_call.return_value = xmltodict.parse(vos)["appdb:appdb"]
res = appdb.get_vo_list()
self.assertEquals(res, ['acc-comp.egi.eu', 'vo.access.egi.eu'])
self.assertEqual(res, ['acc-comp.egi.eu', 'vo.access.egi.eu'])

@patch('app.appdb.appdb_call')
def test_get_services(self, appdb_call):
Expand All @@ -84,7 +84,7 @@ def test_get_services(self, appdb_call):
</appdb:site>"""
appdb_call.return_value = xmltodict.parse(site.replace('\n', ''))
res = appdb._get_services()
self.assertEquals(res[0]["@type"], "openstack")
self.assertEqual(res[0]["@type"], "openstack")

site = """<appdb:appdb><appdb:site id="80090G0" name="100IT" infrastructure="Production" status="Certified">
<site:service type="openstack" id="11541G0" host="devcloud-egi.100percentit.com">
Expand All @@ -97,7 +97,7 @@ def test_get_services(self, appdb_call):
</appdb:appdb>"""
appdb_call.return_value = xmltodict.parse(site.replace('\n', ''))["appdb:appdb"]
res = appdb._get_services()
self.assertEquals(res[0]["@type"], "openstack")
self.assertEqual(res[0]["@type"], "openstack")

@patch('app.appdb.appdb_call')
@patch('app.appdb._get_services')
Expand All @@ -106,8 +106,8 @@ def test_get_sites(self, get_services, appdb_call):
va_provider = read_file_as_string("files/va_provider.xml")
appdb_call.return_value = xmltodict.parse(va_provider.replace('\n', ''))["appdb:appdb"]
res = appdb.get_sites("vo.access.egi.eu")
self.assertEquals(res, {'CESGA': {'url': 'https://fedcloud-osservices.egi.cesga.es:5000',
'state': '', 'id': '1', 'name': 'CESGA'}})
self.assertEqual(res, {'CESGA': {'url': 'https://fedcloud-osservices.egi.cesga.es:5000',
'state': '', 'id': '1', 'name': 'CESGA'}})
# self.assertIn(appdb_call.call_args_list[0][0][0], ["/rest/1.0/va_providers/1"])

@patch('app.appdb.appdb_call')
Expand All @@ -120,8 +120,8 @@ def test_get_project_ids(self, appdb_call):
</virtualization:provider>"""
appdb_call.return_value = xmltodict.parse(shares.replace('\n', ''))
res = appdb.get_project_ids("11548G0")
self.assertEquals(res, {"vo.access.egi.eu": "3a8e9d966e644405bf19b536adf7743d",
"covid-19.eosc-synergy.eu": "972298c557184a2192ebc861f3184da8"})
self.assertEqual(res, {"vo.access.egi.eu": "3a8e9d966e644405bf19b536adf7743d",
"covid-19.eosc-synergy.eu": "972298c557184a2192ebc861f3184da8"})

@patch('app.appdb.appdb_call')
def test_get_images(self, appdb_call):
Expand All @@ -131,7 +131,7 @@ def test_get_images(self, appdb_call):
</virtualization:provider>"""
appdb_call.return_value = xmltodict.parse(images.replace('\n', ''))
res = appdb.get_images('11548G0', 'vo.access.egi.eu')
self.assertEquals(res, [("ScipionCloud-GPU", "scipioncloud.gpu")])
self.assertEqual(res, [("ScipionCloud-GPU", "scipioncloud.gpu")])


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions app/tests/test_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ def test_get_infra(self):
res.close()

res = infra.get_infra("infid")
self.assertEquals(res, {'name': 'infra_name'})
self.assertEqual(res, {'name': 'infra_name'})

def test_write_infra(self):
infra = Infrastructures("sqlite:///tmp/creds.db")
infra.write_infra("infid", {"name": "infra_name"})
res = infra.get_infra("infid")
self.assertEquals(res, {"name": "infra_name"})
self.assertEqual(res, {"name": "infra_name"})
infra.write_infra("infid", {"state": "infra_state"})
res = infra.get_infra("infid")
self.assertEquals(res, {"name": "infra_name", "state": "infra_state"})
self.assertEqual(res, {"name": "infra_name", "state": "infra_state"})

def test_delete_infra(self):
infra = Infrastructures("sqlite:///tmp/creds.db")
infra.delete_infra("infid")
res = infra.get_infra("infid")
self.assertEquals(res, {})
self.assertEqual(res, {})


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit cc5fd4e

Please sign in to comment.