replace pytest by unittest
This commit is contained in:
parent
bf1447a3a9
commit
3eb1b86246
4 changed files with 107 additions and 86 deletions
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from stacosys.conf.config import Config, ConfigParameter
|
||||
|
||||
EXPECTED_DB_SQLITE_FILE = "db.sqlite"
|
||||
|
|
@ -10,48 +11,46 @@ EXPECTED_IMAP_PORT = "5000"
|
|||
EXPECTED_IMAP_LOGIN = "user"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def conf():
|
||||
conf = Config()
|
||||
conf.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE)
|
||||
conf.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
|
||||
conf.put(ConfigParameter.IMAP_PORT, EXPECTED_IMAP_PORT)
|
||||
conf.put(ConfigParameter.SMTP_STARTTLS, "yes")
|
||||
conf.put(ConfigParameter.IMAP_SSL, "false")
|
||||
return conf
|
||||
class ConfigTestCase(unittest.TestCase):
|
||||
|
||||
def conf(self):
|
||||
conf = Config()
|
||||
conf.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE)
|
||||
conf.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
|
||||
conf.put(ConfigParameter.IMAP_PORT, EXPECTED_IMAP_PORT)
|
||||
conf.put(ConfigParameter.SMTP_STARTTLS, "yes")
|
||||
conf.put(ConfigParameter.IMAP_SSL, "false")
|
||||
return conf
|
||||
|
||||
def test_exists(conf):
|
||||
assert conf is not None
|
||||
assert conf.exists(ConfigParameter.DB_SQLITE_FILE)
|
||||
assert not conf.exists(ConfigParameter.IMAP_HOST)
|
||||
def test_exists(self):
|
||||
conf = self.conf()
|
||||
self.assertTrue(conf.exists(ConfigParameter.DB_SQLITE_FILE))
|
||||
self.assertFalse(conf.exists(ConfigParameter.IMAP_HOST))
|
||||
|
||||
def test_get(self):
|
||||
conf = self.conf()
|
||||
self.assertEqual(conf.get(ConfigParameter.DB_SQLITE_FILE), EXPECTED_DB_SQLITE_FILE)
|
||||
self.assertEqual(conf.get(ConfigParameter.HTTP_PORT), EXPECTED_HTTP_PORT)
|
||||
self.assertIsNone(conf.get(ConfigParameter.HTTP_HOST))
|
||||
self.assertEqual(conf.get(ConfigParameter.HTTP_PORT), EXPECTED_HTTP_PORT)
|
||||
self.assertEqual(conf.get(ConfigParameter.IMAP_PORT), EXPECTED_IMAP_PORT)
|
||||
self.assertEqual(conf.get_int(ConfigParameter.IMAP_PORT), int(EXPECTED_IMAP_PORT))
|
||||
try:
|
||||
conf.get_int(ConfigParameter.HTTP_PORT)
|
||||
self.assertTrue(False)
|
||||
except Exception:
|
||||
pass
|
||||
self.assertTrue(conf.get_bool(ConfigParameter.SMTP_STARTTLS))
|
||||
self.assertFalse(conf.get_bool(ConfigParameter.IMAP_SSL))
|
||||
try:
|
||||
conf.get_bool(ConfigParameter.DB_URL)
|
||||
self.assertTrue(False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def test_get(conf):
|
||||
assert conf is not None
|
||||
assert conf.get(ConfigParameter.DB_SQLITE_FILE) == EXPECTED_DB_SQLITE_FILE
|
||||
assert conf.get(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
|
||||
assert conf.get(ConfigParameter.HTTP_HOST) is None
|
||||
assert conf.get(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
|
||||
assert conf.get(ConfigParameter.IMAP_PORT) == EXPECTED_IMAP_PORT
|
||||
assert conf.get_int(ConfigParameter.IMAP_PORT) == int(EXPECTED_IMAP_PORT)
|
||||
try:
|
||||
conf.get_int(ConfigParameter.HTTP_PORT)
|
||||
assert False
|
||||
except Exception:
|
||||
pass
|
||||
assert conf.get_bool(ConfigParameter.SMTP_STARTTLS)
|
||||
assert not conf.get_bool(ConfigParameter.IMAP_SSL)
|
||||
try:
|
||||
conf.get_bool(ConfigParameter.DB_URL)
|
||||
assert False
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def test_put(conf):
|
||||
assert conf is not None
|
||||
assert not conf.exists(ConfigParameter.IMAP_LOGIN)
|
||||
conf.put(ConfigParameter.IMAP_LOGIN, EXPECTED_IMAP_LOGIN)
|
||||
assert conf.exists(ConfigParameter.IMAP_LOGIN)
|
||||
assert conf.get(ConfigParameter.IMAP_LOGIN) == EXPECTED_IMAP_LOGIN
|
||||
def test_put(self):
|
||||
conf = self.conf()
|
||||
self.assertFalse(conf.exists(ConfigParameter.IMAP_LOGIN))
|
||||
conf.put(ConfigParameter.IMAP_LOGIN, EXPECTED_IMAP_LOGIN)
|
||||
self.assertTrue(conf.exists(ConfigParameter.IMAP_LOGIN))
|
||||
self.assertEqual(conf.get(ConfigParameter.IMAP_LOGIN), EXPECTED_IMAP_LOGIN)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue