From 985c8a9737e36d677875789e885994f4254e59ac Mon Sep 17 00:00:00 2001
From: Jochen Klar <mail@jochenklar.de>
Date: Fri, 31 Mar 2023 12:36:18 +0200
Subject: [PATCH] Fix tests

---
 fixtures/search.json                        | 34 ++++++++++-----------
 isimip_data/annotations/tests/test_utils.py |  4 ++-
 testing/fixtures/search.json                |  8 ++---
 testing/sql/test_isimip_metadata.sql        | 12 ++++----
 4 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/fixtures/search.json b/fixtures/search.json
index f7276e3a..82334c2e 100644
--- a/fixtures/search.json
+++ b/fixtures/search.json
@@ -4,7 +4,7 @@
     "pk": 1,
     "fields": {
       "title": "ISIMIP simulation round",
-      "attribute": "simulation_round",
+      "identifier": "simulation_round",
       "order": 1
     }
   },
@@ -13,7 +13,7 @@
     "pk": 2,
     "fields": {
       "title": "Data product",
-      "attribute": "product",
+      "identifier": "product",
       "order": 2
     }
   },
@@ -22,7 +22,7 @@
     "pk": 3,
     "fields": {
       "title": "Input category",
-      "attribute": "category",
+      "identifier": "category",
       "order": 14
     }
   },
@@ -31,7 +31,7 @@
     "pk": 5,
     "fields": {
       "title": "Climate scenario",
-      "attribute": "climate_scenario",
+      "identifier": "climate_scenario",
       "order": 8
     }
   },
@@ -40,7 +40,7 @@
     "pk": 8,
     "fields": {
       "title": "Climate forcing",
-      "attribute": "climate_forcing",
+      "identifier": "climate_forcing",
       "order": 7
     }
   },
@@ -49,7 +49,7 @@
     "pk": 18,
     "fields": {
       "title": "Climate variable",
-      "attribute": "climate_variable",
+      "identifier": "climate_variable",
       "order": 17
     }
   },
@@ -58,7 +58,7 @@
     "pk": 19,
     "fields": {
       "title": "Input subcategory",
-      "attribute": "subcategory",
+      "identifier": "subcategory",
       "order": 15
     }
   },
@@ -67,7 +67,7 @@
     "pk": 20,
     "fields": {
       "title": "Socio-economic scenario",
-      "attribute": "soc_scenario",
+      "identifier": "soc_scenario",
       "order": 9
     }
   },
@@ -76,7 +76,7 @@
     "pk": 21,
     "fields": {
       "title": "Socio-economic dataset",
-      "attribute": "soc_dataset",
+      "identifier": "soc_dataset",
       "order": 16
     }
   },
@@ -85,7 +85,7 @@
     "pk": 22,
     "fields": {
       "title": "Geographic dataset",
-      "attribute": "geo_dataset",
+      "identifier": "geo_dataset",
       "order": 18
     }
   },
@@ -94,7 +94,7 @@
     "pk": 23,
     "fields": {
       "title": "Output variable",
-      "attribute": "variable",
+      "identifier": "variable",
       "order": 13
     }
   },
@@ -103,7 +103,7 @@
     "pk": 24,
     "fields": {
       "title": "Temporal resolution",
-      "attribute": "time_step",
+      "identifier": "time_step",
       "order": 11
     }
   },
@@ -112,7 +112,7 @@
     "pk": 25,
     "fields": {
       "title": "Sector",
-      "attribute": "sector",
+      "identifier": "sector",
       "order": 4
     }
   },
@@ -121,7 +121,7 @@
     "pk": 26,
     "fields": {
       "title": "Impact model",
-      "attribute": "model",
+      "identifier": "model",
       "order": 5
     }
   },
@@ -130,7 +130,7 @@
     "pk": 27,
     "fields": {
       "title": "Simulation period",
-      "attribute": "period",
+      "identifier": "period",
       "order": 3
     }
   },
@@ -139,7 +139,7 @@
     "pk": 28,
     "fields": {
       "title": "Sensitivity scenario",
-      "attribute": "sens_scenario",
+      "identifier": "sens_scenario",
       "order": 10
     }
   },
