Exemplo 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
Exemplo 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)
Exemplo n.º 3
0
def area():
    """Get an instance of Area."""
    area = next(iter(Site(site_key)))
    global area_key
    area_key = area.key
    yield area
Exemplo n.º 4
0
def test_key_raises():
    """Constructing Site with an invalid key should raise an exception."""
    with pytest.raises(ValueError):
        Site("invalid_key")
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
def test_key():
    """Test `key` attribute of site instance."""
    site_key = Site(key).key
    expected_key = key
    assert site_key == expected_key