Skip to content

Commit

Permalink
fix merge conflict with latest from dev/7.6.x, re #10804
Browse files Browse the repository at this point in the history
  • Loading branch information
whatisgalen committed Aug 8, 2024
2 parents 4bb7573 + af4ab84 commit 0c36502
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
6 changes: 0 additions & 6 deletions arches/app/models/migrations/0005_4_0_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ def forwards_func(apps, schema_editor):
# We get the model from the versioned app registry;
# if we directly import it, it'll be the wrong version

# index base Arches concept
arches_concept = Concept().get(
id="00000000-0000-0000-0000-000000000001", include=["label"]
)
arches_concept.index()

DValueType = apps.get_model("models", "DValueType")
DValueType.objects.create(
valuetype="identifier",
Expand Down
8 changes: 1 addition & 7 deletions arches/app/models/migrations/0010_4_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@


def forwards_func(apps, schema_editor):
# We get the model from the versioned app registry;
# if we directly import it, it'll be the wrong version

arches_concept = Concept().get(
id="00000000-0000-0000-0000-000000000007", include=["label"]
)
arches_concept.index()
pass


def reverse_func(apps, schema_editor):
Expand Down
79 changes: 68 additions & 11 deletions tests/search/search_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import json
import time
from django.test.utils import captured_stdout
import uuid

from tests.base_test import ArchesTestCase
from tests.utils.search_test_utils import sync_es
from arches.app.search.search_engine_factory import SearchEngineFactory
from arches.app.models import models
from arches.app.models.resource import Resource
from arches.app.models.tile import Tile
from arches.app.search.elasticsearch_dsl_builder import (
Bool,
Match,
Query,
Nested,
Terms,
GeoShape,
Range,
)
from arches.app.search.search_engine_factory import SearchEngineFactory
from arches.app.utils.i18n import LanguageSynchronizer
from arches.app.views.search import search_terms
from django.http import HttpRequest
from django.contrib.auth.models import User
from django.test.utils import captured_stdout
from tests.base_test import ArchesTestCase
from tests.utils.search_test_utils import sync_es

# these tests can be run from the command line via
# python manage.py test tests.search.search_tests --settings="tests.test_settings"
Expand All @@ -39,12 +43,27 @@
class SearchTests(ArchesTestCase):
@classmethod
def tearDownClass(cls):
models.GraphModel.objects.filter(
pk="d291a445-fa5f-11e6-afa8-14109fd34195"
).delete()
User.objects.filter(username="Tester").delete()
Resource.objects.filter(pk="745f5e4a-d645-4c50-bafc-c677ea95f060").delete()
se = SearchEngineFactory().create()
with captured_stdout():
se.delete_index(index="test")
se.delete_index(index="bulk")
super().tearDownClass()

@classmethod
def setUpClass(cls):
super().setUpClass()
LanguageSynchronizer.synchronize_settings_with_db()
User.objects.create_user(
username="Tester", email="[email protected]", password="test12345!"
)
cls.loadOntology()
cls.ensure_resource_test_model_loaded()

def test_delete_by_query(self):
"""
Test deleting documents by query in Elasticsearch
Expand All @@ -64,7 +83,6 @@ def test_delete_by_query(self):
query = Query(se, start=0, limit=100)
match = Match(field="type", query="altLabel")
query.add_query(match)

query.delete(index="test", refresh=True)

self.assertEqual(se.count(index="test"), 10)
Expand Down Expand Up @@ -93,7 +111,7 @@ def test_bulk_add_documents(self):
)
)

ret = se.bulk_index(documents, refresh=True)
se.bulk_index(documents, refresh=True)
count_after = se.count(index="test")
self.assertEqual(count_after - count_before, 10)

Expand All @@ -109,3 +127,42 @@ def test_bulk_indexer(self):

count_after = se.count(index="bulk")
self.assertEqual(count_after, 1001)

def test_search_terms(self):
"""
Test finding a resource by a term
"""

nodeid = "c9b37b7c-17b3-11eb-a708-acde48001122"
tileid = "bebffbea-daf6-414e-80c2-530ec88d2705"
resourceinstanceid = "745f5e4a-d645-4c50-bafc-c677ea95f060"
resource = Resource(uuid.UUID(resourceinstanceid))
user = User.objects.get(username="Tester")
resource.graph_id = "c9b37a14-17b3-11eb-a708-acde48001122"
resource.save(user=user, transaction_id=uuid.uuid4())
tile_data = {}
tile_data[nodeid] = {
"en": {"value": "Etiwanda Avenue Street Trees", "direction": "ltr"}
}
new_tile = Tile(
tileid=uuid.UUID(tileid),
resourceinstance_id=resourceinstanceid,
data=tile_data,
nodegroup_id=nodeid,
)
new_tile.save()
time.sleep(1) # wait a moment for ES to finish indexing
request = HttpRequest()
request.method = "GET"
request.GET.__setitem__("lang", "en")
request.GET.__setitem__("q", "Etiwanda")
request.LANGUAGE_CODE = "en"
request.user = user
response = search_terms(request)
result = {}
try:
result = json.loads(response.content)
except json.decoder.JSONDecodeError:
print("Failed to parse search result")
self.assertTrue("terms" in result and len(result["terms"]) == 1)

0 comments on commit 0c36502

Please sign in to comment.