Add preliminary automated tests #1

Merged
3wordchant merged 16 commits from tests into master 2021-08-16 00:11:16 +00:00
3 changed files with 20 additions and 10 deletions
Showing only changes of commit 8c10f71f58 - Show all commits

2
.gitignore vendored
View File

@ -17,4 +17,4 @@ build/
*.egg-info/
.venv
unittest-output.log
unittest-log-output.log

View File

@ -56,28 +56,38 @@ def authorized_as_hub(headers):
def my_exec_info_message(exec_info):
return "{}: {}".format(".".join([exec_info[0].__module__, exec_info[0].__name__]), exec_info[1])
mylog_current_test_id_container = {
'value': '',
}
def set_mylog_test_id(test_id):
mylog_current_test_id_container['value'] = ".".join(test_id.split(".")[-2:])
def log_output_for_tests(app: Flask, message: str):
if app.config['TESTING'] != False:
if app.config['TESTING'] and mylog_current_test_id_container['value'] != "":
file_object = open('unittest-log-output.log', 'a')
file_object.write(message)
file_object.write(f"{mylog_current_test_id_container['value']}: {message}\n")
file_object.close()
def mylog_debug(app: Flask, message: str):
log_output_for_tests(app, f"DEBUG: {message}\n")
log_output_for_tests(app, f"DEBUG: {message}")
app.logger.debug(message)
def mylog_info(app: Flask, message: str):
log_output_for_tests(app, f"INFO: {message}\n")
log_output_for_tests(app, f"INFO: {message}")
app.logger.info(message)
def mylog_warning(app: Flask, message: str):
log_output_for_tests(app, f"WARNING: {message}\n")
log_output_for_tests(app, f"WARNING: {message}")
app.logger.warning(message)
def mylog_error(app: Flask, message: str):
log_output_for_tests(app, f"ERROR: {message}\n")
log_output_for_tests(app, f"ERROR: {message}")
app.logger.error(message)
def mylog_critical(app: Flask, message: str):
log_output_for_tests(app, f"CRITICAL: {message}\n")
log_output_for_tests(app, f"CRITICAL: {message}")
app.logger.critical(message)

View File

@ -23,10 +23,10 @@ class BaseTestCase(TestCase):
return self.app
def setUp(self):
mylog_info(self.app, f"setting up {self.id()}")
set_mylog_test_id(self.id())
def tearDown(self):
mylog_info(self.app, f"tearing down {self.id()}")
set_mylog_test_id("")
def _login(self, user_email):
get_model().login(user_email)