From 0f04cde4b508483495d8162114bf21b9d53c7b49 Mon Sep 17 00:00:00 2001
From: roadscape <roadscape@users.noreply.github.com>
Date: Fri, 22 Jun 2018 13:35:04 -0500
Subject: [PATCH] pytest config, utils-account test

---
 Makefile                    |  2 +-
 Pipfile                     |  9 +++++----
 bin/lint                    |  4 ++--
 pylintrc                    |  4 +++-
 setup.cfg                   |  2 +-
 setup.py                    | 16 +++++++++-------
 tests/test_utils_account.py | 36 ++++++++++++++++++++++++++++++++++++
 7 files changed, 57 insertions(+), 16 deletions(-)
 create mode 100644 tests/test_utils_account.py

diff --git a/Makefile b/Makefile
index 5b3ef9407..1109510ee 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 0eef591d6..b49322893 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 46c64ac5e..465cebe56 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 864ff9fbe..995adbc7c 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 936223e8c..3eea5fcd4 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 c938e025f..44e1c0c8f 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 000000000..8398894b8
--- /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'] == ''
-- 
GitLab