test/builder: mock koji file uploads
Replace the "fast_incremental_upload" of the plugin with a custom one that will keeps track of all uploaded files through it. Can be used to ensure that certain uploads happen. NB: this assumes that "fast_incremental_upload" was or will be directly imported into the plugin namespace.
This commit is contained in:
parent
3342f88f3b
commit
521bee4700
1 changed files with 31 additions and 0 deletions
|
|
@ -91,9 +91,40 @@ class MockComposer:
|
||||||
return [200, response_headers, json.dumps(result)]
|
return [200, response_headers, json.dumps(result)]
|
||||||
|
|
||||||
|
|
||||||
|
class UploadTracker:
|
||||||
|
"""Mock koji file uploading and keep track of uploaded files
|
||||||
|
|
||||||
|
This assumes that `fast_incremental_upload` will be imported
|
||||||
|
directly into the plugin namespace.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.uploads = {}
|
||||||
|
|
||||||
|
def patch(self, plugin):
|
||||||
|
setattr(plugin,
|
||||||
|
"fast_incremental_upload",
|
||||||
|
self._fast_incremental_upload)
|
||||||
|
|
||||||
|
def _fast_incremental_upload(self, _session, name, fd, path, _tries, _log):
|
||||||
|
upload = self.uploads.get(name, {"path": path})
|
||||||
|
fd.seek(0, os.SEEK_END)
|
||||||
|
upload["pos"] = fd.tell()
|
||||||
|
self.uploads[name] = upload
|
||||||
|
|
||||||
|
def assert_upload(self, name):
|
||||||
|
if name not in self.uploads:
|
||||||
|
raise AssertionError(f"Upload {name} missing")
|
||||||
|
|
||||||
|
|
||||||
@PluginTest.load_plugin("builder")
|
@PluginTest.load_plugin("builder")
|
||||||
class TestBuilderPlugin(PluginTest):
|
class TestBuilderPlugin(PluginTest):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.uploads = UploadTracker()
|
||||||
|
self.uploads.patch(self.plugin)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mock_session():
|
def mock_session():
|
||||||
session = flexmock()
|
session = flexmock()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue