From 2054f0b083e48525ca60998e96568d1bd9dbf4cc Mon Sep 17 00:00:00 2001 From: Olivia Warren Date: Thu, 27 Jul 2023 16:05:10 +0100 Subject: [PATCH 1/2] added iiif test --- testing_workshop/tests/test_functions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testing_workshop/tests/test_functions.py b/testing_workshop/tests/test_functions.py index 9cf8177..eae7145 100644 --- a/testing_workshop/tests/test_functions.py +++ b/testing_workshop/tests/test_functions.py @@ -44,6 +44,10 @@ def test_get_metadata_code_500_raises_exception(self, page_url_invalid): page.get_metadata() # Exercise 2 - add test(s) for get_iiif_image_url() here + def test_get_iiif_image_url(self, page_url_valid): + page = DigitalLibraryPage(page_url_valid) + result = page.get_iiif_image_url() + assert result == "unknown" # Exercise 5 - add test for expected exception FileNotFoundAtUrl for get_iiif_image_url() here From b5f37cd67fdc3797dc90227d1eae28d40b7ee969 Mon Sep 17 00:00:00 2001 From: Olivia Warren Date: Thu, 27 Jul 2023 16:46:03 +0100 Subject: [PATCH 2/2] fixed iiif url test --- testing_workshop/functions.py | 4 +++- testing_workshop/tests/test_functions.py | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/testing_workshop/functions.py b/testing_workshop/functions.py index 8c9a3a9..863847b 100644 --- a/testing_workshop/functions.py +++ b/testing_workshop/functions.py @@ -76,7 +76,9 @@ def get_metadata(self): def get_iiif_image_url(self): """Returns the IIIF social media image of the page.""" # Exercise 2 - fill in the implementation here - pass + response = requests.get(self.url) + iiifSoup = BeautifulSoup(response.text) + return iiifSoup.head.find(property="og:image")["content"] class NamedEntityDocument: diff --git a/testing_workshop/tests/test_functions.py b/testing_workshop/tests/test_functions.py index eae7145..e1afffc 100644 --- a/testing_workshop/tests/test_functions.py +++ b/testing_workshop/tests/test_functions.py @@ -46,8 +46,11 @@ def test_get_metadata_code_500_raises_exception(self, page_url_invalid): # Exercise 2 - add test(s) for get_iiif_image_url() here def test_get_iiif_image_url(self, page_url_valid): page = DigitalLibraryPage(page_url_valid) - result = page.get_iiif_image_url() - assert result == "unknown" + iiif_image_url = page.get_iiif_image_url() + assert ( + iiif_image_url + == "https://images.lib.cam.ac.uk/iiif/MS-DAR-00100-000-00001.jp2/0,1885,2986,1568/1200,630/0/default.jpg" + ) # Exercise 5 - add test for expected exception FileNotFoundAtUrl for get_iiif_image_url() here