Skip to content

Commit 49c5350

Browse files
authored
Merge pull request #11 from NatashaAlker/exercise_2
Exercise 2
2 parents aae58dd + 3439c17 commit 49c5350

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

testing_workshop/functions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def get_metadata(self):
7676
def get_iiif_image_url(self):
7777
"""Returns the IIIF social media image of the page."""
7878
# Exercise 2 - fill in the implementation here
79-
pass
79+
response = requests.get(self.url)
80+
iiifSoup = BeautifulSoup(response.text)
81+
return iiifSoup.head.find(property="og:image")["content"]
8082

8183

8284
class NamedEntityDocument:

testing_workshop/tests/test_functions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ def test_get_metadata_code_500_raises_exception(self, page_url_invalid):
4444
page.get_metadata()
4545

4646
# Exercise 2 - add test(s) for get_iiif_image_url() here
47+
def test_get_iiif_image_url(self, page_url_valid):
48+
page = DigitalLibraryPage(page_url_valid)
49+
iiif_image_url = page.get_iiif_image_url()
50+
assert (
51+
iiif_image_url
52+
== "https://images.lib.cam.ac.uk/iiif/MS-DAR-00100-000-00001.jp2/0,1885,2986,1568/1200,630/0/default.jpg"
53+
)
4754

4855
# Exercise 5 - add test for expected exception FileNotFoundAtUrl for get_iiif_image_url() here
4956

testing_workshop/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def ner(request):
2525

2626
try:
2727
item = DigitalLibraryPage(xml_url)
28-
# iiif_image = item.get_iiif_image_url() # Uncomment Exercise 2
28+
iiif_image = item.get_iiif_image_url() # Uncomment Exercise 2
2929

3030
letter = Letter(item.get_metadata())
3131
xml_title = letter.get_title()

0 commit comments

Comments
 (0)