-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to scraping Goodreads rather than using API
* management commands converted into one view, sync * updated tests * got rid of all the views related to using the goodreads api * got rid of redis dependency Closes #170 and probably some others too
- Loading branch information
1 parent
0d8f88f
commit de47ebb
Showing
24 changed files
with
433 additions
and
1,421 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,32 +1,38 @@ | ||
from unittest.mock import patch, Mock | ||
import datetime | ||
|
||
from django.test import TestCase | ||
|
||
from books import goodreadstools | ||
|
||
|
||
class TestGoodreadstools(TestCase): | ||
def setUp(self): | ||
self.client = Mock() | ||
self.redistools = Mock() | ||
|
||
def test_get_author_new(self): | ||
with patch.multiple( | ||
'books.goodreadstools', | ||
_client=self.client, | ||
redistools=self.redistools | ||
): | ||
self.redistools.get_author.return_value = None | ||
self.client.find_author.return_value = None | ||
self.assertEqual(None, goodreadstools.get_author_by_name('new')) | ||
self.client.find_author.assert_called_once_with('new') | ||
|
||
def test_get_books_new(self): | ||
with patch.multiple( | ||
'books.goodreadstools', | ||
_client=self.client, | ||
redistools=self.redistools | ||
): | ||
self.redistools.get_book.return_value = None | ||
self.client.search_books.return_value = [] | ||
self.assertEqual([], goodreadstools.get_books_by_title('new')) | ||
self.client.search_books.assert_called_once_with('new') | ||
class TestParseNumPages(TestCase): | ||
def test_invalid_input(self): | ||
self.assertEqual(None, goodreadstools._parse_num_pages('blah')) | ||
|
||
def test_valid_input(self): | ||
self.assertEqual(123, goodreadstools._parse_num_pages('123\np')) | ||
|
||
|
||
class TestParseId(TestCase): | ||
def test_with_hyphen(self): | ||
self.assertEqual( | ||
'37941942', | ||
goodreadstools._parse_id('/book/show/37941942-the-flame') | ||
) | ||
|
||
def test_without_hyphen(self): | ||
self.assertEqual( | ||
'1188779', | ||
goodreadstools._parse_id('/book/show/1188779.Money') | ||
) | ||
|
||
|
||
class TestParseDate(TestCase): | ||
def test_invalid_input(self): | ||
self.assertEqual(None, goodreadstools._parse_date('')) | ||
|
||
def test_valid_input(self): | ||
self.assertEqual( | ||
datetime.date(2023, 2, 7), | ||
goodreadstools._parse_date('Feb 07, 2023') | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.