2021-07-27 18:28:49 +00:00
|
|
|
from io import StringIO
|
|
|
|
import logging
|
|
|
|
import unittest
|
2021-07-16 15:51:06 +00:00
|
|
|
import os
|
|
|
|
from nanoid import generate
|
|
|
|
|
|
|
|
from flask_testing import TestCase
|
2021-07-27 18:28:49 +00:00
|
|
|
from flask import current_app
|
2021-07-16 15:51:06 +00:00
|
|
|
|
|
|
|
from capsulflask import create_app
|
2021-07-17 09:42:44 +00:00
|
|
|
from capsulflask.db import get_model
|
2021-07-16 15:51:06 +00:00
|
|
|
|
|
|
|
class BaseTestCase(TestCase):
|
|
|
|
def create_app(self):
|
|
|
|
# Use default connection paramaters
|
|
|
|
os.environ['POSTGRES_CONNECTION_PARAMETERS'] = "host=localhost port=5432 user=postgres password=dev dbname=capsulflask_test"
|
|
|
|
os.environ['TESTING'] = '1'
|
2021-07-27 17:48:48 +00:00
|
|
|
os.environ['LOG_LEVEL'] = 'DEBUG'
|
2021-07-16 15:51:06 +00:00
|
|
|
os.environ['SPOKE_MODEL'] = 'mock'
|
2021-07-27 17:48:48 +00:00
|
|
|
os.environ['HUB_MODEL'] = 'capsul-flask'
|
2021-07-27 18:28:49 +00:00
|
|
|
self.app = create_app()
|
|
|
|
return self.app
|
2021-07-16 15:51:06 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2021-07-27 18:56:58 +00:00
|
|
|
pass
|
2021-07-16 15:51:06 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2021-07-27 18:56:58 +00:00
|
|
|
pass
|
2021-07-16 15:51:06 +00:00
|
|
|
|
|
|
|
def _login(self, user_email):
|
2021-07-17 09:42:44 +00:00
|
|
|
get_model().login(user_email)
|
2021-07-16 15:51:06 +00:00
|
|
|
with self.client.session_transaction() as session:
|
|
|
|
session['account'] = user_email
|
|
|
|
session['csrf-token'] = generate()
|
2021-07-27 18:28:49 +00:00
|
|
|
|