Skip to content

Commit

Permalink
wip resolver views (tests added)
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Jan 3, 2024
1 parent 66a3a05 commit 851f851
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
15 changes: 5 additions & 10 deletions apis_core/apis_entities/resolver_views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
from django.shortcuts import redirect
from icecream import ic

from apis_core.apis_metainfo.models import Uri, TempEntityClass
from apis_core.apis_metainfo.models import TempEntityClass, Uri


def uri_resolver(request):
uri = request.GET.get("uri", None)
format_param = request.GET.get("format", False)
requested_format = request.META.get("HTTP_ACCEPT")
# format_param = request.GET.get("format", False)
# requested_format = request.META.get("HTTP_ACCEPT")
if uri is None:
raise Http404
else:
Expand All @@ -18,9 +17,5 @@ def uri_resolver(request):
except ObjectDoesNotExist:
raise Http404
entity = TempEntityClass.objects_inheritance.get_subclass(pk=uri.entity_id)
entity_type = entity.__class__.__name__.lower()
ic(entity_type)
if requested_format is not None:
if requested_format.startswith("text/html") and format_param is False:
url = entity.get_absolute_url()
return redirect(url)
url = entity.get_absolute_url()
return redirect(url)
24 changes: 23 additions & 1 deletion apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from icecream import ic

from apis_core.apis_entities.forms import get_entities_form
from apis_core.apis_entities.models import Person
from apis_core.apis_entities.models import Person, Place
from apis_core.apis_metainfo.models import Uri
from normdata.forms import NormDataImportForm
from normdata.utils import (
Expand Down Expand Up @@ -275,3 +275,25 @@ def test_020_api_list_view(self):
except Exception as e:
print(value, e)
continue

def test_021_api_detail_view(self):
item = Person.objects.last()
r = client.get(item.get_api_url())
self.assertTrue(r.status_code, 200)
item = Place.objects.last()
r = client.get(item.get_api_url())
self.assertTrue(r.status_code, 200)

def test_022_resolver_view(self):
target = Person.objects.last()
source = Person.objects.create(**{"name": "wirdgleichgemerged"})
source_id = source.id
source_uri = f"https://pmb.acdh.oeaw.ac.at/entity/{source.id}/"
target.merge_with(source_id)
url = reverse("uri-resolver")
r = client.get(url)
self.assertTrue(r.status_code, 404)
r = client.get(f"{url}?uri={source_uri}")
self.assertTrue(r.status_code, 302)
r = client.get(f"{url}?uri=https://dasgibtsjagarnicht.com")
self.assertTrue(r.status_code, 404)

0 comments on commit 851f851

Please sign in to comment.