Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:recipy/recipy
- Loading branch information
Showing
3 changed files
with
105 additions
and
8 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,61 @@ | ||
import os | ||
import unittest | ||
import mock | ||
|
||
from recipy.log import open_or_create_db, log_values, log_init | ||
|
||
|
||
TEST_DB_PATH = os.path.expanduser('~/.recipy/test_recipyDB.json') | ||
|
||
|
||
def open_or_create_test_db(): | ||
return open_or_create_db(TEST_DB_PATH) | ||
|
||
|
||
class TestLog(unittest.TestCase): | ||
def setUp(self): | ||
""" Invoke log_init with the test database, so as not to interfere with the regular database """ | ||
with mock.patch('recipy.log.open_or_create_db', open_or_create_test_db): | ||
log_init() | ||
|
||
def test_log_values_single_dictionary(self): | ||
with mock.patch('recipy.log.open_or_create_db', open_or_create_test_db): | ||
log_values({'a': 1, 'b': 2}) | ||
|
||
db = open_or_create_test_db() | ||
last_entry = db.all()[-1] | ||
|
||
self.assertIn('custom_values', last_entry) | ||
self.assertEquals(last_entry['custom_values'], {'a': 1, 'b': 2}) | ||
|
||
def test_log_values_multiple_dictionaries(self): | ||
with mock.patch('recipy.log.open_or_create_db', open_or_create_test_db): | ||
log_values({'a': 1, 'b': 2}) | ||
log_values({'a': 3, 'b': 4}) | ||
log_values({'c': 5, 'd': 6}) | ||
|
||
db = open_or_create_test_db() | ||
last_entry = db.all()[-1] | ||
|
||
self.assertIn('custom_values', last_entry) | ||
self.assertEquals(last_entry['custom_values'], {'a': 3, 'b': 4, 'c': 5, 'd': 6}) | ||
|
||
def test_log_values_keyword_arguments(self): | ||
with mock.patch('recipy.log.open_or_create_db', open_or_create_test_db): | ||
log_values(cat=1, dog=2) | ||
|
||
db = open_or_create_test_db() | ||
last_entry = db.all()[-1] | ||
|
||
self.assertIn('custom_values', last_entry) | ||
self.assertEquals(last_entry['custom_values'], {'cat': 1, 'dog': 2}) | ||
|
||
def test_log_values_dict_and_keyword_arguments(self): | ||
with mock.patch('recipy.log.open_or_create_db', open_or_create_test_db): | ||
log_values({'bananas': 3, 'pears': 4}, apples=1, oranges=2) | ||
|
||
db = open_or_create_test_db() | ||
last_entry = db.all()[-1] | ||
|
||
self.assertIn('custom_values', last_entry) | ||
self.assertEquals(last_entry['custom_values'], {'bananas': 3, 'pears': 4, 'apples':1, 'oranges':2}) |
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