pyytdata
pyytdata copied to clipboard
Add new testcases to increase code coverage
Hey, I am new to this testing field, can you elaborate a little . I can work on this if you permit.
Hey, I am new to this testing field, can you elaborate a little . I can work on this if you permit.
you should check the file inside tests, As you can see we are validating only one API response get_videoinfo
https://github.com/Agent-Hellboy/pyytdata/blob/master/tests/test_util.py#L16
we should validate all other API responses
you can check this article to know more about python unit test https://www.digitalocean.com/community/tutorials/how-to-use-unittest-to-write-a-test-case-for-a-function-in-python
yes , I got to the source file . So the API responses are the get_links(), get_description() , and others. Am I right? I have to validate that in the tests_utils.py . But I dont know how exactly to do this.
yes , I got to the source file . So the API responses are the get_links(), get_description() , and others. Am I right?
Yes get_links(), get_description()
these are the APIs you have to validate responses of these APIs
I have to validate that in the tests_utils.py. But I don't know how exactly to do this. Yes, read the article I share with you.
def test_get_description(self):
not sure bout the body of the function and on what basis I can validate. In the article , they had a list to validate upon. (Sorry for all this query , I am pretty new to this.)
not sure bout the body of the function and on what basis I can validate. In the article , they had a list to validate upon. (Sorry for all this query , I am pretty new to this.)
Yes, that's the trickiest part, take some time, and play around with the package you will get some idea if not I will share some pointers with you tomorrow.
Can you assign it to me , I will work around it at evening or midnight. I have exam tomarrow so need to prepare for that as well. I will surely solve this issue.
@Agent-Hellboy I got some idea about unnitest . And some assert methods as well. The responses will be mostly a type of string. for example if we take get_description()
,it should be a kind of string ,checking if the description is null or not will be enough?
or should we check assertIn() to compare with some sample data.
def test_get_videoinfo(self):
self.assertTrue(len(self.rslt) == 1)
I do not understand this part though .
class TestPyYtData(unittest.TestCase):
def test_check_env(self):
self.assertTrue(os.environ.get("API_KEY") != None)
def setUp(self):
self.data = PyYtData("flask", 1)
self.rslt = self.data.get_videoinfo()
def test_get_videoinfo(self):
self.assertTrue(len(self.rslt) == 1)
Here you can see we are querying Youtube data v3 API with flask keyword which is just like searching on youtube and parameter 1 means we want only one result, self.data is VidInfo object you can add a print statement and check these things. As self.data is PyYtData object it has a method called get_videoinfo
which returns video info objects https://github.com/Agent-Hellboy/pyytdata/blob/3e70e427d7c3c8bf0c799819bc4e8ab12be78840/pyytdata/util/vidinfo.py#L46
Like Video Info we have other classes like Channel Info you need to add test cases for methods of these classes
I will suggest you read the article I have shared and watch some videos also.
self.assertTrue(len(self.rslt) == 1)
here we are validating whether we get one videoinfo object which we have requested in setup method.