server/tags: fix wrong case in merging requests
This commit is contained in:
parent
59ae0a4c9a
commit
a5b2d835d6
3 changed files with 15 additions and 15 deletions
2
API.md
2
API.md
|
@ -461,7 +461,7 @@ data.
|
||||||
```json5
|
```json5
|
||||||
{
|
{
|
||||||
"remove": <source-tag-name>,
|
"remove": <source-tag-name>,
|
||||||
"merge-to": <target-tag-name>
|
"mergeTo": <target-tag-name>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ class TagDetailApi(BaseApi):
|
||||||
class TagMergeApi(BaseApi):
|
class TagMergeApi(BaseApi):
|
||||||
def post(self, ctx):
|
def post(self, ctx):
|
||||||
source_tag_name = ctx.get_param_as_string('remove', required=True) or ''
|
source_tag_name = ctx.get_param_as_string('remove', required=True) or ''
|
||||||
target_tag_name = ctx.get_param_as_string('merge-to', required=True) or ''
|
target_tag_name = ctx.get_param_as_string('mergeTo', required=True) or ''
|
||||||
source_tag = tags.get_tag_by_name(source_tag_name)
|
source_tag = tags.get_tag_by_name(source_tag_name)
|
||||||
target_tag = tags.get_tag_by_name(target_tag_name)
|
target_tag = tags.get_tag_by_name(target_tag_name)
|
||||||
if source_tag.tag_id == target_tag.tag_id:
|
if source_tag.tag_id == target_tag.tag_id:
|
||||||
|
|
|
@ -30,7 +30,7 @@ def test_merging_without_usages(test_ctx, fake_datetime):
|
||||||
test_ctx.context_factory(
|
test_ctx.context_factory(
|
||||||
input={
|
input={
|
||||||
'remove': 'source',
|
'remove': 'source',
|
||||||
'merge-to': 'target',
|
'mergeTo': 'target',
|
||||||
},
|
},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
||||||
assert result['tag'] == {
|
assert result['tag'] == {
|
||||||
|
@ -66,7 +66,7 @@ def test_merging_with_usages(test_ctx, fake_datetime, post_factory):
|
||||||
test_ctx.context_factory(
|
test_ctx.context_factory(
|
||||||
input={
|
input={
|
||||||
'remove': 'source',
|
'remove': 'source',
|
||||||
'merge-to': 'target',
|
'mergeTo': 'target',
|
||||||
},
|
},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
||||||
assert tags.try_get_tag_by_name('source') is None
|
assert tags.try_get_tag_by_name('source') is None
|
||||||
|
@ -76,9 +76,9 @@ def test_merging_with_usages(test_ctx, fake_datetime, post_factory):
|
||||||
({'remove': None}, tags.TagNotFoundError),
|
({'remove': None}, tags.TagNotFoundError),
|
||||||
({'remove': ''}, tags.TagNotFoundError),
|
({'remove': ''}, tags.TagNotFoundError),
|
||||||
({'remove': []}, tags.TagNotFoundError),
|
({'remove': []}, tags.TagNotFoundError),
|
||||||
({'merge-to': None}, tags.TagNotFoundError),
|
({'mergeTo': None}, tags.TagNotFoundError),
|
||||||
({'merge-to': ''}, tags.TagNotFoundError),
|
({'mergeTo': ''}, tags.TagNotFoundError),
|
||||||
({'merge-to': []}, tags.TagNotFoundError),
|
({'mergeTo': []}, tags.TagNotFoundError),
|
||||||
])
|
])
|
||||||
def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
|
def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
|
||||||
source_tag = test_ctx.tag_factory(names=['source'], category_name='meta')
|
source_tag = test_ctx.tag_factory(names=['source'], category_name='meta')
|
||||||
|
@ -87,7 +87,7 @@ def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
real_input = {
|
real_input = {
|
||||||
'remove': 'source',
|
'remove': 'source',
|
||||||
'merge-to': 'target',
|
'mergeTo': 'target',
|
||||||
}
|
}
|
||||||
for key, value in input.items():
|
for key, value in input.items():
|
||||||
real_input[key] = value
|
real_input[key] = value
|
||||||
|
@ -98,7 +98,7 @@ def test_trying_to_pass_invalid_input(test_ctx, input, expected_exception):
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'field', ['remove', 'merge-to'])
|
'field', ['remove', 'mergeTo'])
|
||||||
def test_trying_to_omit_mandatory_field(test_ctx, field):
|
def test_trying_to_omit_mandatory_field(test_ctx, field):
|
||||||
db.session.add_all([
|
db.session.add_all([
|
||||||
test_ctx.tag_factory(names=['source'], category_name='meta'),
|
test_ctx.tag_factory(names=['source'], category_name='meta'),
|
||||||
|
@ -107,7 +107,7 @@ def test_trying_to_omit_mandatory_field(test_ctx, field):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
input = {
|
input = {
|
||||||
'remove': 'source',
|
'remove': 'source',
|
||||||
'merge-to': 'target',
|
'mergeTo': 'target',
|
||||||
}
|
}
|
||||||
del input[field]
|
del input[field]
|
||||||
with pytest.raises(errors.ValidationError):
|
with pytest.raises(errors.ValidationError):
|
||||||
|
@ -122,12 +122,12 @@ def test_trying_to_merge_non_existing(test_ctx):
|
||||||
with pytest.raises(tags.TagNotFoundError):
|
with pytest.raises(tags.TagNotFoundError):
|
||||||
test_ctx.api.post(
|
test_ctx.api.post(
|
||||||
test_ctx.context_factory(
|
test_ctx.context_factory(
|
||||||
input={'remove': 'good', 'merge-to': 'bad'},
|
input={'remove': 'good', 'mergeTo': 'bad'},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
||||||
with pytest.raises(tags.TagNotFoundError):
|
with pytest.raises(tags.TagNotFoundError):
|
||||||
test_ctx.api.post(
|
test_ctx.api.post(
|
||||||
test_ctx.context_factory(
|
test_ctx.context_factory(
|
||||||
input={'remove': 'bad', 'merge-to': 'good'},
|
input={'remove': 'bad', 'mergeTo': 'good'},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
||||||
|
|
||||||
def test_trying_to_merge_to_itself(test_ctx):
|
def test_trying_to_merge_to_itself(test_ctx):
|
||||||
|
@ -136,7 +136,7 @@ def test_trying_to_merge_to_itself(test_ctx):
|
||||||
with pytest.raises(tags.InvalidTagRelationError):
|
with pytest.raises(tags.InvalidTagRelationError):
|
||||||
test_ctx.api.post(
|
test_ctx.api.post(
|
||||||
test_ctx.context_factory(
|
test_ctx.context_factory(
|
||||||
input={'remove': 'good', 'merge-to': 'good'},
|
input={'remove': 'good', 'mergeTo': 'good'},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)))
|
||||||
|
|
||||||
@pytest.mark.parametrize('input', [
|
@pytest.mark.parametrize('input', [
|
||||||
|
@ -156,6 +156,6 @@ def test_trying_to_merge_without_privileges(test_ctx, input):
|
||||||
test_ctx.context_factory(
|
test_ctx.context_factory(
|
||||||
input={
|
input={
|
||||||
'remove': 'source',
|
'remove': 'source',
|
||||||
'merge-to': 'target',
|
'mergeTo': 'target',
|
||||||
},
|
},
|
||||||
user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
|
user=test_ctx.user_factory(rank=db.User.RANK_ANONYMOUS)))
|
||||||
|
|
Loading…
Reference in a new issue