From 762a3b81de900090479bf081f2d1cc0e1065642d Mon Sep 17 00:00:00 2001
From: jrybicki-jsc <j.rybicki@fz-juelich.de>
Date: Mon, 7 Jun 2021 17:37:29 +0200
Subject: [PATCH] tuples insead of dicts

---
 apiserver/storage/JsonFileStorageAdapter.py |  3 ++-
 tests/apiserver_tests/test_apiwithauth.py   | 24 ++++++++++++++++++++-
 tests/storage_tests/test_jsonbackend.py     |  6 +++---
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/apiserver/storage/JsonFileStorageAdapter.py b/apiserver/storage/JsonFileStorageAdapter.py
index 5a8f1ae..961c08e 100644
--- a/apiserver/storage/JsonFileStorageAdapter.py
+++ b/apiserver/storage/JsonFileStorageAdapter.py
@@ -65,7 +65,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter):
             if not os.path.isfile(p):
                 continue
             data = self.__load_object(p)
-            retList.append({data.actualData.name: f})
+            retList.append((data.actualData.name, f))
         return retList
 
     def add_new(self, n_type: LocationDataType, data: LocationData, user_name: str):
@@ -94,6 +94,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter):
 
     def delete(self, n_type: LocationDataType, oid: str, usr: str):
         fullpath = self.__get_object_path(value=n_type.value, oid=oid)
+        print(f"Removing {fullpath}")
         os.remove(fullpath)
 
     def get_owner(self, type: LocationDataType, oid: str):
diff --git a/tests/apiserver_tests/test_apiwithauth.py b/tests/apiserver_tests/test_apiwithauth.py
index 7e64500..6afd0c6 100644
--- a/tests/apiserver_tests/test_apiwithauth.py
+++ b/tests/apiserver_tests/test_apiwithauth.py
@@ -18,6 +18,7 @@ class UserTests(TestCase):
         
     def tearDown(self):
         apiserver.app.dependency_overrides={}
+
     
     def test_me(self):
        
@@ -44,4 +45,25 @@ class UserTests(TestCase):
         self.assertIsNotNone(oid)
         self.assertEqual(dty, my_data)
 
-        self.client.delete(f'/dataset/{oid}')
+        self.client.delete(f"/dataset/{oid}")
+
+
+    def test_create_and_get(self):
+        dss = [{'name': f"ds_{i}", 'url': f"http://www.o.com/{i}"} for i in range(5)]
+        for d in dss:
+            rsp = self.client.post('/dataset', json=d)
+            self.assertEqual(rsp.status_code, 200)
+            (oid, dty) = rsp.json()
+            d['id'] = oid
+
+        
+
+        for d in dss:
+            i = d['id']
+            rsp = self.client.get(f"/dataset/{i}")
+            self.assertEqual(rsp.status_code, 200)
+            dty = rsp.json()
+            self.assertEqual(d['name'], dty['name'])
+            self.assertEqual(d['url'], dty['url'])
+
+            self.client.delete(f"/dataset/{i}")
diff --git a/tests/storage_tests/test_jsonbackend.py b/tests/storage_tests/test_jsonbackend.py
index afb657d..5dada28 100644
--- a/tests/storage_tests/test_jsonbackend.py
+++ b/tests/storage_tests/test_jsonbackend.py
@@ -48,9 +48,9 @@ class SomeTests(unittest.TestCase):
 
         lst = self.store.get_list(n_type=LocationDataType.DATASET)
         self.assertEqual(len(lst), 1,  'One should be there')
-        m_o = lst[0]
-        self.assertEqual(list(m_o.keys())[0], l_data.name)
-        self.assertEqual(list(m_o.values())[0], oid)
+        (n_name, n_o) = lst[0]
+        self.assertEqual(n_name, l_data.name)
+        self.assertEqual(n_o, oid)
 
     def test_get_details(self):
         # get_details(self, n_type: LocationDataType, oid: str):
-- 
GitLab