From 007c1132e21782791d0691148022d2e900d9ccf5 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Sat, 11 Nov 2023 22:14:33 +0100 Subject: [PATCH] Add another test case --- .../vcr/fetch_site_information_valid.yaml | 60 +++++++++++++++++++ pyproject.toml | 3 + tests/test_scraper.py | 10 +++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 fixtures/vcr/fetch_site_information_valid.yaml diff --git a/fixtures/vcr/fetch_site_information_valid.yaml b/fixtures/vcr/fetch_site_information_valid.yaml new file mode 100644 index 0000000..4361d2a --- /dev/null +++ b/fixtures/vcr/fetch_site_information_valid.yaml @@ -0,0 +1,60 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.31.0 + method: GET + uri: https://example.org/ + response: + body: + string: !!binary | + H4sIAMIVqF0AA31UTXPbIBC9+1ds1UsyIyQnaRqPLWn6mWkPaQ9pDz0SsbKYCFAByfZ08t+7Qo4j + N5makYFdeLvvsZC9Eqb0uxah9qopZtljh1wUM6Bf5qVvsPi85aptED4ZxaXO0tE6G5co9BzKmluH + Po86X7FFBGkxcdbetwx/d7LPo49Ge9SeDWEjKMdZHnnc+nQIvzpAvYSkucI86iVuWmP9ZP9GCl/n + AntZIguTGKSWXvKGuZI3mJ89QTm/IzJDBvvApXPR6LszYgd/wjBMeXm/tqbTgpWmMXYJr6s5tfPV + YYnidi31EuZPppYLIfX6yFZRpqziSja7JTDekpzM7ZxHFcPYs07G8KGR+v6Gl7fBdE2bYohucW0Q + fn6NaPy9RQ23XLth8gWbHr0sOXzDDslyMMTw3hJ3wqalzKGV1VMuYfAQ/oXsJ3SDcEt4O5+32+cM + L1EB77x5geg5qtV/RRPUJhncGSvQMsuF7BzplFweAZgtczUXZkPI7RYu6Luibxjb9R0/mcehJfPz + 09WEDF8O6sXU99JJj2JC7TGTi8WbxWKSyXD+TGBpLPfSEEttNE5B3ykUksOJ4lu21+dq0Od0An6s + 4lFV/KPYROVjx8MkZJaGCi3CWWXpeB1n2VCbdDsp2L6O67NnN5NMo68tftTSgQh2oFFlLHQOYZg1 + Tef8QLhHwBHBDQ56DjpF98kl8Mt0RGIXtnhCGqtlj6ahIXkJoLNIdHxtOg+tlRSiNHS0Ugcxgebc + 3VOFhOgtWiWdI0eSpe0hz4weCItVHg3PhFum6WazSSTXPDF2nY4hXbpPMypujB1IEKAKQZKE0HgR + ELM0iJOle6nS8UH7CyjrfG/oBAAA + headers: + Accept-Ranges: + - bytes + Age: + - '327361' + Cache-Control: + - max-age=604800 + Content-Encoding: + - gzip + Content-Length: + - '648' + Content-Type: + - text/html; charset=UTF-8 + Date: + - Sat, 11 Nov 2023 21:14:24 GMT + Etag: + - '"3147526947+gzip"' + Expires: + - Sat, 18 Nov 2023 21:14:24 GMT + Last-Modified: + - Thu, 17 Oct 2019 07:18:26 GMT + Server: + - ECS (dcb/7EA3) + Vary: + - Accept-Encoding + X-Cache: + - HIT + status: + code: 200 + message: OK +version: 1 diff --git a/pyproject.toml b/pyproject.toml index a67f762..2475a99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,9 @@ vcrpy = "^5.1.0" [tool.ruff] ignore = ["E501"] +[tool.isort] +profile = "black" + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/tests/test_scraper.py b/tests/test_scraper.py index 09ca3c2..72c70b7 100644 --- a/tests/test_scraper.py +++ b/tests/test_scraper.py @@ -3,7 +3,9 @@ import pytest import vcr -from cert_host_scraper.scraper import Options, fetch_urls +from cert_host_scraper.scraper import Options, fetch_site_information, fetch_urls + +TIMEOUT = 2 class TestScraper(TestCase): @@ -13,3 +15,9 @@ def test_fetch_urls_clean(self): results = fetch_urls("example.org", Options(timeout=2, clean=True)) self.assertEqual(4, len(results)) self.assertIn("https://www.example.org", results) + + @pytest.mark.enable_socket + @vcr.use_cassette("fixtures/vcr/fetch_site_information_valid.yaml") + def test_fetch_site_information_valid(self): + result = fetch_site_information("https://example.org", TIMEOUT) + self.assertEqual(200, result)