Esempio n. 1
0
def test_has_area():
    """Test `has_area` method of a site instance."""
    has_area = Site("boston").has_area()
    expected_has_area = True
    assert has_area == expected_has_area

    has_area = Site("eugene").has_area()
    expected_has_area = False
    assert has_area == expected_has_area
Esempio n. 2
0
def craigsearch(CraigslistObject, site_keys, **kwargs):
    for key in site_keys:
        site = Site(key)
        if site.has_area():
            for area in site:
                yield CraigslistObject(site=site.key(),
                                       area=area.key(),
                                       **kwargs)
        else:
            yield CraigslistObject(site=site.key(), **kwargs)
def get_urls():
    """Get every Craigslist url using craigslist_meta API."""
    all_urls = []
    for site in Site.all():
        if site.has_area():
            for area in site:
                all_urls.append(area.url)
        else:
            all_urls.append(site.url)

    return all_urls
Esempio n. 4
0
def area():
    """Get an instance of Area."""
    area = next(iter(Site(site_key)))
    global area_key
    area_key = area.key
    yield area
Esempio n. 5
0
def test_key_raises():
    """Constructing Site with an invalid key should raise an exception."""
    with pytest.raises(ValueError):
        Site("invalid_key")
Esempio n. 6
0
def test_all():
    """Test `all` method yields all site instances."""
    site_instances = [site for site in Site.all()]
    assert all(isinstance(item, Site) for item in site_instances)
Esempio n. 7
0
def test_url(get_url):
    """Test `url` attribute of site instance."""
    site_url = Site(key).url
    expected_url = get_url(selector, key)
    assert site_url == expected_url
Esempio n. 8
0
def test_title(get_title):
    """Test `title` attribute of site instance."""
    site_title = Site(key).title
    expected_title = get_title(selector, key)
    assert site_title == expected_title
Esempio n. 9
0
def test_children(get_children):
    """Test `children` attribute of site instance."""
    site_children = Site(key).children
    expected_children = list(get_children(selector, key))
    assert site_children == expected_children
Esempio n. 10
0
def test_key():
    """Test `key` attribute of site instance."""
    site_key = Site(key).key
    expected_key = key
    assert site_key == expected_key