Simplify Config setup and move some functions to dedicated files

This commit is contained in:
Patrick Jentsch
2021-09-15 12:31:53 +02:00
parent 8a69d6364a
commit 52c25fd563
11 changed files with 81 additions and 136 deletions

View File

@ -0,0 +1,6 @@
from config import Config
class TestConfig(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = 'sqlite://'

View File

@ -1,11 +1,12 @@
import unittest
from flask import current_app
from app import create_app, db
from flask import current_app
from . import TestConfig
import unittest
class BasicsTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app('testing')
self.app = create_app(TestConfig)
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()

View File

@ -1,10 +1,11 @@
import unittest
from app import create_app, db
from . import TestConfig
import unittest
class FlaskClientTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app('testing')
self.app = create_app(TestConfig)
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
@ -48,7 +49,8 @@ class FlaskClientTestCase(unittest.TestCase):
'password2': 'cat'
})
self.assertEqual(response.status_code, 200)
self.assertTrue('Usernames must have only letters, numbers, dots or underscores' in response.get_data(as_text=True))
self.assertTrue(
'Usernames must have only letters, numbers, dots or underscores' in response.get_data(as_text=True))
def test_register_false_email(self):
# register a new account with wrong username
@ -59,7 +61,8 @@ class FlaskClientTestCase(unittest.TestCase):
'password2': 'cat'
})
self.assertEqual(response.status_code, 200)
self.assertTrue('Invalid email address.' in response.get_data(as_text=True))
self.assertTrue(
'Invalid email address.' in response.get_data(as_text=True))
def test_duplicates(self):
# tries to register an account that has already been registered
@ -78,7 +81,8 @@ class FlaskClientTestCase(unittest.TestCase):
'password2': 'cat'
})
self.assertEqual(response.status_code, 200)
self.assertTrue('Username already in use.' in response.get_data(as_text=True))
self.assertTrue(
'Username already in use.' in response.get_data(as_text=True))
response = self.client.post('/auth/register', data={
'email': 'john@example.com',
'username': 'johnsmith',
@ -86,7 +90,8 @@ class FlaskClientTestCase(unittest.TestCase):
'password2': 'cat'
})
self.assertEqual(response.status_code, 200)
self.assertTrue('Email already registered.' in response.get_data(as_text=True))
self.assertTrue(
'Email already registered.' in response.get_data(as_text=True))
def test_admin_forbidden(self):
response = self.client.post('/auth/login', data={

View File

@ -1,12 +1,13 @@
import unittest
import time
from app import create_app, db
from app.models import User, AnonymousUser, Role, Permission
from . import TestConfig
import time
import unittest
class UserModelTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app('testing')
self.app = create_app(TestConfig)
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()