replace unittest by pytest
This commit is contained in:
parent
b1c64d2cc8
commit
a62cb8eff1
2 changed files with 68 additions and 73 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
from stacosys.service import config
|
from stacosys.service import config
|
||||||
from stacosys.service.configuration import ConfigParameter
|
from stacosys.service.configuration import ConfigParameter
|
||||||
|
@ -11,31 +11,24 @@ EXPECTED_HTTP_PORT = 8080
|
||||||
EXPECTED_LANG = "fr"
|
EXPECTED_LANG = "fr"
|
||||||
|
|
||||||
|
|
||||||
class ConfigTestCase(unittest.TestCase):
|
@pytest.fixture
|
||||||
def setUp(self):
|
def init_config():
|
||||||
config.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE)
|
config.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE)
|
||||||
config.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
|
config.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
|
||||||
|
|
||||||
def test_exists(self):
|
def test_exists(init_config):
|
||||||
self.assertTrue(config.exists(ConfigParameter.DB_SQLITE_FILE))
|
assert config.exists(ConfigParameter.DB_SQLITE_FILE)
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(init_config):
|
||||||
self.assertEqual(
|
assert config.get(ConfigParameter.DB_SQLITE_FILE) == EXPECTED_DB_SQLITE_FILE
|
||||||
config.get(ConfigParameter.DB_SQLITE_FILE), EXPECTED_DB_SQLITE_FILE
|
assert config.get(ConfigParameter.HTTP_HOST) == ""
|
||||||
)
|
assert config.get(ConfigParameter.HTTP_PORT) == str(EXPECTED_HTTP_PORT)
|
||||||
self.assertEqual(config.get(ConfigParameter.HTTP_HOST), "")
|
assert config.get_int(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
|
||||||
self.assertEqual(
|
with pytest.raises(AssertionError):
|
||||||
config.get(ConfigParameter.HTTP_PORT), str(EXPECTED_HTTP_PORT)
|
|
||||||
)
|
|
||||||
self.assertEqual(config.get_int(ConfigParameter.HTTP_PORT), 8080)
|
|
||||||
try:
|
|
||||||
config.get_bool(ConfigParameter.DB_SQLITE_FILE)
|
config.get_bool(ConfigParameter.DB_SQLITE_FILE)
|
||||||
self.assertTrue(False)
|
|
||||||
except AssertionError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_put(self):
|
def test_put(init_config):
|
||||||
self.assertFalse(config.exists(ConfigParameter.LANG))
|
assert not config.exists(ConfigParameter.LANG)
|
||||||
config.put(ConfigParameter.LANG, EXPECTED_LANG)
|
config.put(ConfigParameter.LANG, EXPECTED_LANG)
|
||||||
self.assertTrue(config.exists(ConfigParameter.LANG))
|
assert config.exists(ConfigParameter.LANG)
|
||||||
self.assertEqual(config.get(ConfigParameter.LANG), EXPECTED_LANG)
|
assert config.get(ConfigParameter.LANG) == EXPECTED_LANG
|
||||||
|
|
|
@ -1,53 +1,55 @@
|
||||||
import unittest
|
#!/usr/bin/python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from stacosys.db import dao
|
from stacosys.db import dao
|
||||||
from stacosys.db import database
|
from stacosys.db import database
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
class DbTestCase(unittest.TestCase):
|
def setup_db():
|
||||||
def setUp(self):
|
|
||||||
database.setup(":memory:")
|
database.setup(":memory:")
|
||||||
|
|
||||||
def test_dao_published(self):
|
|
||||||
|
|
||||||
|
def test_dao_published(setup_db):
|
||||||
|
|
||||||
# test count published
|
# test count published
|
||||||
self.assertEqual(0, dao.count_published_comments(""))
|
assert 0 == dao.count_published_comments("")
|
||||||
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1")
|
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1")
|
||||||
self.assertEqual(0, dao.count_published_comments(""))
|
assert 0 == dao.count_published_comments("")
|
||||||
dao.publish_comment(c1)
|
dao.publish_comment(c1)
|
||||||
self.assertEqual(1, dao.count_published_comments(""))
|
assert 1 == dao.count_published_comments("")
|
||||||
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2")
|
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2")
|
||||||
dao.publish_comment(c2)
|
dao.publish_comment(c2)
|
||||||
self.assertEqual(2, dao.count_published_comments(""))
|
assert 2 == dao.count_published_comments("")
|
||||||
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3")
|
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3")
|
||||||
dao.publish_comment(c3)
|
dao.publish_comment(c3)
|
||||||
self.assertEqual(1, dao.count_published_comments("/post1"))
|
assert 1 == dao.count_published_comments("/post1")
|
||||||
self.assertEqual(2, dao.count_published_comments("/post2"))
|
assert 2 == dao.count_published_comments("/post2")
|
||||||
|
|
||||||
# test find published
|
# test find published
|
||||||
self.assertEqual(0, len(dao.find_published_comments_by_url("/")))
|
assert 0 == len(dao.find_published_comments_by_url("/"))
|
||||||
self.assertEqual(1, len(dao.find_published_comments_by_url("/post1")))
|
assert 1 == len(dao.find_published_comments_by_url("/post1"))
|
||||||
self.assertEqual(2, len(dao.find_published_comments_by_url("/post2")))
|
assert 2 == len(dao.find_published_comments_by_url("/post2"))
|
||||||
|
|
||||||
dao.delete_comment(c1)
|
dao.delete_comment(c1)
|
||||||
self.assertEqual(0, len(dao.find_published_comments_by_url("/post1")))
|
assert 0 == len(dao.find_published_comments_by_url("/post1"))
|
||||||
|
|
||||||
def test_dao_notified(self):
|
def test_dao_notified(setup_db):
|
||||||
|
|
||||||
# test count notified
|
# test count notified
|
||||||
self.assertEqual(0, len(dao.find_not_notified_comments()))
|
assert 0 == len(dao.find_not_notified_comments())
|
||||||
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1")
|
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1")
|
||||||
self.assertEqual(1, len(dao.find_not_notified_comments()))
|
assert 1 == len(dao.find_not_notified_comments())
|
||||||
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2")
|
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2")
|
||||||
self.assertEqual(2, len(dao.find_not_notified_comments()))
|
assert 2 == len(dao.find_not_notified_comments())
|
||||||
dao.notify_comment(c1)
|
dao.notify_comment(c1)
|
||||||
dao.notify_comment(c2)
|
dao.notify_comment(c2)
|
||||||
self.assertEqual(0, len(dao.find_not_notified_comments()))
|
assert 0 == len(dao.find_not_notified_comments())
|
||||||
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3")
|
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3")
|
||||||
self.assertEqual(1, len(dao.find_not_notified_comments()))
|
assert 1 == len(dao.find_not_notified_comments())
|
||||||
dao.notify_comment(c3)
|
dao.notify_comment(c3)
|
||||||
self.assertEqual(0, len(dao.find_not_notified_comments()))
|
assert 0 == len(dao.find_not_notified_comments())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue