server/tests: fix leftover rank strings

This commit is contained in:
rr- 2016-05-10 12:01:01 +02:00
parent ba3678dec1
commit 14a20e55f8
24 changed files with 35 additions and 41 deletions

View File

@ -87,4 +87,4 @@ def test_trying_to_create_without_privileges(test_ctx):
test_ctx.api.post( test_ctx.api.post(
test_ctx.context_factory( test_ctx.context_factory(
input={}, input={},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))

View File

@ -150,5 +150,5 @@ def test_trying_to_rate_without_privileges(test_ctx):
test_ctx.api.put( test_ctx.api.put(
test_ctx.context_factory( test_ctx.context_factory(
input={'score': 1}, input={'score': 1},
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
comment.comment_id) comment.comment_id)

View File

@ -43,7 +43,7 @@ def test_trying_to_retrieve_multiple_without_privileges(test_ctx):
test_ctx.list_api.get( test_ctx.list_api.get(
test_ctx.context_factory( test_ctx.context_factory(
input={'query': '', 'page': 1}, input={'query': '', 'page': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
def test_retrieving_single(test_ctx): def test_retrieving_single(test_ctx):
comment = test_ctx.comment_factory(text='dummy text') comment = test_ctx.comment_factory(text='dummy text')
@ -74,5 +74,5 @@ def test_trying_to_retrieve_single_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.detail_api.get( test_ctx.detail_api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
5) 5)

View File

@ -118,7 +118,6 @@ def test_creating_from_url_saves_source(
unittest.mock.patch('szurubooru.func.posts.create_post'), \ unittest.mock.patch('szurubooru.func.posts.create_post'), \
unittest.mock.patch('szurubooru.func.posts.update_post_source'): unittest.mock.patch('szurubooru.func.posts.update_post_source'):
config_injector({ config_injector({
'ranks': ['anonymous', db.User.RANK_REGULAR],
'privileges': {'posts:create': db.User.RANK_REGULAR}, 'privileges': {'posts:create': db.User.RANK_REGULAR},
}) })
net.download.return_value = b'content' net.download.return_value = b'content'
@ -150,7 +149,6 @@ def test_creating_from_url_with_source_specified(
unittest.mock.patch('szurubooru.func.posts.create_post'), \ unittest.mock.patch('szurubooru.func.posts.create_post'), \
unittest.mock.patch('szurubooru.func.posts.update_post_source'): unittest.mock.patch('szurubooru.func.posts.update_post_source'):
config_injector({ config_injector({
'ranks': ['anonymous', db.User.RANK_REGULAR],
'privileges': {'posts:create': db.User.RANK_REGULAR}, 'privileges': {'posts:create': db.User.RANK_REGULAR},
}) })
net.download.return_value = b'content' net.download.return_value = b'content'
@ -198,4 +196,4 @@ def test_trying_to_create_without_privileges(context_factory, user_factory):
api.PostListApi().post( api.PostListApi().post(
context_factory( context_factory(
input='whatever', input='whatever',
user=user_factory(rank='anonymous'))) user=user_factory(rank=db.User.RANK_ANONYMOUS)))

View File

@ -43,6 +43,6 @@ def test_trying_to_delete_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.api.delete( test_ctx.api.delete(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
1) 1)
assert db.session.query(db.Post).count() == 1 assert db.session.query(db.Post).count() == 1

View File

@ -124,5 +124,5 @@ def test_trying_to_rate_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.api.post( test_ctx.api.post(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
post.post_id) post.post_id)

View File

@ -98,12 +98,12 @@ def test_trying_to_feature_without_privileges(test_ctx):
test_ctx.api.post( test_ctx.api.post(
test_ctx.context_factory( test_ctx.context_factory(
input={'id': 1}, input={'id': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
def test_getting_featured_post_without_privileges_to_view(test_ctx): def test_getting_featured_post_without_privileges_to_view(test_ctx):
try: try:
test_ctx.api.get( test_ctx.api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
except: except:
pytest.fail() pytest.fail()

View File

@ -144,5 +144,5 @@ def test_trying_to_rate_without_privileges(test_ctx):
test_ctx.api.put( test_ctx.api.put(
test_ctx.context_factory( test_ctx.context_factory(
input={'score': 1}, input={'score': 1},
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
post.post_id) post.post_id)

View File

@ -60,20 +60,19 @@ def test_trying_to_use_special_tokens_without_logging_in(
test_ctx, config_injector): test_ctx, config_injector):
config_injector({ config_injector({
'privileges': {'posts:list': 'anonymous'}, 'privileges': {'posts:list': 'anonymous'},
'ranks': ['anonymous'],
}) })
with pytest.raises(errors.SearchError): with pytest.raises(errors.SearchError):
test_ctx.list_api.get( test_ctx.list_api.get(
test_ctx.context_factory( test_ctx.context_factory(
input={'query': 'special:fav', 'page': 1}, input={'query': 'special:fav', 'page': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
def test_trying_to_retrieve_multiple_without_privileges(test_ctx): def test_trying_to_retrieve_multiple_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.list_api.get( test_ctx.list_api.get(
test_ctx.context_factory( test_ctx.context_factory(
input={'query': '', 'page': 1}, input={'query': '', 'page': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
def test_retrieving_single(test_ctx): def test_retrieving_single(test_ctx):
db.session.add(test_ctx.post_factory(id=1)) db.session.add(test_ctx.post_factory(id=1))
@ -96,5 +95,5 @@ def test_trying_to_retrieve_single_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.detail_api.get( test_ctx.detail_api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'-') '-')

View File

@ -75,7 +75,6 @@ def test_post_updating(
def test_uploading_from_url_saves_source( def test_uploading_from_url_saves_source(
config_injector, context_factory, post_factory, user_factory): config_injector, context_factory, post_factory, user_factory):
config_injector({ config_injector({
'ranks': ['anonymous', db.User.RANK_REGULAR],
'privileges': {'posts:edit:content': db.User.RANK_REGULAR}, 'privileges': {'posts:edit:content': db.User.RANK_REGULAR},
}) })
post = post_factory() post = post_factory()
@ -100,7 +99,6 @@ def test_uploading_from_url_saves_source(
def test_uploading_from_url_with_source_specified( def test_uploading_from_url_with_source_specified(
config_injector, context_factory, post_factory, user_factory): config_injector, context_factory, post_factory, user_factory):
config_injector({ config_injector({
'ranks': ['anonymous', db.User.RANK_REGULAR],
'privileges': { 'privileges': {
'posts:edit:content': db.User.RANK_REGULAR, 'posts:edit:content': db.User.RANK_REGULAR,
'posts:edit:source': db.User.RANK_REGULAR, 'posts:edit:source': db.User.RANK_REGULAR,
@ -152,7 +150,6 @@ def test_trying_to_create_without_privileges(
input, input,
privilege): privilege):
config_injector({ config_injector({
'ranks': ['anonymous', db.User.RANK_REGULAR],
'privileges': {privilege: db.User.RANK_REGULAR}, 'privileges': {privilege: db.User.RANK_REGULAR},
}) })
post = post_factory() post = post_factory()
@ -163,5 +160,5 @@ def test_trying_to_create_without_privileges(
context_factory( context_factory(
input=input, input=input,
files=files, files=files,
user=user_factory(rank='anonymous')), user=user_factory(rank=db.User.RANK_ANONYMOUS)),
post.post_id) post.post_id)

View File

@ -46,4 +46,4 @@ def test_trying_to_retrieve_multiple_without_privileges(test_ctx):
test_ctx.api.get( test_ctx.api.get(
test_ctx.context_factory( test_ctx.context_factory(
input={'query': '', 'page': 1}, input={'query': '', 'page': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))

View File

@ -88,4 +88,4 @@ def test_trying_to_create_without_privileges(test_ctx):
test_ctx.api.post( test_ctx.api.post(
test_ctx.context_factory( test_ctx.context_factory(
input={'name': 'meta', 'color': 'black'}, input={'name': 'meta', 'color': 'black'},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))

View File

@ -74,6 +74,6 @@ def test_trying_to_delete_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.api.delete( test_ctx.api.delete(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'category') 'category')
assert db.session.query(db.TagCategory).count() == 1 assert db.session.query(db.TagCategory).count() == 1

View File

@ -57,5 +57,5 @@ def test_trying_to_retrieve_single_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.detail_api.get( test_ctx.detail_api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'-') '-')

View File

@ -128,5 +128,5 @@ def test_trying_to_update_without_privileges(test_ctx, input):
test_ctx.api.put( test_ctx.api.put(
test_ctx.context_factory( test_ctx.context_factory(
input=input, input=input,
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'dummy') 'dummy')

View File

@ -266,4 +266,4 @@ def test_trying_to_create_tag_without_privileges(test_ctx):
'suggestions': ['tag'], 'suggestions': ['tag'],
'implications': [], 'implications': [],
}, },
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))

View File

@ -56,6 +56,6 @@ def test_trying_to_delete_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.api.delete( test_ctx.api.delete(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'tag') 'tag')
assert db.session.query(db.Tag).count() == 1 assert db.session.query(db.Tag).count() == 1

View File

@ -158,4 +158,4 @@ def test_trying_to_merge_without_privileges(test_ctx, input):
'remove': 'source', 'remove': 'source',
'merge-to': 'target', 'merge-to': 'target',
}, },
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))

View File

@ -39,7 +39,7 @@ def test_trying_to_retrieve_multiple_without_privileges(test_ctx):
test_ctx.list_api.get( test_ctx.list_api.get(
test_ctx.context_factory( test_ctx.context_factory(
input={'query': '', 'page': 1}, input={'query': '', 'page': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
def test_retrieving_single(test_ctx): def test_retrieving_single(test_ctx):
db.session.add(test_ctx.tag_factory(names=['tag'])) db.session.add(test_ctx.tag_factory(names=['tag']))
@ -71,5 +71,5 @@ def test_trying_to_retrieve_single_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.detail_api.get( test_ctx.detail_api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'-') '-')

View File

@ -92,4 +92,4 @@ def test_trying_to_retrieve_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.api.get( test_ctx.api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), '-') user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)), '-')

View File

@ -259,5 +259,5 @@ def test_trying_to_update_without_privileges(test_ctx, input):
test_ctx.api.put( test_ctx.api.put(
test_ctx.context_factory( test_ctx.context_factory(
input=input, input=input,
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'tag') 'tag')

View File

@ -61,7 +61,7 @@ def test_first_user_becomes_admin_others_not(test_ctx):
'email': 'asd@asd.asd', 'email': 'asd@asd.asd',
'password': 'oks', 'password': 'oks',
}, },
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
result2 = test_ctx.api.post( result2 = test_ctx.api.post(
test_ctx.context_factory( test_ctx.context_factory(
input={ input={
@ -69,7 +69,7 @@ def test_first_user_becomes_admin_others_not(test_ctx):
'email': 'asd@asd.asd', 'email': 'asd@asd.asd',
'password': 'sok', 'password': 'sok',
}, },
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
assert result1['user']['rank'] == 'administrator' assert result1['user']['rank'] == 'administrator'
assert result2['user']['rank'] == 'regular' assert result2['user']['rank'] == 'regular'
first_user = users.get_user_by_name('chewie1') first_user = users.get_user_by_name('chewie1')
@ -86,7 +86,7 @@ def test_first_user_does_not_become_admin_if_they_dont_wish_so(test_ctx):
'password': 'oks', 'password': 'oks',
'rank': 'regular', 'rank': 'regular',
}, },
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
assert result['user']['rank'] == 'regular' assert result['user']['rank'] == 'regular'
def test_trying_to_become_someone_else(test_ctx): def test_trying_to_become_someone_else(test_ctx):

View File

@ -39,7 +39,7 @@ def test_trying_to_retrieve_multiple_without_privileges(test_ctx):
test_ctx.list_api.get( test_ctx.list_api.get(
test_ctx.context_factory( test_ctx.context_factory(
input={'query': '', 'page': 1}, input={'query': '', 'page': 1},
user=test_ctx.user_factory(rank='anonymous'))) user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
def test_retrieving_single(test_ctx): def test_retrieving_single(test_ctx):
db.session.add(test_ctx.user_factory(name='u1', rank=db.User.RANK_REGULAR)) db.session.add(test_ctx.user_factory(name='u1', rank=db.User.RANK_REGULAR))
@ -70,5 +70,5 @@ def test_trying_to_retrieve_single_without_privileges(test_ctx):
with pytest.raises(errors.AuthError): with pytest.raises(errors.AuthError):
test_ctx.detail_api.get( test_ctx.detail_api.get(
test_ctx.context_factory( test_ctx.context_factory(
user=test_ctx.user_factory(rank='anonymous')), user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)),
'-') '-')

View File

@ -89,7 +89,7 @@ def test_updating_user(test_ctx):
({'avatarStyle': 'manual'}, users.InvalidAvatarError), # missing file ({'avatarStyle': 'manual'}, users.InvalidAvatarError), # missing file
]) ])
def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception): def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
user = test_ctx.user_factory(name='u1', rank='administrator') user = test_ctx.user_factory(name='u1', rank=db.User.RANK_ADMINISTRATOR)
db.session.add(user) db.session.add(user)
with pytest.raises(expected_exception): with pytest.raises(expected_exception):
test_ctx.api.put( test_ctx.api.put(
@ -100,7 +100,7 @@ def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
def test_omitting_optional_field(test_ctx, tmpdir, field): def test_omitting_optional_field(test_ctx, tmpdir, field):
config.config['data_dir'] = str(tmpdir.mkdir('data')) config.config['data_dir'] = str(tmpdir.mkdir('data'))
config.config['data_url'] = 'http://example.com/data/' config.config['data_url'] = 'http://example.com/data/'
user = test_ctx.user_factory(name='u1', rank='administrator') user = test_ctx.user_factory(name='u1', rank=db.User.RANK_ADMINISTRATOR)
db.session.add(user) db.session.add(user)
input = { input = {
'name': 'chewie', 'name': 'chewie',
@ -119,13 +119,13 @@ def test_omitting_optional_field(test_ctx, tmpdir, field):
assert result is not None assert result is not None
def test_trying_to_update_non_existing(test_ctx): def test_trying_to_update_non_existing(test_ctx):
user = test_ctx.user_factory(name='u1', rank='administrator') user = test_ctx.user_factory(name='u1', rank=db.User.RANK_ADMINISTRATOR)
db.session.add(user) db.session.add(user)
with pytest.raises(users.UserNotFoundError): with pytest.raises(users.UserNotFoundError):
test_ctx.api.put(test_ctx.context_factory(user=user), 'u2') test_ctx.api.put(test_ctx.context_factory(user=user), 'u2')
def test_removing_email(test_ctx): def test_removing_email(test_ctx):
user = test_ctx.user_factory(name='u1', rank='administrator') user = test_ctx.user_factory(name='u1', rank=db.User.RANK_ADMINISTRATOR)
db.session.add(user) db.session.add(user)
test_ctx.api.put( test_ctx.api.put(
test_ctx.context_factory(input={'email': ''}, user=user), 'u1') test_ctx.context_factory(input={'email': ''}, user=user), 'u1')