[LNT] r307994 - api: Implement machine deletion
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 19:05:04 PDT 2017
Author: matze
Date: Thu Jul 13 19:05:04 2017
New Revision: 307994
URL: http://llvm.org/viewvc/llvm-project?rev=307994&view=rev
Log:
api: Implement machine deletion
Modified:
lnt/trunk/lnt/server/ui/api.py
lnt/trunk/tests/server/ui/test_api_deletes.py
Modified: lnt/trunk/lnt/server/ui/api.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/api.py?rev=307994&r1=307993&r2=307994&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/api.py (original)
+++ lnt/trunk/lnt/server/ui/api.py Thu Jul 13 19:05:04 2017
@@ -142,6 +142,18 @@ class Machine(Resource):
return jsonify(machine)
+ @staticmethod
+ @requires_auth_token
+ def delete(machine_id):
+ ts = request.get_testsuite()
+ machine = ts.query(ts.Machine).filter(ts.Machine.id == machine_id) \
+ .first()
+ if machine is None:
+ return abort(404, msg="Did not find machine " + str(machine_id))
+ ts.session.delete(machine)
+ ts.commit()
+ return
+
class Runs(Resource):
method_decorators = [in_db]
Modified: lnt/trunk/tests/server/ui/test_api_deletes.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_api_deletes.py?rev=307994&r1=307993&r2=307994&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/test_api_deletes.py (original)
+++ lnt/trunk/tests/server/ui/test_api_deletes.py Thu Jul 13 19:05:04 2017
@@ -28,7 +28,7 @@ class JSONAPIDeleteTester(unittest.TestC
app.testing = True
self.client = app.test_client()
- def test_run_api(self):
+ def test_runs_api(self):
"""Check /runs/n can be deleted."""
client = self.client
@@ -42,10 +42,12 @@ class JSONAPIDeleteTester(unittest.TestC
resp = client.delete('api/db_default/v4/nts/runs/1')
self.assertEqual(resp.status_code, 401)
- resp = client.delete('api/db_default/v4/nts/runs/1', headers={'AuthToken': 'wrong token'})
+ resp = client.delete('api/db_default/v4/nts/runs/1',
+ headers={'AuthToken': 'wrong token'})
self.assertEqual(resp.status_code, 401)
- resp = client.delete('api/db_default/v4/nts/runs/1', headers={'AuthToken': 'test_token'})
+ resp = client.delete('api/db_default/v4/nts/runs/1',
+ headers={'AuthToken': 'test_token'})
self.assertEqual(resp.status_code, 200)
resp = client.get('api/db_default/v4/nts/runs/1')
@@ -53,6 +55,42 @@ class JSONAPIDeleteTester(unittest.TestC
for sid in sample_ids:
resp = client.get('api/db_default/v4/nts/samples/{}'.format(sid))
+ self.assertEqual(resp.status_code, 404)
+
+ def test_machines_api(self):
+ """Check /machines/n can be deleted."""
+ client = self.client
+
+ j = check_json(client, 'api/db_default/v4/nts/machines/2')
+ run_ids = [s['id'] for s in j['runs']]
+ self.assertNotEqual(len(run_ids), 0)
+ sample_ids = []
+ for run_id in run_ids:
+ resp = check_json(client,
+ 'api/db_default/v4/nts/runs/{}'.format(run_id))
+ sample_ids.append([s['id'] for s in resp['samples']])
+ self.assertNotEqual(len(sample_ids), 0)
+
+ resp = client.delete('api/db_default/v4/nts/machines/2')
+ self.assertEqual(resp.status_code, 401)
+
+ resp = client.delete('api/db_default/v4/nts/machines/2',
+ headers={'AuthToken': 'wrong token'})
+ self.assertEqual(resp.status_code, 401)
+
+ resp = client.delete('api/db_default/v4/nts/machines/2',
+ headers={'AuthToken': 'test_token'})
+ self.assertEqual(resp.status_code, 200)
+
+ resp = client.get('api/db_default/v4/nts/machines/2')
+ self.assertEqual(resp.status_code, 404)
+
+ for run_id in run_ids:
+ resp = client.get('api/db_default/v4/nts/runs/{}'.format(run_id))
+ self.assertEqual(resp.status_code, 404)
+
+ for sid in sample_ids:
+ resp = client.get('api/db_default/v4/nts/samples/{}'.format(sid))
self.assertEqual(resp.status_code, 404)
More information about the llvm-commits
mailing list