Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Tests utils.common
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijie committed Mar 3, 2017
1 parent 7af65b8 commit 19b09d0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
Empty file added tests/__init__.py
Empty file.
60 changes: 60 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-

"""
tests.common
~~~~~~~~~~~~
Tests utils.common
:author: Feei <[email protected]>
:homepage: https://github.com/wufeifei/cobra
:license: MIT, see LICENSE for more details.
:copyright: Copyright (c) 2017 Feei. All rights reserved
"""
from utils import common


def test_convert_time():
time = common.convert_time(129)
assert time == '2\xe2\x80\xb29\xe2\x80\xb3'


def test_convert_number():
number = common.convert_number(1234)
assert number == '1,234'


def test_md5():
md5 = common.md5('Cobra')
assert md5 == 'd13eca1c700558f57d0310ef14277cc2'


def test_allowed_file():
is_allowed = common.allowed_file('test01/test02/file.rar')
assert is_allowed is True


def test_to_bool():
test_bool = ['yes', 1, 'y', 'true', 't']
for tb in test_bool:
assert common.to_bool(tb) is True


def test_path_to_short():
path = '/impl/src/main/java/com/mogujie/service/mgs/digitalcert/utils/CertUtil.java'
short_path = common.path_to_short(path)
assert 'impl/src/.../utils/CertUtil.java' == short_path


def test_path_to_file():
path = '/impl/src/main/java/com/mogujie/service/mgs/digitalcert/utils/CertUtil.java'
short_file = common.path_to_file(path)
assert '.../CertUtil.java' == short_file


def test_percent():
assert '20.0%' == common.percent(20, 100)


def test_format_gmt():
assert '2016-09-14 17:57:41' == common.format_gmt('Wed, 14 Sep 2016 17:57:41 GMT')
12 changes: 1 addition & 11 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@
logging = logging.getLogger(__name__)


def convert_timestamp(stamp):
"""returns a datetime.date object off a timestamp"""
# Really, this should be implemented using time.strptime()
date_shards = stamp.split()
date_shards = date_shards[0].split('-')
date_shards = [x.lstrip('0') for x in date_shards]
processed_date = datetime.date(int(date_shards[0]), int(date_shards[1]), int(date_shards[2]))
return processed_date


def convert_time(seconds):
"""
Seconds to minute/second
Expand All @@ -56,7 +46,7 @@ def convert_number(number):
if number is None or number == 0:
return 0
number = int(number)
return '{:20,}'.format(number)
return '{:20,}'.format(number).strip()


def md5(content):
Expand Down

0 comments on commit 19b09d0

Please sign in to comment.