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_object_invalid(): s = Scraper('jurisdiction', '/tmp/') p = Person('Michael Jordan') # no source, won't validate with pytest.raises(ValueError): s.save_object(p)
def test_save_invalid_object(): s = Scraper('jurisdiction', '2013', '/tmp/') p = Person('Michael Jordan') # no source, won't validate # this is hideous... with assert_raises(ValueError): s.save_object(p)
def test_save_invalid_object(): s = Scraper('jurisdiction', '2013', '/tmp/') p = Person('Michael Jordan') # this is hideous... with assert_raises(ValueError): with mock.patch.object(Person, 'as_dict', new=lambda s: {'bad': 'x'}): s.save_object(p)
def test_save_object_basics(): s = Scraper('jurisdiction', '2013', '/tmp/') p = Person('Michael Jordan') with mock.patch('json.dump') as json_dump: s.save_object(p) # saved in right place filename = 'person_' + p._id + '.json' assert_in(filename, s.output_names['person']) json_dump.assert_called_once_with(p.as_dict(), mock.ANY, cls=mock.ANY)
def test_save_object_basics(): # ensure that save object dumps a file s = Scraper('jurisdiction', '/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)
def test_save_related(): s = Scraper('jurisdiction', '/tmp/') p = Person('Michael Jordan') p.add_source('http://example.com') o = Organization('Chicago Bulls') 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_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)
def test_save_related(): s = Scraper('jurisdiction', '2013', '/tmp/') p = Person('Michael Jordan') o = Organization('Chicago Bulls') p._related.append(o) with mock.patch('json.dump') as json_dump: s.save_object(p) assert_equal(json_dump.mock_calls, [ mock.call(p.as_dict(), mock.ANY, cls=mock.ANY), mock.call(o.as_dict(), mock.ANY, cls=mock.ANY) ])