diff --git a/Makefile b/Makefile index 5b3ef940705c9a71f3db3e0ca82d12206bec9f1a..1109510eecd10b6847afeb80d11f6a27a6a183a2 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ test: test-without-build build test-without-build: test-without-lint test-pylint test-without-lint: - py.test tests + py.test --cov=hive test-pylint: py.test --pylint -m pylint $(PROJECT_NAME) diff --git a/Pipfile b/Pipfile index 0eef591d6e6cddc98f293f8c4d74dbae89df3fe4..b493228931a459f863517c0437f5b8cdbcc67b1b 100644 --- a/Pipfile +++ b/Pipfile @@ -19,11 +19,12 @@ aiomysql = "*" [dev-packages] -ipython = "*" +"ipython" = "*" "pep8" = "*" -pytest = "*" -"pytest-console-scripts" = "*" +"pytest" = "*" +"pytest-cov" = "*" "pytest-docker" = "*" "pytest-pylint" = "*" -yapf = "*" +"pytest-console-scripts" = "*" +"yapf" = "*" "autopep8" = "*" diff --git a/bin/lint b/bin/lint index 46c64ac5ee7963d605a6d7895f11f6176ca788bd..465cebe561e6919f7ce1f5edccfb0158e956dff5 100755 --- a/bin/lint +++ b/bin/lint @@ -1,8 +1,8 @@ if [ -z "$1" ] then - pylint hive/**/*.py -f colorized -r n --disable=fixme + pylint hive/**/*.py -f colorized -r n grep -r --color=always 'pylint: disable' hive else - pylint $1 -f colorized -r n --disable=fixme + pylint $1 -f colorized -r n grep -r --color=always 'pylint: disable' $1 fi diff --git a/pylintrc b/pylintrc index 864ff9fbe6144611b5920b570fd4c75ba91ffbf5..995adbc7cfebb66971bd83fc21d7007f628585e1 100644 --- a/pylintrc +++ b/pylintrc @@ -116,7 +116,9 @@ disable= using-cmp-argument, setslice-method, oct-method, - coerce-method + coerce-method, + #custom + fixme [REPORTS] diff --git a/setup.cfg b/setup.cfg index 936223e8cc92274eef7ee664094d57cf4d2dd09e..3eea5fcd49dfb5fcb57ff08ec5d5c4ecfa7fc5ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,7 +18,7 @@ ignore = E501 [tool:pytest] norecursedirs=dist docs build .tox deploy -addopts = --pylint +adopts = --pylint [coverage:run] diff --git a/setup.py b/setup.py index c938e025f1a5628c36c94018cf8524712280dedb..44e1c0c8f6fa5f4fce26b0259e1931d3a77a3183 100644 --- a/setup.py +++ b/setup.py @@ -14,13 +14,15 @@ setup( long_description=open('README.md').read(), packages=find_packages(exclude=['scripts']), setup_requires=['pytest-runner'], - tests_require=['pytest', - 'pep8', - 'pytest-pylint', - 'yapf', - 'git-pylint-commit-hook', - 'pytest-console-scripts'], - + tests_require=[ + 'pytest', + 'pytest-cov', + 'pytest-pylint', + 'pytest-console-scripts', + 'git-pylint-commit-hook', + 'pep8', + 'yapf', + ], install_requires=[ 'aiopg', 'jsonrpcserver', diff --git a/tests/test_utils_account.py b/tests/test_utils_account.py new file mode 100644 index 0000000000000000000000000000000000000000..8398894b88e58e409c4eb06392cdfc693ec3539b --- /dev/null +++ b/tests/test_utils_account.py @@ -0,0 +1,36 @@ +import json + +from hive.utils.account import safe_profile_metadata + +def test_valid_account(): + raw_profile = dict( + name='Leonardo Da Vinci', + about='Renaissance man, vegetarian, inventor of the helicopter in 1512 and painter of the Mona Lisa.', + location='Florence', + website='http://www.davincilife.com/', + cover_image='https://steemitimages.com/0x0/https://pbs.twimg.com/profile_banners/816255358066946050/1483447009/1500x500', + profile_image='https://www.parhlo.com/wp-content/uploads/2016/01/tmp617041537745813506.jpg', + ) + account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile))} + + safe_profile = safe_profile_metadata(account) + for key, safe_value in safe_profile.items(): + assert raw_profile[key] == safe_value + +def test_invalid_account(): + raw_profile = dict( + name='NameIsTooBigByOneChar', + location='Florence\x00', + website='davincilife.com/', + cover_image='example.com/avatar.jpg', + profile_image='https://example.com/valid-url-but-longer-than-1024-chars' + 'x' * 1024, + ) + account = {'name': 'foo', 'json_metadata': json.dumps(dict(profile=raw_profile))} + + safe_profile = safe_profile_metadata(account) + assert safe_profile['name'] == 'NameIsTooBigByOne...' + assert safe_profile['about'] == '' + assert safe_profile['location'] == '' + assert safe_profile['website'] == 'http://davincilife.com/' # TODO: should normalize to https? + assert safe_profile['cover_image'] == '' + assert safe_profile['profile_image'] == ''