-
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1113 from Santhosh-Siddhardha/main2
Added test file for librarygenesis module
- Loading branch information
Showing
3 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .library import LibGen | ||
|
||
__all__ = ["LibGen"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import unittest | ||
from scrape_up.librarygenesis import LibGen | ||
|
||
|
||
class TestLibGen(unittest.TestCase): | ||
""" | ||
| Methods | Details | | ||
| --------------| ----------------------------- | | ||
| `.getBooks(book_name=" ")` | Returns the books with name, author, size, format, book link, book cover link, language | | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Initialize a LibGen instance before each test method. | ||
""" | ||
self.libgen = LibGen() | ||
|
||
def test_getBooks_empty_name(self): | ||
""" | ||
Test the getBooks() method with an empty book name. | ||
""" | ||
try: | ||
result = self.libgen.getBooks("") | ||
self.assertEqual( | ||
result, | ||
"Error: enter name", | ||
"Expected error message for empty book name", | ||
) | ||
except: | ||
return None | ||
|
||
def test_getBooks_short_name(self): | ||
""" | ||
Test the getBooks() method with a short book name. | ||
""" | ||
try: | ||
result = self.libgen.getBooks("AI") | ||
self.assertEqual( | ||
result, | ||
"Error: Title Too Short", | ||
"Expected error message for short book name", | ||
) | ||
except: | ||
return None | ||
|
||
def test_getBooks_valid_name(self): | ||
""" | ||
Test the getBooks() method with a valid book name. | ||
""" | ||
try: | ||
result = self.libgen.getBooks("Python") | ||
self.assertIsInstance(result, list, "Expected a list of books") | ||
if result: # Check if there are books returned | ||
book = result[0] | ||
self.assertIn("name", book, "Book should have a 'name' field") | ||
self.assertIn("author", book, "Book should have an 'author' field") | ||
self.assertIn("size", book, "Book should have a 'size' field") | ||
self.assertIn("format", book, "Book should have a 'format' field") | ||
self.assertIn("link", book, "Book should have a 'link' field") | ||
self.assertIn("language", book, "Book should have a 'language' field") | ||
except: | ||
return None | ||
|
||
def test_getBooks_no_results(self): | ||
""" | ||
Test the getBooks() method with a book name that yields no results. | ||
""" | ||
try: | ||
result = self.libgen.getBooks("somebookthatdoesnotexist") | ||
self.assertEqual( | ||
result, | ||
"Error: no results found", | ||
"Expected error message for no results found", | ||
) | ||
except: | ||
return None | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |