def preload_cache(cache, url='http://www.example.com/', content=b'foobar'): metadata = QNetworkCacheMetaData() metadata.setUrl(QUrl(url)) assert metadata.isValid() device = cache.prepare(metadata) assert device is not None device.write(content) cache.insert(device)