from scraper import search_CL
from scraper import read_search_results
from scraper import parse_source
from scraper import extract_listings
from scraper import fetch_json_results
from scraper import read_json_results
from types import GeneratorType
import bs4


def test_search_CL():
    test_body, test_encoding = search_CL(minAsk=500, maxAsk=1000, bedrooms=2)
    assert "<span class=\"desktop\">craigslist</span>" in test_body
    assert test_encoding == 'utf-8'


def test_json_search():
    json = fetch_json_results()
    assert isinstance(json, list)
    assert isinstance(json[0], list)
    assert isinstance(json[0][0], dict)
    assert json[-1][u'baseurl'] == u'//seattle.craigslist.org'


def test_read_json():
    json = read_json_results()
    assert isinstance(json, list)
    assert isinstance(json[0], list)
    assert isinstance(json[0][0], dict)
    assert json[-1][u'baseurl'] == u'//seattle.craigslist.org'


def test_read_search_result():
    test_body, test_encoding = read_search_results()
    assert "<span class=\"desktop\">craigslist</span>" in test_body
    assert test_encoding == 'utf-8'


def test_parse_source():
    test_body, test_encoding = read_search_results()
    test_parse = parse_source(test_body, test_encoding)
    assert isinstance(test_parse, bs4.BeautifulSoup)


def test_extract_listings():
    test_body, test_encoding = read_search_results()
    test_parse = parse_source(test_body, test_encoding)
    test_data = extract_listings(test_parse)
    assert isinstance(test_data, GeneratorType)
    for dict_ in test_data:
        assert isinstance(dict_, dict)
@@ -206,24 +206,57 @@
 son_results%0A
+from scraper import add_location%0A
 from types i
@@ -1627,12 +1627,476 @@
 dict_, dict)
+%0A%0A%0Adef test_add_location_1():%0A    listing = %7B'pid': u'1'%7D%0A    search = %7B%0A        u'1': %7B'Latitude': 45.0, 'Longitude': 90.0%7D,%0A        u'2': %7B'Latitude': 30.0, 'Longitude': 90.0%7D%0A    %7D%0A    assert add_location(listing, search) == True%0A%0Adef test_add_location_2():%0A    listing = %7B'pid': u'3'%7D%0A    search = %7B%0A        u'1': %7B'Latitude': 45.0, 'Longitude': 90.0%7D,%0A        u'2': %7B'Latitude': 30.0, 'Longitude': 90.0%7D%0A    %7D%0A    assert add_location(listing, search) == False

Add tests for add_location() that verify that function returns the proper bool based on the presence of the pid being in both the html listing and the json search