update call data for unit test
This commit is contained in:
parent
140aeacda0
commit
1d929d0d71
3 changed files with 171 additions and 1 deletions
|
|
@ -44,6 +44,8 @@ class FakeClientSession(BaseFakeClientSession):
|
|||
super(FakeClientSession, self).__init__(*a, **kw)
|
||||
self._calldata = {}
|
||||
self._offsets = {}
|
||||
self._missing_rsession = None
|
||||
# caller can set _missing_rsession to a Recording session to handle missing calls
|
||||
|
||||
def load_calls(self, data):
|
||||
"""Load call data
|
||||
|
|
@ -75,6 +77,9 @@ class FakeClientSession(BaseFakeClientSession):
|
|||
# we may have a series of calls for each key
|
||||
calls = self._calldata.get(key)
|
||||
ofs = self._offsets.get(key, 0)
|
||||
if calls is None:
|
||||
# we don't have it
|
||||
return self._handle_missing(name, args, kwargs)
|
||||
call = calls[ofs]
|
||||
ofs += 1
|
||||
if ofs < len(calls):
|
||||
|
|
@ -90,6 +95,15 @@ class FakeClientSession(BaseFakeClientSession):
|
|||
else:
|
||||
return mock.MagicMock()
|
||||
|
||||
def _handle_missing(self, name, args, kwargs):
|
||||
print('Missing call data for: %s %r %r' % (name, args, kwargs))
|
||||
rsession = self._missing_rsession
|
||||
if rsession is None:
|
||||
return mock.MagicMock()
|
||||
|
||||
# otherwise use the recording session
|
||||
return rsession._callMethod(name, args, kwargs)
|
||||
|
||||
def _munge(self, data):
|
||||
def callback(value):
|
||||
if isinstance(value, list):
|
||||
|
|
|
|||
|
|
@ -56142,5 +56142,155 @@
|
|||
"task_id": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"kwargs": {
|
||||
"queryOpts": {
|
||||
"countOnly": true
|
||||
},
|
||||
"repoID": 2580
|
||||
},
|
||||
"method": "listBuildroots",
|
||||
"result": 2
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
[
|
||||
[
|
||||
"repo_id",
|
||||
"=",
|
||||
2580
|
||||
]
|
||||
],
|
||||
[
|
||||
"id"
|
||||
]
|
||||
],
|
||||
"kwargs": {},
|
||||
"method": "repo.queryQueue",
|
||||
"result": []
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
798
|
||||
],
|
||||
"kwargs": {},
|
||||
"method": "repo.get",
|
||||
"result": null
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
[
|
||||
[
|
||||
"tag_id",
|
||||
"=",
|
||||
798
|
||||
]
|
||||
]
|
||||
],
|
||||
"kwargs": {
|
||||
"opts": {
|
||||
"countOnly": true
|
||||
}
|
||||
},
|
||||
"method": "repo.queryQueue",
|
||||
"result": 0
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"kwargs": {
|
||||
"queryOpts": {
|
||||
"countOnly": true
|
||||
},
|
||||
"repoID": 88
|
||||
},
|
||||
"method": "listBuildroots",
|
||||
"result": 0
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
[
|
||||
[
|
||||
"repo_id",
|
||||
"=",
|
||||
88
|
||||
]
|
||||
],
|
||||
[
|
||||
"id"
|
||||
]
|
||||
],
|
||||
"kwargs": {},
|
||||
"method": "repo.queryQueue",
|
||||
"result": []
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
2
|
||||
],
|
||||
"kwargs": {},
|
||||
"method": "repo.get",
|
||||
"result": {
|
||||
"begin_event": 497768,
|
||||
"begin_ts": 1732049290.238136,
|
||||
"create_event": 497784,
|
||||
"create_ts": 1732569672.685269,
|
||||
"creation_time": "2024-11-25 21:21:12.682068+00:00",
|
||||
"creation_ts": 1732569672.682068,
|
||||
"custom_opts": {},
|
||||
"dist": false,
|
||||
"end_event": null,
|
||||
"end_ts": null,
|
||||
"id": 2599,
|
||||
"opts": {
|
||||
"debuginfo": false,
|
||||
"maven": false,
|
||||
"separate_src": false,
|
||||
"src": false
|
||||
},
|
||||
"state": 1,
|
||||
"state_time": "2024-11-25 21:21:19.711390+00:00",
|
||||
"state_ts": 1732569679.71139,
|
||||
"tag_id": 2,
|
||||
"tag_name": "f24-build",
|
||||
"task_id": 14431,
|
||||
"task_state": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
[
|
||||
[
|
||||
"tag_id",
|
||||
"=",
|
||||
2
|
||||
]
|
||||
]
|
||||
],
|
||||
"kwargs": {
|
||||
"opts": {
|
||||
"countOnly": true
|
||||
}
|
||||
},
|
||||
"method": "repo.queryQueue",
|
||||
"result": 0
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
[
|
||||
[
|
||||
"task_id",
|
||||
"=",
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
"id"
|
||||
]
|
||||
],
|
||||
"kwargs": {},
|
||||
"method": "repo.queryQueue",
|
||||
"result": []
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ class TestPages(unittest.TestCase):
|
|||
def setUpClass(cls):
|
||||
# recording session used across tests in recording mode
|
||||
cls.cfile = os.path.dirname(__file__) + f'/data/pages_calls.json'
|
||||
cls.cfile2 = os.path.dirname(__file__) + f'/data/pages_calls_updates.json'
|
||||
cls.recording = False
|
||||
cls.updating = False
|
||||
cls.rsession = RecordingClientSession('http://localhost/kojihub', {})
|
||||
|
||||
@classmethod
|
||||
|
|
@ -35,6 +37,8 @@ class TestPages(unittest.TestCase):
|
|||
if cls.recording:
|
||||
# save recorded calls
|
||||
cls.rsession.dump(cls.cfile)
|
||||
elif cls.updating:
|
||||
cls.rsession.dump(cls.cfile2)
|
||||
|
||||
def setUp(self):
|
||||
self.environ = {
|
||||
|
|
@ -77,6 +81,8 @@ class TestPages(unittest.TestCase):
|
|||
else:
|
||||
self.server = FakeClientSession('SERVER', {})
|
||||
self.server.load(self.cfile)
|
||||
if self.updating:
|
||||
self.server._missing_rsession = self.rsession
|
||||
return self.server
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue