Make it possible to set the instance admin
This commit is contained in:
@@ -17,9 +17,60 @@
|
||||
"""General tests for Calendar.social
|
||||
"""
|
||||
|
||||
from flask import current_app
|
||||
|
||||
import pytest
|
||||
|
||||
def test_index_no_login(client):
|
||||
"""Test the main page without logging in
|
||||
"""
|
||||
|
||||
page = client.get('/')
|
||||
assert b'Peek inside' in page.data
|
||||
|
||||
|
||||
def test_instance_adin_unset(database):
|
||||
"""Test the instance admin feature if the admin is not set
|
||||
"""
|
||||
|
||||
with pytest.warns(UserWarning, match=r'Instance admin is not set correctly \(value is None\)'):
|
||||
assert current_app.instance_admin is None
|
||||
|
||||
|
||||
def test_instance_admin_bad_value(database):
|
||||
"""Test the instance admin feature if the value is invalid
|
||||
"""
|
||||
|
||||
from calsocial.models import AppState
|
||||
|
||||
AppState['instance_admin'] = 'value'
|
||||
|
||||
with pytest.warns(UserWarning, match=r'Instance admin is not set correctly \(value is value\)'):
|
||||
assert current_app.instance_admin is None
|
||||
|
||||
|
||||
def test_instance_admin_doesnot_exist(database):
|
||||
"""Test the instance admin feature if the admin user does not exist
|
||||
"""
|
||||
|
||||
from calsocial.models import AppState
|
||||
|
||||
AppState['instance_admin'] = '0'
|
||||
|
||||
with pytest.warns(UserWarning, match=r'Instance admin is not set correctly \(value is 0\)'):
|
||||
assert current_app.instance_admin is None
|
||||
|
||||
|
||||
def test_instance_admin(database):
|
||||
"""Test the instance admin feature if the admin user does not exist
|
||||
"""
|
||||
|
||||
from calsocial.models import db, AppState, User
|
||||
|
||||
user = User(username='admin')
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
AppState['instance_admin'] = user.id
|
||||
|
||||
assert current_app.instance_admin == user
|
||||
|
Reference in New Issue
Block a user