Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Dec 13, 2024
1 parent 9e0140b commit 19f538e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
wget -P tosca-templates https://raw.githubusercontent.com/grycap/tosca/main/templates/simple-node-disk.yml
sed -i -e 's|/opt|'${GITHUB_WORKSPACE}'|g' app/config.json
sed -i -e 's|creds.db|tmp/creds.db|g' app/config.json
sed -i -e 's|"EXTRA_AUTH": {},|"DISABLE_APPSCHEDULER": true,|g' app/config.json
- name: Unit tests
run: python -m coverage run --source=. -m unittest discover -s app/tests -p 'test*.py'
Expand Down
14 changes: 6 additions & 8 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ def create_app(oidc_blueprint=None):
ssh_key = SSHKey(settings.db_url)
vault_info = VaultInfo(settings.db_url)
ott = OneTimeTokenData(settings.vault_url)

scheduler = APScheduler()

# To Reload internally the site cache
if 'DISABLE_APPSCHEDULER' not in app.config:
scheduler.api_enabled = False
scheduler.init_app(app)
scheduler.start()
scheduler = APScheduler()
scheduler.api_enabled = False
scheduler.init_app(app)
scheduler.start()

toscaTemplates = utils.loadToscaTemplates(settings.toscaDir)
toscaInfo = utils.extractToscaInfo(settings.toscaDir, toscaTemplates, settings.hide_tosca_tags)
Expand Down Expand Up @@ -254,8 +253,7 @@ def home():
return render_template('home.html', oidc_name=settings.oidcName)

# Force to get the user credentials to cache them
ndate = datetime.datetime.now() + datetime.timedelta(0, 2)
scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=ndate,
scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=datetime.datetime.now(),
misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds')

# if there are any next url, redirect to it
Expand Down
3 changes: 2 additions & 1 deletion app/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unittest
import json
import defusedxml.ElementTree as etree
from app import create_app
from app import create_app, utils
from urllib.parse import urlparse
from mock import patch, MagicMock

Expand Down Expand Up @@ -569,6 +569,7 @@ def test_manage_creds(self, get_project_ids, get_sites, get_creds, avatar):
get_sites.return_value = {"SITE_NAME": {"url": "URL", "state": "", "id": ""},
"SITE2": {"url": "URL2", "state": "CRITICAL", "id": ""}}
get_creds.return_value = [{"id": "credid", "type": "fedcloud", "host": "site_url", "project_id": "project"}]
utils.CREDS_CACHE = {}
res = self.client.get('/manage_creds')
self.assertEqual(200, res.status_code)
self.assertIn(b'credid', res.data)
Expand Down

0 comments on commit 19f538e

Please sign in to comment.