mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
use mocks for isni API calls
- fixes a couple of tests making author ISNI calls - notes a future TODO to remove some possibly useless code
This commit is contained in:
parent
578de27515
commit
aa6eaccfbb
2 changed files with 42 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
""" test for app action functionality """
|
""" test for app action functionality """
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
import responses
|
import responses
|
||||||
|
from responses import matchers
|
||||||
|
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
@ -46,6 +47,43 @@ class EditBookViews(TestCase):
|
||||||
parent_work=self.work,
|
parent_work=self.work,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.authors_body = "<?xml version='1.0' encoding='UTF-8' ?><?xml-stylesheet type='text/xsl' href='http://isni.oclc.org/sru/DB=1.2/?xsl=searchRetrieveResponse' ?><srw:searchRetrieveResponse xmlns:srw='http://www.loc.gov/zing/srw/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:diag='http://www.loc.gov/zing/srw/diagnostic/' xmlns:xcql='http://www.loc.gov/zing/cql/xcql/'><srw:version>1.1</srw:version><srw:records><srw:record><isniUnformatted>0000000084510024</isniUnformatted></srw:record></srw:records></srw:searchRetrieveResponse>"
|
||||||
|
|
||||||
|
self.author_body = "<?xml version='1.0' encoding='UTF-8' ?><?xml-stylesheet type='text/xsl' href='http://isni.oclc.org/sru/DB=1.2/?xsl=searchRetrieveResponse' ?><srw:searchRetrieveResponse xmlns:srw='http://www.loc.gov/zing/srw/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:diag='http://www.loc.gov/zing/srw/diagnostic/' xmlns:xcql='http://www.loc.gov/zing/cql/xcql/'><srw:records><srw:record><srw:recordData><responseRecord><ISNIAssigned><isniUnformatted>0000000084510024</isniUnformatted><isniURI>https://isni.org/isni/0000000084510024</isniURI><dataConfidence>60</dataConfidence><ISNIMetadata><identity><personOrFiction><personalName><surname>Catherine Amy Dawson Scott</surname><nameTitle>poet and novelist</nameTitle><nameUse>public</nameUse><source>VIAF</source><source>WKP</source><subsourceIdentifier>Q544961</subsourceIdentifier></personalName><personalName><forename>C. A.</forename><surname>Dawson Scott</surname><marcDate>1865-1934</marcDate><nameUse>public</nameUse><source>VIAF</source><source>NLP</source><subsourceIdentifier>a28927850</subsourceIdentifier></personalName><sources><codeOfSource>VIAF</codeOfSource><sourceIdentifier>45886165</sourceIdentifier><reference><class>ALL</class><role>CRE</role><URI>http://viaf.org/viaf/45886165</URI></reference></sources><externalInformation><information>Wikipedia</information><URI>https://en.wikipedia.org/wiki/Catherine_Amy_Dawson_Scott</URI></externalInformation></ISNIMetadata></ISNIAssigned></responseRecord></srw:recordData></srw:record></srw:records></srw:searchRetrieveResponse>"
|
||||||
|
|
||||||
|
responses.get(
|
||||||
|
"http://isni.oclc.org/sru/",
|
||||||
|
content_type="text/xml",
|
||||||
|
match=[
|
||||||
|
matchers.query_param_matcher(
|
||||||
|
{"query": 'pica.na="Sappho"'}, strict_match=False
|
||||||
|
)
|
||||||
|
],
|
||||||
|
body=self.authors_body,
|
||||||
|
)
|
||||||
|
|
||||||
|
responses.get(
|
||||||
|
"http://isni.oclc.org/sru/",
|
||||||
|
content_type="text/xml",
|
||||||
|
match=[
|
||||||
|
matchers.query_param_matcher(
|
||||||
|
{"query": 'pica.na="Some Guy"'}, strict_match=False
|
||||||
|
)
|
||||||
|
],
|
||||||
|
body=self.authors_body,
|
||||||
|
)
|
||||||
|
|
||||||
|
responses.get(
|
||||||
|
"http://isni.oclc.org/sru/",
|
||||||
|
content_type="text/xml",
|
||||||
|
match=[
|
||||||
|
matchers.query_param_matcher(
|
||||||
|
{"query": 'pica.isn="0000000084510024"'}, strict_match=False
|
||||||
|
)
|
||||||
|
],
|
||||||
|
body=self.author_body,
|
||||||
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_edit_book_get(self):
|
def test_edit_book_get(self):
|
||||||
|
@ -97,6 +135,7 @@ class EditBookViews(TestCase):
|
||||||
result.context_data["cover_url"], "http://local.host/cover.jpg"
|
result.context_data["cover_url"], "http://local.host/cover.jpg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@responses.activate
|
||||||
def test_edit_book_add_author(self):
|
def test_edit_book_add_author(self):
|
||||||
"""lets a user edit a book with new authors"""
|
"""lets a user edit a book with new authors"""
|
||||||
view = views.EditBook.as_view()
|
view = views.EditBook.as_view()
|
||||||
|
@ -227,6 +266,7 @@ class EditBookViews(TestCase):
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
self.assertTrue(self.book.cover)
|
self.assertTrue(self.book.cover)
|
||||||
|
|
||||||
|
@responses.activate
|
||||||
def test_add_authors_helper(self):
|
def test_add_authors_helper(self):
|
||||||
"""converts form input into author matches"""
|
"""converts form input into author matches"""
|
||||||
form = forms.EditionForm(instance=self.book)
|
form = forms.EditionForm(instance=self.book)
|
||||||
|
|
|
@ -85,6 +85,8 @@ def find_authors_by_name(name_string, description=False):
|
||||||
# build list of possible authors
|
# build list of possible authors
|
||||||
possible_authors = []
|
possible_authors = []
|
||||||
for element in root.iter("responseRecord"):
|
for element in root.iter("responseRecord"):
|
||||||
|
|
||||||
|
# TODO: we don't seem to do anything with the personal_name variable - is this code block needed?
|
||||||
personal_name = element.find(".//forename/..")
|
personal_name = element.find(".//forename/..")
|
||||||
if not personal_name:
|
if not personal_name:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue