mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Simplify Config setup and move some functions to dedicated files
This commit is contained in:
		@@ -0,0 +1,6 @@
 | 
			
		||||
from config import Config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestConfig(Config):
 | 
			
		||||
    TESTING = True
 | 
			
		||||
    SQLALCHEMY_DATABASE_URI = 'sqlite://'
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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={
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user