##// END OF EJS Templates
logging: http logging should limit the data to some sane ammount....
logging: http logging should limit the data to some sane ammount. Despite debug logs aren't production use, we can have situation that this could potentially print GBs of data from commands like file upload. Having some sane limit here is better.

File last commit:

r3363:f08e98b1 default
r3813:8aa49fab stable
Show More
test_schema_types.py
102 lines | 3.4 KiB | text/x-python | PythonLexer
gists: use colander schema to validate input data....
r523 # -*- coding: utf-8 -*-
docs: updated copyrights to 2019
r3363 # Copyright (C) 2016-2019 RhodeCode GmbH
gists: use colander schema to validate input data....
r523 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import colander
import pytest
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 from rhodecode.model.validation_schema.types import (
GroupNameType, RepoNameType, StringBooleanType)
gists: use colander schema to validate input data....
r523
class TestGroupNameType(object):
@pytest.mark.parametrize('given, expected', [
('//group1/group2//', 'group1/group2'),
('//group1///group2//', 'group1/group2'),
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 ('group1/group2///group3', 'group1/group2/group3'),
gists: use colander schema to validate input data....
r523 ])
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 def test_normalize_path(self, given, expected):
result = GroupNameType()._normalize(given)
gists: use colander schema to validate input data....
r523 assert result == expected
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 @pytest.mark.parametrize('given, expected', [
('//group1/group2//', 'group1/group2'),
('//group1///group2//', 'group1/group2'),
('group1/group2///group3', 'group1/group2/group3'),
('v1.2', 'v1.2'),
('/v1.2', 'v1.2'),
('.dirs', '.dirs'),
('..dirs', '.dirs'),
('./..dirs', '.dirs'),
('dir/;name;/;[];/sub', 'dir/name/sub'),
(',/,/,d,,,', 'd'),
('/;/#/,d,,,', 'd'),
('long../../..name', 'long./.name'),
('long../..name', 'long./.name'),
('../', ''),
('\'../"../', ''),
('c,/,/..//./,c,,,/.d/../.........c', 'c/c/.d/.c'),
('c,/,/..//./,c,,,', 'c/c'),
('d../..d', 'd./.d'),
('d../../d', 'd./d'),
('d\;\./\,\./d', 'd./d'),
('d\.\./\.\./d', 'd./d'),
('d\.\./\..\../d', 'd./d'),
])
def test_deserialize_clean_up_name(self, given, expected):
gists: use colander schema to validate input data....
r523 class TestSchema(colander.Schema):
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 field_group = colander.SchemaNode(GroupNameType())
field_repo = colander.SchemaNode(RepoNameType())
gists: use colander schema to validate input data....
r523
schema = TestSchema()
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 cleaned_data = schema.deserialize({
'field_group': given,
'field_repo': given
})
assert cleaned_data['field_group'] == expected
assert cleaned_data['field_repo'] == expected
class TestStringBooleanType(object):
def _get_schema(self):
class Schema(colander.MappingSchema):
bools = colander.SchemaNode(StringBooleanType())
return Schema()
@pytest.mark.parametrize('given, expected', [
('1', True),
('yEs', True),
('true', True),
('0', False),
('NO', False),
('FALSE', False),
])
def test_convert_type(self, given, expected):
schema = self._get_schema()
result = schema.deserialize({'bools':given})
assert result['bools'] == expected
def test_try_convert_bad_type(self):
schema = self._get_schema()
with pytest.raises(colander.Invalid):
result = schema.deserialize({'bools': 'boom'})