def test_save_object_invalid():
    s = Scraper(juris, '/tmp/')
    p = Person('Michael Jordan')
    # no source, won't validate

    with pytest.raises(ValueError):
        s.save_object(p)
def test_save_related():
    s = Scraper(juris, '/tmp/')
    p = Person('Michael Jordan')
    p.add_source('http://example.com')
    o = Organization('Chicago Bulls', classification='committee')
    o.add_source('http://example.com')
    p._related.append(o)

    with mock.patch('json.dump') as json_dump:
        s.save_object(p)

    assert json_dump.mock_calls == [mock.call(p.as_dict(), mock.ANY, cls=mock.ANY),
                                    mock.call(o.as_dict(), mock.ANY, cls=mock.ANY)]
def test_save_object_basics():
    # ensure that save object dumps a file
    s = Scraper(juris, '/tmp/')
    p = Person('Michael Jordan')
    p.add_source('http://example.com')

    with mock.patch('json.dump') as json_dump:
        s.save_object(p)

    # ensure object is saved in right place
    filename = 'person_' + p._id + '.json'
    assert filename in s.output_names['person']
    json_dump.assert_called_once_with(p.as_dict(), mock.ANY, cls=mock.ANY)