trying to get tests to pass with hub_model=capsulflask

This commit is contained in:
2021-07-27 12:48:48 -05:00
committed by 3wc
parent 5e682cc705
commit 2348191990
6 changed files with 24 additions and 12 deletions

View File

@ -114,7 +114,7 @@ def init_app(app, is_running_server):
def get_model():
def get_model() -> DBModel:
if 'db_model' not in g:
connection = current_app.config['PSYCOPG2_CONNECTION_POOL'].getconn()
cursor = connection.cursor()

View File

@ -381,7 +381,7 @@ class DBModel:
def list_all_operations(self):
self.cursor.execute("""
SELECT operations.id, operations.email, operations.created, operations.payload,
host_operation.host host_operation.assignment_status, host_operation.assigned,
host_operation.host, host_operation.assignment_status, host_operation.assigned,
host_operation.completed, host_operation.results FROM operations
JOIN host_operation ON host_operation.operation = operations.id
""")

View File

@ -196,7 +196,7 @@ class CapsulFlaskHub(VirtualizationInterface):
def create(self, email: str, id: str, os: str, size: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_authorized_keys: list):
validate_capsul_id(id)
online_hosts = get_model().get_online_hosts()
#current_app.logger.debug(f"hub_model.create(): ${len(online_hosts)} hosts")
current_app.logger.debug(f"hub_model.create(): ${len(online_hosts)} hosts")
payload = json.dumps(dict(
type="create",
email=email,

View File

@ -6,7 +6,7 @@ from flask import url_for
from capsulflask.db import get_model
from capsulflask.tests_base import BaseTestCase
from capsulflask.hub_model import MockHub
from capsulflask.spoke_model import MockSpoke
class ConsoleTests(BaseTestCase):
@ -65,9 +65,11 @@ class ConsoleTests(BaseTestCase):
get_model().create_payment_session('fake', 'test', 'test@example.com', 20)
get_model().consume_payment_session('fake', 'test', 20)
with patch.object(MockHub, 'capacity_avaliable', return_value=False) as mock_method:
with patch.object(MockSpoke, 'capacity_avaliable', return_value=False) as mock_method:
response = client.post(url_for("console.create"), data=data)
self.assert200(response)
mock_method.assert_called()
capacity_message = \
@ -112,6 +114,14 @@ class ConsoleTests(BaseTestCase):
response = client.post(url_for("console.create"), data=data)
self.assertEqual(
len(get_model().list_all_operations()),
1
)
vms = get_model().list_vms_for_account('test@example.com')
self.assertEqual(
len(vms),
@ -125,6 +135,7 @@ class ConsoleTests(BaseTestCase):
url_for("console.index") + f'?created={vm_id}'
)
def test_keys_loads(self):
self._login('test@example.com')
with self.client as client:

View File

@ -11,8 +11,9 @@ class BaseTestCase(TestCase):
# Use default connection paramaters
os.environ['POSTGRES_CONNECTION_PARAMETERS'] = "host=localhost port=5432 user=postgres password=dev dbname=capsulflask_test"
os.environ['TESTING'] = '1'
os.environ['LOG_LEVEL'] = 'DEBUG'
os.environ['SPOKE_MODEL'] = 'mock'
os.environ['HUB_MODEL'] = 'mock'
os.environ['HUB_MODEL'] = 'capsul-flask'
return create_app()
def setUp(self):