replace pytest by unittest

pull/6/head
Yax 3 years ago
parent bf1447a3a9
commit 3eb1b86246

@ -1,7 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import pytest import unittest
from stacosys.conf.config import Config, ConfigParameter from stacosys.conf.config import Config, ConfigParameter
EXPECTED_DB_SQLITE_FILE = "db.sqlite" EXPECTED_DB_SQLITE_FILE = "db.sqlite"
@ -10,48 +11,46 @@ EXPECTED_IMAP_PORT = "5000"
EXPECTED_IMAP_LOGIN = "user" EXPECTED_IMAP_LOGIN = "user"
@pytest.fixture class ConfigTestCase(unittest.TestCase):
def conf():
conf = Config() def conf(self):
conf.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE) conf = Config()
conf.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT) conf.put(ConfigParameter.DB_SQLITE_FILE, EXPECTED_DB_SQLITE_FILE)
conf.put(ConfigParameter.IMAP_PORT, EXPECTED_IMAP_PORT) conf.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
conf.put(ConfigParameter.SMTP_STARTTLS, "yes") conf.put(ConfigParameter.IMAP_PORT, EXPECTED_IMAP_PORT)
conf.put(ConfigParameter.IMAP_SSL, "false") conf.put(ConfigParameter.SMTP_STARTTLS, "yes")
return conf conf.put(ConfigParameter.IMAP_SSL, "false")
return conf
def test_exists(conf): def test_exists(self):
assert conf is not None conf = self.conf()
assert conf.exists(ConfigParameter.DB_SQLITE_FILE) self.assertTrue(conf.exists(ConfigParameter.DB_SQLITE_FILE))
assert not conf.exists(ConfigParameter.IMAP_HOST) self.assertFalse(conf.exists(ConfigParameter.IMAP_HOST))
def test_get(self):
def test_get(conf): conf = self.conf()
assert conf is not None self.assertEqual(conf.get(ConfigParameter.DB_SQLITE_FILE), EXPECTED_DB_SQLITE_FILE)
assert conf.get(ConfigParameter.DB_SQLITE_FILE) == EXPECTED_DB_SQLITE_FILE self.assertEqual(conf.get(ConfigParameter.HTTP_PORT), EXPECTED_HTTP_PORT)
assert conf.get(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT self.assertIsNone(conf.get(ConfigParameter.HTTP_HOST))
assert conf.get(ConfigParameter.HTTP_HOST) is None self.assertEqual(conf.get(ConfigParameter.HTTP_PORT), EXPECTED_HTTP_PORT)
assert conf.get(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT self.assertEqual(conf.get(ConfigParameter.IMAP_PORT), EXPECTED_IMAP_PORT)
assert conf.get(ConfigParameter.IMAP_PORT) == EXPECTED_IMAP_PORT self.assertEqual(conf.get_int(ConfigParameter.IMAP_PORT), int(EXPECTED_IMAP_PORT))
assert conf.get_int(ConfigParameter.IMAP_PORT) == int(EXPECTED_IMAP_PORT) try:
try: conf.get_int(ConfigParameter.HTTP_PORT)
conf.get_int(ConfigParameter.HTTP_PORT) self.assertTrue(False)
assert False except Exception:
except Exception: pass
pass self.assertTrue(conf.get_bool(ConfigParameter.SMTP_STARTTLS))
assert conf.get_bool(ConfigParameter.SMTP_STARTTLS) self.assertFalse(conf.get_bool(ConfigParameter.IMAP_SSL))
assert not conf.get_bool(ConfigParameter.IMAP_SSL) try:
try: conf.get_bool(ConfigParameter.DB_URL)
conf.get_bool(ConfigParameter.DB_URL) self.assertTrue(False)
assert False except Exception:
except Exception: pass
pass
def test_put(self):
conf = self.conf()
def test_put(conf): self.assertFalse(conf.exists(ConfigParameter.IMAP_LOGIN))
assert conf is not None conf.put(ConfigParameter.IMAP_LOGIN, EXPECTED_IMAP_LOGIN)
assert not conf.exists(ConfigParameter.IMAP_LOGIN) self.assertTrue(conf.exists(ConfigParameter.IMAP_LOGIN))
conf.put(ConfigParameter.IMAP_LOGIN, EXPECTED_IMAP_LOGIN) self.assertEqual(conf.get(ConfigParameter.IMAP_LOGIN), EXPECTED_IMAP_LOGIN)
assert conf.exists(ConfigParameter.IMAP_LOGIN)
assert conf.get(ConfigParameter.IMAP_LOGIN) == EXPECTED_IMAP_LOGIN

@ -0,0 +1,22 @@
import unittest
from stacosys.interface import form
class FormInterfaceTestCase(unittest.TestCase):
def test_check_form_data_ok(self):
d = {"url": "/", "message": "", "site": "", "remarque": "", "author": "", "token": "", "email": ""}
self.assertTrue(form.check_form_data(d))
d = {"url": "/"}
self.assertTrue(form.check_form_data(d))
d = {}
self.assertTrue(form.check_form_data(d))
def test_check_form_data_ko(self):
d = {"url": "/", "message": "", "site": "", "remarque": "", "author": "", "token": "", "email": "", "bonus": ""}
self.assertFalse(form.check_form_data(d))
if __name__ == '__main__':
unittest.main()

@ -1,5 +1,9 @@
import unittest
from stacosys import __version__ from stacosys import __version__
def test_version(): class StacosysTestCase(unittest.TestCase):
assert __version__ == "2.0"
def test_version(self):
self.assertEqual("2.0", __version__)

@ -2,55 +2,51 @@
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import os import os
import unittest
from stacosys.core.templater import Templater, Template from stacosys.core.templater import Templater, Template
def get_template_content(lang, template_name, **kwargs): class TemplateTestCase(unittest.TestCase):
current_path = os.path.dirname(__file__)
template_path = os.path.abspath(os.path.join(current_path, "../stacosys/templates")) def get_template_content(self, lang, template_name, **kwargs):
templater = Templater(template_path) current_path = os.path.dirname(__file__)
template = templater.get_template(lang, template_name) template_path = os.path.abspath(os.path.join(current_path, "../stacosys/templates"))
assert template template = Templater(template_path).get_template(lang, template_name)
return template.render(kwargs) return template.render(kwargs)
def test_approve_comment(self):
def test_approve_comment(): content = self.get_template_content("fr", Template.APPROVE_COMMENT, original="[texte]")
content = get_template_content("fr", Template.APPROVE_COMMENT, original="[texte]") self.assertTrue(content.startswith("Bonjour,\n\nLe commentaire sera bientôt publié."))
assert content.startswith("Bonjour,\n\nLe commentaire sera bientôt publié.") self.assertTrue(content.endswith("[texte]"))
assert content.endswith("[texte]") content = self.get_template_content("en", Template.APPROVE_COMMENT, original="[texte]")
content = get_template_content("en", Template.APPROVE_COMMENT, original="[texte]") self.assertTrue(content.startswith("Hi,\n\nThe comment should be published soon."))
assert content.startswith("Hi,\n\nThe comment should be published soon.") self.assertTrue(content.endswith("[texte]"))
assert content.endswith("[texte]")
def test_drop_comment(self):
content = self.get_template_content("fr", Template.DROP_COMMENT, original="[texte]")
def test_drop_comment(): self.assertTrue(content.startswith("Bonjour,\n\nLe commentaire ne sera pas publié."))
content = get_template_content("fr", Template.DROP_COMMENT, original="[texte]") self.assertTrue(content.endswith("[texte]"))
assert content.startswith("Bonjour,\n\nLe commentaire ne sera pas publié.") content = self.get_template_content("en", Template.DROP_COMMENT, original="[texte]")
assert content.endswith("[texte]") self.assertTrue(content.startswith("Hi,\n\nThe comment will not be published."))
content = get_template_content("en", Template.DROP_COMMENT, original="[texte]") self.assertTrue(content.endswith("[texte]"))
assert content.startswith("Hi,\n\nThe comment will not be published.")
assert content.endswith("[texte]") def test_new_comment(self):
content = self.get_template_content("fr", Template.NEW_COMMENT, comment="[comment]")
self.assertTrue(content.startswith("Bonjour,\n\nUn nouveau commentaire a été posté"))
def test_new_comment(): self.assertTrue(content.endswith("[comment]\n\n--\nStacosys"))
content = get_template_content("fr", Template.NEW_COMMENT, comment="[comment]") content = self.get_template_content("en", Template.NEW_COMMENT, comment="[comment]")
assert content.startswith("Bonjour,\n\nUn nouveau commentaire a été posté") self.assertTrue(content.startswith("Hi,\n\nA new comment has been submitted"))
assert content.endswith("[comment]\n\n--\nStacosys") self.assertTrue(content.endswith("[comment]\n\n--\nStacosys"))
content = get_template_content("en", Template.NEW_COMMENT, comment="[comment]")
assert content.startswith("Hi,\n\nA new comment has been submitted") def test_notify_message(self):
assert content.endswith("[comment]\n\n--\nStacosys") content = self.get_template_content("fr", Template.NOTIFY_MESSAGE)
self.assertEqual("Nouveau commentaire", content)
content = self.get_template_content("en", Template.NOTIFY_MESSAGE)
def test_notify_message(): self.assertEqual("New comment", content)
content = get_template_content("fr", Template.NOTIFY_MESSAGE)
assert content == "Nouveau commentaire" def test_rss_title(self):
content = get_template_content("en", Template.NOTIFY_MESSAGE) content = self.get_template_content("fr", Template.RSS_TITLE_MESSAGE, site="[site]")
assert content == "New comment" self.assertEqual("[site] : commentaires", content)
content = self.get_template_content("en", Template.RSS_TITLE_MESSAGE, site="[site]")
self.assertEqual("[site] : comments", content)
def test_rss_title():
content = get_template_content("fr", Template.RSS_TITLE_MESSAGE, site="[site]")
assert content == "[site] : commentaires"
content = get_template_content("en", Template.RSS_TITLE_MESSAGE, site="[site]")
assert content == "[site] : comments"

Loading…
Cancel
Save