-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_scraper.py
35 lines (20 loc) · 867 Bytes
/
test_scraper.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
import pytest
@pytest.fixture(scope="session")
def scrape_craigslist():
from scraper import fetch_search_results
body, encoding = fetch_search_results('Near downtown seattle', 1500,2500,2)
return body, encoding
def test_fetch(scrape_craigslist):
from scraper import read_search_results
body, encoding1 = scrape_craigslist
apartment, encoding2 = read_search_results()
assert apartment == body
assert encoding1 == encoding2
def test_extract_listing(scrape_craigslist):
from scraper import parse_source, extract_listings, read_search_results
body, encoding = scrape_craigslist
parsed_body = parse_source(body, encoding)
extracted = extract_listings(parsed_body)
apartment = parse_source(read_search_results()[0], encoding)
apartment2 = extract_listings(apartment)
assert extracted == apartment2