-
-
Notifications
You must be signed in to change notification settings - Fork 19
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 #47 from bport/unittest
Add unittests, port Config code to SQLAlchemy
- Loading branch information
Showing
5 changed files
with
85 additions
and
6 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,53 @@ | ||
# -*- coding: UTF-8 -*- | ||
""" | ||
Alias test cases | ||
@author: Benjamin Port <benjamin.port@ben2367.fr> | ||
@license: GPL v3 or later | ||
""" | ||
|
||
import unittest | ||
import sys | ||
from io import StringIO | ||
|
||
from yokadi.core import db | ||
from yokadi.core.db import setDefaultConfig | ||
from yokadi.core.yokadiexception import YokadiException | ||
from yokadi.ycli import tui | ||
from yokadi.ycli.main import YokadiCmd | ||
|
||
|
||
class ConfTestCase(unittest.TestCase): | ||
def setUp(self): | ||
db.connectDatabase("", memoryDatabase=True) | ||
setDefaultConfig() | ||
self.session = db.getSession() | ||
tui.clearInputAnswers() | ||
self.cmd = YokadiCmd() | ||
|
||
def testConfig(self): | ||
out = StringIO() | ||
oldstdout = sys.stdout | ||
tui.stdout = out | ||
self.cmd.do_c_set("ALARM_DELAY 69") | ||
self.cmd.do_c_get("ALARM_DELAY") | ||
self.assertTrue("ALARM_DELAY" in out.getvalue()) | ||
self.assertTrue("69" in out.getvalue()) | ||
tui.stdout = oldstdout | ||
|
||
def testPositiveValueConfig(self): | ||
self.assertRaises(YokadiException, self.cmd.do_c_set, "ALARM_DELAY -1") | ||
self.assertRaises(YokadiException, self.cmd.do_c_set, "ALARM_SUSPEND -1") | ||
self.assertRaises(YokadiException, self.cmd.do_c_set, "PURGE_DELAY -1") | ||
|
||
def testPassphraseCacheValue(self): | ||
# Test PASSPHRASE_CACHE error | ||
self.assertRaises(YokadiException, self.cmd.do_c_set, "PASSPHRASE_CACHE 2") | ||
|
||
# Test PASSPHRASE_CACHE valid value (if that work we don't have exception) | ||
self.cmd.do_c_set("PASSPHRASE_CACHE 0") | ||
self.cmd.do_c_set("PASSPHRASE_CACHE 1") | ||
|
||
def testWrongKey(self): | ||
# Test PASSPHRASE_CACHE error | ||
self.assertRaises(YokadiException, self.cmd.do_c_set, "BAD_KEY value") | ||
self.assertRaises(YokadiException, self.cmd.do_c_get, "BAD_KEY") |
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
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