def test_data_set_optional_fields_just_src(): json = '{"src":"http://foo.com","path":"/mount/path"}' with pytest.warns(None) as record: dataset = DownloadableContent.from_json(json) assert dataset == DownloadableContent(src="http://foo.com", path="/mount/path") assert not record.list
def test_data_set_with_enums(): json = '{"src":"http://foo.com","type":"FILE","status":"DONE","path":"/mount/path"}' dataset = DownloadableContent.from_json(json) assert dataset == DownloadableContent(src="http://foo.com", path="/mount/path", type=FetchedType.FILE, status=FetcherStatus.DONE)
def test_data_set_dont_fail_unknown_fields(): json = '{"src":"http://foo.com","foo":"bar","path":"/mount/path"}' dataset = DownloadableContent.from_json(json) assert not hasattr(dataset, "foo")
def test_data_set_optional_missing_src(): json = '{"dst":"http://foo.com", "md5":"42"}' with pytest.raises(KeyError): DownloadableContent.from_json(json)