blah failed attempts at getting tests to log
This commit is contained in:
parent
3fb8254c15
commit
aa67a1e1b2
@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from unittest.mock import patch
|
||||
@ -81,6 +83,10 @@ class ConsoleTests(BaseTestCase):
|
||||
0
|
||||
)
|
||||
|
||||
file_object = open('unittest-output.log', 'a')
|
||||
file_object.write(f"{self.id()} captured output:\n{self.logs_from_test.getvalue()}\n")
|
||||
file_object.close()
|
||||
|
||||
def test_create_fails_invalid(self):
|
||||
with self.client as client:
|
||||
client.get(url_for("console.create"))
|
||||
@ -190,10 +196,12 @@ class ConsoleTests(BaseTestCase):
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self._login('test@example.com')
|
||||
get_model().create_ssh_public_key('test@example.com', 'key', 'foo')
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
get_model().cursor.execute("DELETE FROM ssh_public_keys")
|
||||
get_model().cursor.execute("DELETE FROM login_tokens")
|
||||
get_model().cursor.execute("DELETE FROM vms")
|
||||
|
@ -1,7 +1,11 @@
|
||||
from io import StringIO
|
||||
import logging
|
||||
import unittest
|
||||
import os
|
||||
from nanoid import generate
|
||||
|
||||
from flask_testing import TestCase
|
||||
from flask import current_app
|
||||
|
||||
from capsulflask import create_app
|
||||
from capsulflask.db import get_model
|
||||
@ -14,16 +18,25 @@ class BaseTestCase(TestCase):
|
||||
os.environ['LOG_LEVEL'] = 'DEBUG'
|
||||
os.environ['SPOKE_MODEL'] = 'mock'
|
||||
os.environ['HUB_MODEL'] = 'capsul-flask'
|
||||
return create_app()
|
||||
self.app = create_app()
|
||||
return self.app
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
self.logs_from_test = StringIO()
|
||||
self.logs_handler = logging.StreamHandler(self.logs_from_test)
|
||||
current_app.logger.addHandler(self.logs_handler)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
#self.app.logger.removeHandler(self.logs_handler)
|
||||
#logging.getLogger("asdasd1").warning(f"{self.id()} captured output:\n{self.logs_from_test.getvalue()}\n")
|
||||
|
||||
file_object = open('unittest-output.log', 'a')
|
||||
file_object.write(f"{self.id()} captured output:\n{self.logs_from_test.getvalue()}\n")
|
||||
file_object.close()
|
||||
|
||||
def _login(self, user_email):
|
||||
get_model().login(user_email)
|
||||
with self.client.session_transaction() as session:
|
||||
session['account'] = user_email
|
||||
session['csrf-token'] = generate()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user