I'm making a screen-scraper that collects schedule data from a TV channel website. To do that, I have to fetch the website's raw HTML. I'm trying my hand at unit-testing for the first time and I have some knowledge about mocking, but I'm not too confident about it yet. (If someone could provide some good learning resources on this, I'd be more than grateful.)
The way I'm going about this is I'm trying to return a schedule class that will parse the DOM from the HTML data and strip the schedule data, like so:
from urllib.request import urlopen
def fetch_html():
url = "https://example.com"
response = urlopen(url)
dom = response.read()
return SomeScheduleClass(dom)
My point is I have no idea how to test if it actually returns SomeScheduleClass
as expected. Do I mock the http.client.HTTPResponse
object I get from the urlopen
? Do I somehow find a way to mock the response.read()
? Or do I not have to test this at all and I'm just wasting my time? If so, what should I test here?
On an unrelated note, I'm still very much rusty since everything I know about Python is self-learnt, so if this is incredibly basic and I'm wasting everyone's time, I'd be more than happy to delete this question and forget it ever existed. Thanks in advance!