@@ -148,7 +148,7 @@
     "pk": 29,
     "fields": {
       "title": "Spacial resolution",
-      "attribute": "resolution",
+      "identifier": "resolution",
       "order": 12
     }
   }
diff --git a/isimip_data/annotations/tests/test_utils.py b/isimip_data/annotations/tests/test_utils.py
index 306528cd..6871a9b8 100644
--- a/isimip_data/annotations/tests/test_utils.py
+++ b/isimip_data/annotations/tests/test_utils.py
@@ -25,5 +25,7 @@ def test_query_datasets_before(db):
 
 
 def test_format_affected_datasets(db):
-    affected_datasets = format_affected_datasets(Dataset.objects.filter(specifiers__contains={'model': 'model'}))
+    affected_datasets = format_affected_datasets(
+        Dataset.objects.using('metadata').filter(specifiers__contains={'model': 'model'})
+    )
     assert len(re.findall(r'<br>', affected_datasets)) == 1
diff --git a/testing/fixtures/search.json b/testing/fixtures/search.json
index f3375482..b5b6da15 100644
--- a/testing/fixtures/search.json
+++ b/testing/fixtures/search.json
@@ -4,7 +4,7 @@
     "pk": 1,
     "fields": {
       "title": "Simulation round",
-      "attribute": "simulation_round",
+      "identifier": "simulation_round",
       "order": 1
     }
   },
@@ -13,7 +13,7 @@
     "pk": 2,
     "fields": {
       "title": "Product",
-      "attribute": "product",
+      "identifier": "product",
       "order": 2
     }
   },
@@ -22,7 +22,7 @@
     "pk": 3,
     "fields": {
       "title": "Sector",
-      "attribute": "sector",
+      "identifier": "sector",
       "order": 3
     }
   },
@@ -31,7 +31,7 @@
     "pk": 4,
     "fields": {
       "title": "Impact model",
-      "attribute": "model",
+      "identifier": "model",
       "order": 4
     }
   }
diff --git a/testing/sql/test_isimip_metadata.sql b/testing/sql/test_isimip_metadata.sql
index b0da2da9..3667fe70 100644
--- a/testing/sql/test_isimip_metadata.sql
+++ b/testing/sql/test_isimip_metadata.sql
@@ -61,10 +61,10 @@ CREATE TABLE public.datasets (
 ALTER TABLE public.datasets OWNER TO isimip_metadata;
 
 --
--- Name: attributes; Type: MATERIALIZED VIEW; Schema: public; Owner: isimip_metadata
+-- Name: identifiers; Type: MATERIALIZED VIEW; Schema: public; Owner: isimip_metadata
 --
 
-CREATE MATERIALIZED VIEW public.attributes AS
+CREATE MATERIALIZED VIEW public.identifiers AS
  SELECT specifiers.key AS identifier,
     array_agg(DISTINCT specifiers.value) AS specifiers
    FROM public.datasets,
@@ -74,7 +74,7 @@ CREATE MATERIALIZED VIEW public.attributes AS
   WITH NO DATA;
 
 
-ALTER TABLE public.attributes OWNER TO isimip_metadata;
+ALTER TABLE public.identifiers OWNER TO isimip_metadata;
 
 --
 -- Name: files; Type: TABLE; Schema: public; Owner: isimip_metadata
@@ -261,7 +261,7 @@ ALTER TABLE ONLY public.trees
 -- Name: attributes_identifier_idx; Type: INDEX; Schema: public; Owner: isimip_metadata
 --
 
-CREATE INDEX attributes_identifier_idx ON public.attributes USING btree (identifier);
+CREATE INDEX identifiers_identifier_idx ON public.identifiers USING btree (identifier);
 
 
 --
@@ -389,10 +389,10 @@ ALTER TABLE ONLY public.resources_datasets
 
 
 --
--- Name: attributes; Type: MATERIALIZED VIEW DATA; Schema: public; Owner: isimip_metadata
+-- Name: identifiers; Type: MATERIALIZED VIEW DATA; Schema: public; Owner: isimip_metadata
 --
 
-REFRESH MATERIALIZED VIEW public.attributes;
+REFRESH MATERIALIZED VIEW public.identifiers;
 
 
 --