-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_downloader.py
44 lines (27 loc) · 1.18 KB
/
test_downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from types import NoneType
import io
import pytest
import pandas as pd
from project0 import downloader
def test_fetch_incidents_should_return_unparsed_data_for_valid_url():
valid_url = 'https://www.normanok.gov/sites/default/files/documents/2022-08/2022-08-01_daily_incident_summary.pdf'
got = downloader.fetch_incidents(valid_url)
assert len(got) > 0
def test_fetch_incidents_should_return_nothing_for_invalid_url():
invalid_url = 'https://www.normanok.gov/blah.pdf'
got = downloader.fetch_incidents(invalid_url)
assert isinstance(got, NoneType)
@pytest.fixture
def sample_file():
with open('./tests/resources/sample.pdf', 'rb') as f:
return io.BytesIO(f.read())
@pytest.fixture
def sample_file_df():
return pd.read_csv('./tests/resources/sample_output.csv')
def test_extract_incidents_should_return_data_as_list_for_valid_file(
sample_file, sample_file_df):
got = downloader.extract_incidents(sample_file)
assert len(got) == len(sample_file_df.index)
def test_extract_incidents_should_return_nothing_for_invalid_file():
got = downloader.extract_incidents(io.BytesIO(b'Not a valid PDF BytesIO'))
assert isinstance(got, NoneType)