No issue - Add first tests for test_api_helpers.py

This commit is contained in:
Mike Taylor 2020-05-22 13:30:20 -05:00
Родитель 6d9086a4f4
Коммит 96b5be34a6
4 изменённых файлов: 79 добавлений и 0 удалений

Просмотреть файл

@ -2,3 +2,4 @@ Flask==1.1.2
markdown==3.2.1
requests==2.23.0
tqdm==4.46.0
pytest

0
tests/__init__.py Normal file
Просмотреть файл

30
tests/fixtures/test_file_with_thirty_lines.csv поставляемый Normal file
Просмотреть файл

@ -0,0 +1,30 @@
1,google.com
2,youtube.com
3,facebook.com
4,tmall.com
5,qq.com
6,netflix.com
7,baidu.com
8,microsoft.com
9,sohu.com
10,twitter.com
11,login.tmall.com
12,instagram.com
13,taobao.com
14,360.cn
15,linkedin.com
16,jd.com
17,wikipedia.org
18,yahoo.com
19,windowsupdate.com
20,amazon.com
21,apple.com
22,zoom.us
23,sina.com.cn
24,live.com
25,pages.tmall.com
26,weibo.com
27,reddit.com
28,googletagmanager.com
29,adobe.com
30,doubleclick.net
1 1 google.com
2 2 youtube.com
3 3 facebook.com
4 4 tmall.com
5 5 qq.com
6 6 netflix.com
7 7 baidu.com
8 8 microsoft.com
9 9 sohu.com
10 10 twitter.com
11 11 login.tmall.com
12 12 instagram.com
13 13 taobao.com
14 14 360.cn
15 15 linkedin.com
16 16 jd.com
17 17 wikipedia.org
18 18 yahoo.com
19 19 windowsupdate.com
20 20 amazon.com
21 21 apple.com
22 22 zoom.us
23 23 sina.com.cn
24 24 live.com
25 25 pages.tmall.com
26 26 weibo.com
27 27 reddit.com
28 28 googletagmanager.com
29 29 adobe.com
30 30 doubleclick.net

48
tests/test_api_helpers.py Normal file
Просмотреть файл

@ -0,0 +1,48 @@
import os
from trexa.api.endpoints import trim_csv
"""Tests for the API helper methods."""
test_dir = os.path.dirname(os.path.abspath(__file__))
test_csv = os.path.join(test_dir, 'fixtures',
'test_file_with_thirty_lines.csv')
def get_csv_length(desired_length):
"""Helper method for trimming."""
f = trim_csv(test_csv, desired_length)
new_file = []
while True:
try:
new_file.append(next(f))
except StopIteration:
break
return len(new_file)
def test_trimming_smaller():
"""Test that we end up with a smaller file."""
assert get_csv_length(10) == 10
assert get_csv_length(0) == 0
def test_trimming_none():
"""Test that passing in None returns the entire file."""
assert get_csv_length(None) == 30
# Test not passing in a count
f = trim_csv(test_csv)
new_file = []
while True:
try:
new_file.append(next(f))
except StopIteration:
break
assert len(new_file) == 30
def test_trimming_with_garbage():
"""Test that nothing weird happens."""
assert get_csv_length(35) == 30
assert get_csv_length('WHAT') == 30
assert get_csv_length('🤬') == 30
assert get_csv_length(hex(10)) == 30