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

Commit

Permalink
add test case for search api
Browse files Browse the repository at this point in the history
  • Loading branch information
40huo committed Sep 12, 2017
1 parent 9728c95 commit 7e31378
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ def test_result_detail():
assert 'No such target' in re.text


def test_search():
url = 'http://127.0.0.1:5000/api/search'
post_data = {
'sid': s_sid,
'rule_id': ["110001", "110005"],
}
headers = {
"Content-Type": "application/json",
}
re = requests.post(url=url, data=json.dumps(post_data), headers=headers)

s_sid_file = os.path.join(running_path, '{sid}_data'.format(sid=s_sid))
if os.path.exists(s_sid_file):
assert '1001' in re.text
assert 'search_result' in re.text
else:
assert '1002' in re.text
assert 'No such sid' in re.text


def test_index():
url = 'http://127.0.0.1:5000/'
re = requests.get(url=url)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ def test_percent():

def test_format_gmt():
assert format_gmt('Wed, 14 Sep 2016 17:57:41 GMT') == '2016-09-14 17:57:41'


def test_split_branch():
target_str = 'https://github.com/test/test.git:dev'
target, branch = split_branch(target_str)
assert target == 'https://github.com/test/test.git'
assert branch == 'dev'
target_str = 'https://github.com/test/test.git'
target, branch = split_branch(target_str)
assert target == 'https://github.com/test/test.git'
assert branch == 'master'


def test_secure_filename():
assert secure_filename(u'正则.测试.md') == u'正则.测试.md'
assert secure_filename('../../../etc/passwd').count('/') == 0

0 comments on commit 7e31378

Please sign in to comment.