Repository: virtool/virtool
Issue: Update index GET method

- [x] only allow retrieval by `index_id`, **not** `version`
- [ ] update API documentation

Changed files:
virtool/api/indexes.py, tests/db/test_indexes.py, tests/api/test_indexes.py

diff --git a/tests/api/test_indexes.py b/tests/api/test_indexes.py
index 8dc6e986d..c18cb0422 100644
--- a/tests/api/test_indexes.py
+++ b/tests/api/test_indexes.py
@@ -281,98 +281,98 @@ class TestCreate:
     '''
 
 
-class TestFindHistory:
-
-    @pytest.mark.parametrize("identifier", ["foobar", 0])
-    async def test(self, identifier, spawn_client):
-        client = await spawn_client(authorize=True)
+@pytest.mark.parametrize("exists", [True, False])
+async def test(exists, spawn_client, resp_is):
+    client = await spawn_client(authorize=True)
 
+    if exists:
         await client.db.indexes.insert_one({
             "_id": "foobar",
             "version": 0
         })
 
-        await client.db.history.insert_many([
-            {
-                "_id": "zxbbvngc.0",
-                "otu": {
-                    "version": 0,
-                    "name": "Test",
-                    "id": "zxbbvngc"
-                },
-                "user": {
-                    "id": "igboyes"
-                },
-                "index": {
-                    "version": 0,
-                    "id": "foobar"
-                }
+    await client.db.history.insert_many([
+        {
+            "_id": "zxbbvngc.0",
+            "otu": {
+                "version": 0,
+                "name": "Test",
+                "id": "zxbbvngc"
             },
-            {
-                "_id": "zxbbvngc.1",
-                "otu": {
-                    "version": 1,
-                    "name": "Test",
-                    "id": "zxbbvngc"
-                },
-                "user": {
-                    "id": "igboyes"
-                },
-                "method_name": "add_isolate",
-                "index": {
-                    "version": 0,
-                    "id": "foobar"
-                }
+            "user": {
+                "id": "igboyes"
             },
-            {
-                "_id": "zxbbvngc.2",
-                "otu": {
-                    "version": 2,
-                    "name": "Test",
-                    "id": "zxbbvngc"
-                },
-                "user": {
-                    "id": "igboyes"
-                },
-                "method_name": "add_isolate",
-                "index": {
-                    "version": 0,
-                    "id": "foobar"
-                }
+            "index": {
+                "version": 0,
+                "id": "foobar"
+            }
+        },
+        {
+            "_id": "zxbbvngc.1",
+            "otu": {
+                "version": 1,
+                "name": "Test",
+                "id": "zxbbvngc"
             },
-            {
-                "_id": "kjs8sa99.3",
-                "otu": {
-                    "version": 3,
-                    "name": "Foo",
-                    "id": "kjs8sa99"
-                },
-                "user": {
-                    "id": "fred"
-                },
-                "method_name": "add_sequence",
-                "index": {
-                    "version": 0,
-                    "id": "foobar"
-                }
+            "user": {
+                "id": "igboyes"
             },
-            {
-                "_id": "test_1",
-                "index": {
-                    "id": "baz"
-                }
-
+            "method_name": "add_isolate",
+            "index": {
+                "version": 0,
+                "id": "foobar"
+            }
+        },
+        {
+            "_id": "zxbbvngc.2",
+            "otu": {
+                "version": 2,
+                "name": "Test",
+                "id": "zxbbvngc"
             },
-            {
-                "_id": "test_2",
-                "index": {
-                    "id": "baz"
-                }
+            "user": {
+                "id": "igboyes"
+            },
+            "method_name": "add_isolate",
+            "index": {
+                "version": 0,
+                "id": "foobar"
+            }
+        },
+        {
+            "_id": "kjs8sa99.3",
+            "otu": {
+                "version": 3,
+                "name": "Foo",
+                "id": "kjs8sa99"
+            },
+            "user": {
+                "id": "fred"
+            },
+            "method_name": "add_sequence",
+            "index": {
+                "version": 0,
+                "id": "foobar"
+            }
+        },
+        {
+            "_id": "test_1",
+            "index": {
+                "id": "baz"
             }
-        ])
 
-        resp = await client.get("/api/indexes/{}/history".format(identifier))
+        },
+        {
+            "_id": "test_2",
+            "index": {
+                "id": "baz"
+            }
+        }
+    ])
 
+    resp = await client.get("/api/indexes/foobar/history")
+
+    if exists:
         assert resp.status == 200
 
         expected = {
@@ -448,9 +448,5 @@ class TestFindHistory:
 
         assert await resp.json() == expected
 
-    async def test_not_found(self, spawn_client, resp_is):
-        client = await spawn_client(authorize=True)
-
-        resp = await client.get("/api/indexes/foobar/history")
-
+    else:
         assert await resp_is.not_found(resp)
diff --git a/tests/db/test_indexes.py b/tests/db/test_indexes.py
index 986a526d7..a3aa75426 100644
--- a/tests/db/test_indexes.py
+++ b/tests/db/test_indexes.py
@@ -26,22 +26,6 @@ async def test_get_current_id_and_version(exists, has_ref, test_indexes, test_mo
         assert index_version == -1
 
 
-@pytest.mark.parametrize("value", ["jgwlhulj", 2])
-@pytest.mark.parametrize("projection", (
-    None,
-    ["_id", "version"]
-))
-async def test_get_index(projection, value, test_indexes, test_motor):
-    await test_motor.indexes.insert_many(test_indexes)
-
-    expected = test_indexes[2]
-
-    if projection:
-        expected = {k: expected[k] for k in projection}
-
-    assert await virtool.db.indexes.get_index(test_motor, value, projection) == expected
-
-
 @pytest.mark.parametrize("empty", [False, True])
 @pytest.mark.parametrize("has_ref", [True, False])
 async def test_get_next_version(empty, has_ref, test_indexes, test_motor):
diff --git a/virtool/api/indexes.py b/virtool/api/indexes.py
index 1727b25b8..9065010d9 100644
--- a/virtool/api/indexes.py
+++ b/virtool/api/indexes.py
@@ -24,7 +24,7 @@ async def find(req):
     return json_response(data)
 
 
-@routes.get("/api/indexes/{index_id_or_version}")
+@routes.get("/api/indexes/{index_id}")
 async def get(req):
     """
     Get the complete document for a given index.
@@ -32,16 +32,18 @@ async def get(req):
     """
     db = req.app["db"]
 
-    document = await virtool.db.indexes.get_index(db, req.match_info["index_id_or_version"])
+    index_id = req.match_info["index_id"]
+
+    document = await db.indexes.find_one(index_id)
 
     if not document:
         return not_found()
 
     document = virtool.utils.base_processor(document)
 
-    document["contributors"] = await virtool.db.indexes.get_contributors(db, document["id"])
+    document["contributors"] = await virtool.db.indexes.get_contributors(db, index_id)
 
-    document["otus"] = await virtool.db.indexes.get_otus(db, document["id"])
+    document["otus"] = await virtool.db.indexes.get_otus(db, index_id)
 
     document["change_count"] = sum(v["change_count"] for v in document["otus"])
 
@@ -126,7 +128,7 @@ async def create(req):
     return json_response(virtool.utils.base_processor(document), status=201, headers=headers)
 
 
-@routes.get("/api/indexes/{index_id_or_version}/history")
+@routes.get("/api/indexes/{index_id}/history")
 async def find_history(req):
     """
     Find history changes for a specific index.
@@ -134,15 +136,15 @@ async def find_history(req):
     """
     db = req.app["db"]
 
-    document = await virtool.db.indexes.get_index(db, req.match_info["index_id_or_version"], projection=["_id"])
+    index_id = req.match_info["index_id"]
 
-    if not document:
+    if not await db.indexes.count({"_id": index_id}):
         return not_found()
 
     term = req.query.get("term", None)
 
     db_query = {
-        "index.id": document["_id"]
+        "index.id": index_id
     }
 
     if term: