Add scoped start stop and delete actions for application containers

This commit is contained in:
Mikei386
2026-10-01 10:11:58 +02:00
parent 88c6957dac
commit f66e7fbf71
7 changed files with 82 additions and 4 deletions
+17
View File
@@ -41,6 +41,23 @@ class Tests(unittest.TestCase):
self.assertEqual(runtime.call_count,1)
self.assertTrue(all('execution' in row and 'used_by_profiles' in row for row in result['entries']))
def test_container_actions_require_admin_and_delete_confirmation(self):
ident='a'*64
with patch.object(self.server.docker,'container_action',return_value={'changed':True}) as action:
for operation in ('start','stop','delete'):
data={'id':ident,**({'confirm':True} if operation=='delete' else {})}
req=urllib.request.Request(self.url+'/api/v1/docker/'+operation,data=json.dumps(data).encode(),headers={'Cookie':self.cookie,'X-Athena-Deck':'1','Content-Type':'application/json'})
with urllib.request.urlopen(req) as response:self.assertTrue(json.load(response)['changed'])
action.assert_called_with(operation,ident)
count=action.call_count
req=urllib.request.Request(self.url+'/api/v1/docker/delete',data=json.dumps({'id':ident}).encode(),headers={'Cookie':self.cookie,'X-Athena-Deck':'1','Content-Type':'application/json'})
with self.assertRaises(urllib.error.HTTPError) as error:urllib.request.urlopen(req)
self.assertEqual(error.exception.code,400);error.exception.close()
req=urllib.request.Request(self.url+'/api/v1/docker/start',data=json.dumps({'id':ident}).encode(),headers={'X-Athena-Deck':'1','Content-Type':'application/json'})
with self.assertRaises(urllib.error.HTTPError) as error:urllib.request.urlopen(req)
self.assertEqual(error.exception.code,401);error.exception.close()
self.assertEqual(action.call_count,count)
def test_demo_removed_from_status(self):
state=self.request('status')
self.assertNotIn('demo',state)