-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
54 additions
and
17 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
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,8 @@ | ||
class FormatExists(object): | ||
|
||
def __init__(self, connection): | ||
self.__connection = connection | ||
|
||
def execute(self, book_id, book_format): | ||
sql = "SELECT 1 FROM BookFormat WHERE Book=? AND Format=?" | ||
return len(self.__connection.execute_sql_fetch_all_with_params(sql, (book_id, book_format))) > 0 |
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
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,25 @@ | ||
import unittest | ||
from unittest.mock import Mock | ||
from aquarius.persistence.sqlitepersistence.Connection import Connection | ||
from aquarius.persistence.sqlitepersistence.FormatExists import FormatExists | ||
|
||
|
||
class TestFormatExists(unittest.TestCase): | ||
|
||
def test_instantiation(self): | ||
FormatExists(Mock(Connection)) | ||
|
||
def test_book_does_not_exist_return_false(self): | ||
conn = self.setup_mock([]) | ||
a = FormatExists(conn) | ||
self.assertFalse(a.execute(book_id=1, book_format="epub")) | ||
|
||
def test_book_exists_returns_true(self): | ||
conn = self.setup_mock([1]) | ||
a = FormatExists(conn) | ||
self.assertTrue(a.execute(book_id=1, book_format="epub")) | ||
|
||
def setup_mock(self, return_value): | ||
conn = Mock(Connection) | ||
conn.execute_sql_fetch_all_with_params = Mock(return_value=return_value) | ||
return conn |
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