server/tests: fix pylint score
This commit is contained in:
parent
5f29fa12c2
commit
c46dc08c1b
|
@ -1,24 +1,18 @@
|
||||||
from datetime import datetime
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from szurubooru import api, db, errors, config
|
from szurubooru import api, errors
|
||||||
from szurubooru.util import auth, misc, mailer
|
from szurubooru.util import auth, mailer
|
||||||
from szurubooru.tests.database_test_case import DatabaseTestCase
|
from szurubooru.tests.database_test_case import DatabaseTestCase
|
||||||
from szurubooru.tests.api import util
|
from szurubooru.tests.api import util
|
||||||
|
|
||||||
class TestPasswordReset(DatabaseTestCase):
|
class TestPasswordReset(DatabaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
config_mock = {
|
util.mock_config({
|
||||||
'secret': 'x',
|
'secret': 'x',
|
||||||
'base_url': 'http://example.com/',
|
'base_url': 'http://example.com/',
|
||||||
'name': 'Test instance',
|
'name': 'Test instance',
|
||||||
}
|
})
|
||||||
self.old_config = config.config
|
util.mock_context(self)
|
||||||
config.config = config_mock
|
|
||||||
self.context = misc.dotdict()
|
|
||||||
self.context.session = self.session
|
|
||||||
self.context.request = {}
|
|
||||||
self.context.user = db.User()
|
|
||||||
self.api = api.PasswordResetApi()
|
self.api = api.PasswordResetApi()
|
||||||
|
|
||||||
def test_reset_non_existing(self):
|
def test_reset_non_existing(self):
|
||||||
|
@ -35,10 +29,9 @@ class TestPasswordReset(DatabaseTestCase):
|
||||||
user.email = 'user@example.com'
|
user.email = 'user@example.com'
|
||||||
self.session.add(user)
|
self.session.add(user)
|
||||||
for getter in ['u1', 'user@example.com']:
|
for getter in ['u1', 'user@example.com']:
|
||||||
with mock.MagicMock() as mock_method:
|
mailer.send_mail = mock.MagicMock()
|
||||||
mailer.send_mail = mock_method
|
|
||||||
self.assertEqual({}, self.api.get(self.context, getter))
|
self.assertEqual({}, self.api.get(self.context, getter))
|
||||||
mock_method.assert_called_once_with(
|
mailer.send_mail.assert_called_once_with(
|
||||||
'noreply@Test instance',
|
'noreply@Test instance',
|
||||||
'user@example.com',
|
'user@example.com',
|
||||||
'Password reset for Test instance',
|
'Password reset for Test instance',
|
||||||
|
|
|
@ -1,26 +1,21 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from szurubooru import api, db, errors, config
|
from szurubooru import api, db, errors
|
||||||
from szurubooru.util import auth, misc
|
from szurubooru.util import auth
|
||||||
from szurubooru.tests.database_test_case import DatabaseTestCase
|
from szurubooru.tests.database_test_case import DatabaseTestCase
|
||||||
from szurubooru.tests.api import util
|
from szurubooru.tests.api import util
|
||||||
|
|
||||||
class TestRetrievingUsers(DatabaseTestCase):
|
class TestRetrievingUsers(DatabaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
config_mock = {
|
util.mock_config({
|
||||||
'privileges': {
|
'privileges': {
|
||||||
'users:list': 'regular_user',
|
'users:list': 'regular_user',
|
||||||
'users:view': 'regular_user',
|
'users:view': 'regular_user',
|
||||||
'users:create': 'regular_user',
|
'users:create': 'regular_user',
|
||||||
},
|
},
|
||||||
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
||||||
}
|
})
|
||||||
self.old_config = config.config
|
util.mock_context(self)
|
||||||
config.config = config_mock
|
|
||||||
self.context = misc.dotdict()
|
|
||||||
self.context.session = self.session
|
|
||||||
self.context.request = {}
|
|
||||||
self.context.user = db.User()
|
|
||||||
|
|
||||||
def test_retrieving_multiple(self):
|
def test_retrieving_multiple(self):
|
||||||
user1 = util.mock_user('u1', 'mod')
|
user1 = util.mock_user('u1', 'mod')
|
||||||
|
@ -71,7 +66,7 @@ class TestRetrievingUsers(DatabaseTestCase):
|
||||||
class TestCreatingUser(DatabaseTestCase):
|
class TestCreatingUser(DatabaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
config_mock = {
|
util.mock_config({
|
||||||
'secret': '',
|
'secret': '',
|
||||||
'user_name_regex': '.{3,}',
|
'user_name_regex': '.{3,}',
|
||||||
'password_regex': '.{3,}',
|
'password_regex': '.{3,}',
|
||||||
|
@ -80,19 +75,11 @@ class TestCreatingUser(DatabaseTestCase):
|
||||||
'privileges': {
|
'privileges': {
|
||||||
'users:create': 'anonymous',
|
'users:create': 'anonymous',
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
self.old_config = config.config
|
|
||||||
config.config = config_mock
|
|
||||||
self.api = api.UserListApi()
|
self.api = api.UserListApi()
|
||||||
self.context = misc.dotdict()
|
util.mock_context(self)
|
||||||
self.context.session = self.session
|
|
||||||
self.context.request = {}
|
|
||||||
self.context.user = db.User()
|
|
||||||
self.context.user.rank = 'anonymous'
|
self.context.user.rank = 'anonymous'
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
config.config = self.old_config
|
|
||||||
|
|
||||||
def test_creating_valid_user(self):
|
def test_creating_valid_user(self):
|
||||||
self.context.request = {
|
self.context.request = {
|
||||||
'name': 'chewie',
|
'name': 'chewie',
|
||||||
|
@ -139,7 +126,7 @@ class TestCreatingUser(DatabaseTestCase):
|
||||||
class TestUpdatingUser(DatabaseTestCase):
|
class TestUpdatingUser(DatabaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
config_mock = {
|
util.mock_config({
|
||||||
'secret': '',
|
'secret': '',
|
||||||
'user_name_regex': '.{3,}',
|
'user_name_regex': '.{3,}',
|
||||||
'password_regex': '.{3,}',
|
'password_regex': '.{3,}',
|
||||||
|
@ -155,16 +142,9 @@ class TestUpdatingUser(DatabaseTestCase):
|
||||||
'users:edit:any:email': 'mod',
|
'users:edit:any:email': 'mod',
|
||||||
'users:edit:any:rank': 'admin',
|
'users:edit:any:rank': 'admin',
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
self.old_config = config.config
|
util.mock_context(self)
|
||||||
config.config = config_mock
|
|
||||||
self.api = api.UserDetailApi()
|
self.api = api.UserDetailApi()
|
||||||
self.context = misc.dotdict()
|
|
||||||
self.context.session = self.session
|
|
||||||
self.context.request = {}
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
config.config = self.old_config
|
|
||||||
|
|
||||||
def test_update_changing_nothing(self):
|
def test_update_changing_nothing(self):
|
||||||
admin_user = util.mock_user('u1', 'admin')
|
admin_user = util.mock_user('u1', 'admin')
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from szurubooru import db
|
from szurubooru import config, db
|
||||||
|
from szurubooru.util import misc
|
||||||
|
|
||||||
|
def mock_config(config_mock):
|
||||||
|
config.config = config_mock
|
||||||
|
|
||||||
def mock_user(name, rank='admin'):
|
def mock_user(name, rank='admin'):
|
||||||
user = db.User()
|
user = db.User()
|
||||||
|
@ -13,6 +17,13 @@ def mock_user(name, rank='admin'):
|
||||||
user.avatar_style = db.User.AVATAR_GRAVATAR
|
user.avatar_style = db.User.AVATAR_GRAVATAR
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
def mock_context(parent):
|
||||||
|
context = misc.dotdict()
|
||||||
|
context.session = parent.session
|
||||||
|
context.request = {}
|
||||||
|
context.user = db.User()
|
||||||
|
parent.context = context
|
||||||
|
|
||||||
def mock_params(context, params):
|
def mock_params(context, params):
|
||||||
def get_param_as_string(key, default=None):
|
def get_param_as_string(key, default=None):
|
||||||
if key not in params:
|
if key not in params:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from szurubooru import db, errors, search
|
from szurubooru import errors, search
|
||||||
from szurubooru.tests.database_test_case import DatabaseTestCase
|
from szurubooru.tests.database_test_case import DatabaseTestCase
|
||||||
from szurubooru.tests.api import util
|
from szurubooru.tests.api import util
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue