Skip to content

Commit 12ec6d1

Browse files
committed
service installed patch fixes in api tests
Signed-off-by: ashish-jabble <ashish@dianomic.com>
1 parent 6c0bd3f commit 12ec6d1

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

tests/unit/python/fledge/services/core/api/test_service.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ async def test_bad_external_service(self, client, payload):
439439
json_response = json.loads(result)
440440
assert {"message": msg} == json_response
441441

442-
@pytest.mark.parametrize("svc_name, svc_type, svc_process, svc_script, svc_priority, enabled", [
443-
("Mgt Server", "Management", "management", "[\"services/management\"]", 300, None),
444-
("NF Server", "Notification", "notification_c", "[\"services/notification_c\"]", 30, "true"),
445-
("DS Server", "Dispatcher", "dispatcher_c", "[\"services/dispatcher_c\"]", 20, "false"),
446-
("BS Server", "BucketStorage", "bucket_storage_c", "[\"services/bucket_storage_c\"]", 10, None)
442+
@pytest.mark.parametrize("svc_name, svc_type, svc_process, svc_script, svc_priority, enabled, svc_installed", [
443+
("Mgt Server", "Management", "management", "[\"services/management\"]", 300, None, ["management"]),
444+
("NF Server", "Notification", "notification_c", "[\"services/notification_c\"]", 30, "true", ["notification"]),
445+
("DS Server", "Dispatcher", "dispatcher_c", "[\"services/dispatcher_c\"]", 20, "false", ["dispatcher"]),
446+
("BS Server", "BucketStorage", "bucket_storage_c", "[\"services/bucket_storage_c\"]", 10, None, ["bucket"])
447447
])
448-
async def test_add_external_service(self, client, svc_name, svc_type, svc_process, svc_script, svc_priority, enabled):
448+
async def test_add_external_service(self, client, svc_name, svc_type, svc_process, svc_script, svc_priority, enabled, svc_installed):
449449
async def async_mock_get_schedule():
450450
schedule = StartUpSchedule()
451451
schedule.schedule_id = sch_id
@@ -464,16 +464,18 @@ async def async_mock_get_schedule():
464464
"process_script": svc_script,
465465
"startup_priority": svc_priority
466466
}
467+
svc_installed.extend(["storage", "south", "north"])
467468
server.Server.scheduler = Scheduler(None, None)
468469
storage_client_mock = MagicMock(StorageClientAsync)
469470
c_mgr = ConfigurationManager(storage_client_mock)
471+
_rv0 = await self.async_mock(svc_installed)
470472
_rv1 = await self.async_mock(svc_info)
471473
_rv2 = await self.async_mock(None)
472474
_rv3 = await self.async_mock(0)
473475
_rv4 = await self.async_mock({'count': 1})
474476
_rv5 = await self.async_mock({'count': 1, 'rows': [{'process_name': "blah"}]})
475477
_rv6 = await async_mock_get_schedule()
476-
with patch('os.path.exists', return_value=True):
478+
with patch.object(service, 'get_service_installed', return_value=_rv0) as patch_svc_installed:
477479
with patch.object(service, '_fetch_service_info', return_value=_rv1):
478480
with patch.object(connect, 'get_storage_async', return_value=storage_client_mock):
479481
with patch.object(c_mgr, 'get_category_all_items', return_value=_rv2) as patch_get_cat_info:
@@ -484,6 +486,7 @@ async def async_mock_get_schedule():
484486
with patch.object(server.Server.scheduler, 'get_schedule_by_name', return_value=_rv6) as patch_schedule_by_name:
485487
resp = await client.post('/fledge/service', data=payload)
486488
server.Server.scheduler = None
489+
print(resp.reason)
487490
assert 200 == resp.status
488491
result = await resp.text()
489492
json_response = json.loads(result)
@@ -493,15 +496,15 @@ async def async_mock_get_schedule():
493496
patch_schedules.assert_called_once_with(storage_client_mock, data['name'])
494497
patch_scheduled_processes.assert_called_once_with(storage_client_mock, svc_info['process'], svc_info['process_script'])
495498
patch_get_cat_info.assert_called_once_with(category_name=data['name'])
499+
assert 2 == patch_svc_installed.call_count
496500

497-
498-
@pytest.mark.parametrize("svc_name, svc_type, svc_process, svc_script, svc_priority", [
499-
("Mgt Server", "Management", "management", "[\"services/management\"]", 300),
500-
("NF Server", "Notification", "notification_c", "[\"services/notification_c\"]", 30),
501-
("DS Server", "Dispatcher", "dispatcher_c", "[\"services/dispatcher_c\"]", 20),
502-
("BS Server", "BucketStorage", "bucket_storage_c", "[\"services/bucket_storage_c\"]", 10)
501+
@pytest.mark.parametrize("svc_name, svc_type, svc_process, svc_script, svc_priority, svc_installed", [
502+
("Mgt Server", "Management", "management", "[\"services/management\"]", 300, ["management"]),
503+
("NF Server", "Notification", "notification_c", "[\"services/notification_c\"]", 30, ["notification"]),
504+
("DS Server", "Dispatcher", "dispatcher_c", "[\"services/dispatcher_c\"]", 20, ["dispatcher"]),
505+
("BS Server", "BucketStorage", "bucket_storage_c", "[\"services/bucket_storage_c\"]", 10, ["bucket"])
503506
])
504-
async def test_dupe_external_service_schedule(self, client, svc_name, svc_type, svc_process, svc_script, svc_priority):
507+
async def test_dupe_external_service_schedule(self, client, svc_name, svc_type, svc_process, svc_script, svc_priority, svc_installed):
505508
payload = json.dumps({"name": svc_name, "type": svc_type})
506509
data = json.loads(payload)
507510
svc_info = {
@@ -515,12 +518,14 @@ async def test_dupe_external_service_schedule(self, client, svc_name, svc_type,
515518
server.Server.scheduler = Scheduler(None, None)
516519
storage_client_mock = MagicMock(StorageClientAsync)
517520
c_mgr = ConfigurationManager(storage_client_mock)
521+
svc_installed.extend(["storage", "south", "north"])
522+
_rv0 = await self.async_mock(svc_installed)
518523
_rv1 = await self.async_mock(svc_info)
519524
_rv2 = await self.async_mock(None)
520525
_rv3 = await self.async_mock(0)
521526
_rv4 = await self.async_mock({'count': 1})
522527
_rv5 = await self.async_mock({'count': 1, 'rows': [{'process_name': svc_info['process']}]})
523-
with patch('os.path.exists', return_value=True):
528+
with patch.object(service, 'get_service_installed', return_value=_rv0) as patch_svc_installed:
524529
with patch.object(service, '_fetch_service_info', return_value=_rv1):
525530
with patch.object(connect, 'get_storage_async', return_value=storage_client_mock):
526531
with patch.object(c_mgr, 'get_category_all_items', return_value=_rv2) as patch_get_cat_info:
@@ -537,6 +542,7 @@ async def test_dupe_external_service_schedule(self, client, svc_name, svc_type,
537542
patch_schedules.assert_called_once_with(storage_client_mock, data['name'])
538543
patch_scheduled_processes.assert_called_once_with(storage_client_mock, svc_info['process'], svc_info['process_script'])
539544
patch_get_cat_info.assert_called_once_with(category_name=data['name'])
545+
assert 2 == patch_svc_installed.call_count
540546

541547
async def test_add_service_with_config(self, client):
542548
payload = '{"name": "Sine", "type": "south", "plugin": "sinusoid", "enabled": "false",' \

0 commit comments

Comments
 (0)