Skip to content

Commit

Permalink
tests for import normdata functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Dec 28, 2023
1 parent 7606fa9 commit 8f7cf22
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
44 changes: 44 additions & 0 deletions apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from apis_core.apis_entities.forms import get_entities_form
from apis_core.apis_entities.models import Person
from apis_core.apis_metainfo.models import Uri
from normdata.forms import NormDataImportForm

client = Client()
USER = {"username": "testuser", "password": "somepassword"}
Expand Down Expand Up @@ -128,3 +130,45 @@ def test_010_delete_views(self):
self.assertContains(response, "Löschen von")
self.assertContains(response, item.id)
item.delete()

def test_010_import_nordmdata_view(self):
client.login(**USER)
payload = {
"normdata_url": "http://lobid.org/gnd/118566512",
"entity_type": "person",
}
url = reverse(
"normdata:import_from_normdata",
)
response = client.post(url, payload, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(Uri.objects.filter(uri__icontains="118566512"))
payload = {
"normdata_url": "https://www.geonames.org/2772400/linz.html",
"entity_type": "place",
}
response = client.post(url, payload, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(Uri.objects.filter(uri__icontains="2772400"))

payload = {
"normdata_url": "https://www.wikidata.org/wiki/Q119350694",
"entity_type": "person",
}
response = client.post(url, payload, follow=True)
self.assertEqual(response.status_code, 200)

payload = {
"normdata_url": "https://www.wikidata.org/wiki/Q119350694",
"entity_type": "person",
}
response = client.post(url, payload, follow=True)
self.assertEqual(response.status_code, 200)

def test_011_import_normdata_form(self):
payload = {
"normdata_url": "http://lobid.org/gnd/118566512",
"entity_type": "person"
}
form = NormDataImportForm(data=payload)
self.assertTrue(form.is_valid())
2 changes: 1 addition & 1 deletion normdata/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class NormDataImportForm(forms.Form):
gnd_url = forms.URLField(
normdata_url = forms.URLField(
label="Normdata URL",
help_text="Zum Beispiel: http://lobid.org/gnd/118566512 oder https://www.geonames.org/2772400/linz.html",
max_length=100,
Expand Down
2 changes: 1 addition & 1 deletion normdata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_success_url(self):
return reverse("apis:apis_entities:person_list_view")

def form_valid(self, form):
raw_url = form.data["gnd_url"]
raw_url = form.data["normdata_url"]
entity_type = form.data["entity_type"]
import_from_normdata(raw_url, entity_type)
return super().form_valid(form)

0 comments on commit 8f7cf22

Please sign in to comment.