replace pytest by unittest
This commit is contained in:
parent
92e6a8965d
commit
3905ef4bbd
4 changed files with 107 additions and 86 deletions
|
@ -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()
|
|
||||||
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 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):
|
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):
|
||||||
|
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):
|
def test_put(self):
|
||||||
assert conf is not None
|
conf = self.conf()
|
||||||
assert conf.get(ConfigParameter.DB_SQLITE_FILE) == EXPECTED_DB_SQLITE_FILE
|
self.assertFalse(conf.exists(ConfigParameter.IMAP_LOGIN))
|
||||||
assert conf.get(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
|
conf.put(ConfigParameter.IMAP_LOGIN, EXPECTED_IMAP_LOGIN)
|
||||||
assert conf.get(ConfigParameter.HTTP_HOST) is None
|
self.assertTrue(conf.exists(ConfigParameter.IMAP_LOGIN))
|
||||||
assert conf.get(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
|
self.assertEqual(conf.get(ConfigParameter.IMAP_LOGIN), EXPECTED_IMAP_LOGIN)
|
||||||
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
|
|
||||||
|
|
22
tests/test_form.py
Normal file
22
tests/test_form.py
Normal file
|
@ -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"))
|
|
||||||
templater = Templater(template_path)
|
|
||||||
template = templater.get_template(lang, template_name)
|
|
||||||
assert template
|
|
||||||
return template.render(kwargs)
|
|
||||||
|
|
||||||
|
def get_template_content(self, lang, template_name, **kwargs):
|
||||||
|
current_path = os.path.dirname(__file__)
|
||||||
|
template_path = os.path.abspath(os.path.join(current_path, "../stacosys/templates"))
|
||||||
|
template = Templater(template_path).get_template(lang, template_name)
|
||||||
|
return template.render(kwargs)
|
||||||
|
|
||||||
def test_approve_comment():
|
def test_approve_comment(self):
|
||||||
content = get_template_content("fr", Template.APPROVE_COMMENT, original="[texte]")
|
content = self.get_template_content("fr", Template.APPROVE_COMMENT, original="[texte]")
|
||||||
assert content.startswith("Bonjour,\n\nLe commentaire sera bientôt publié.")
|
self.assertTrue(content.startswith("Bonjour,\n\nLe commentaire sera bientôt publié."))
|
||||||
assert content.endswith("[texte]")
|
self.assertTrue(content.endswith("[texte]"))
|
||||||
content = get_template_content("en", Template.APPROVE_COMMENT, original="[texte]")
|
content = self.get_template_content("en", Template.APPROVE_COMMENT, original="[texte]")
|
||||||
assert content.startswith("Hi,\n\nThe comment should be published soon.")
|
self.assertTrue(content.startswith("Hi,\n\nThe comment should be published soon."))
|
||||||
assert content.endswith("[texte]")
|
self.assertTrue(content.endswith("[texte]"))
|
||||||
|
|
||||||
|
def test_drop_comment(self):
|
||||||
|
content = self.get_template_content("fr", Template.DROP_COMMENT, original="[texte]")
|
||||||
|
self.assertTrue(content.startswith("Bonjour,\n\nLe commentaire ne sera pas publié."))
|
||||||
|
self.assertTrue(content.endswith("[texte]"))
|
||||||
|
content = self.get_template_content("en", Template.DROP_COMMENT, original="[texte]")
|
||||||
|
self.assertTrue(content.startswith("Hi,\n\nThe comment will not be published."))
|
||||||
|
self.assertTrue(content.endswith("[texte]"))
|
||||||
|
|
||||||
def test_drop_comment():
|
def test_new_comment(self):
|
||||||
content = get_template_content("fr", Template.DROP_COMMENT, original="[texte]")
|
content = self.get_template_content("fr", Template.NEW_COMMENT, comment="[comment]")
|
||||||
assert content.startswith("Bonjour,\n\nLe commentaire ne sera pas publié.")
|
self.assertTrue(content.startswith("Bonjour,\n\nUn nouveau commentaire a été posté"))
|
||||||
assert content.endswith("[texte]")
|
self.assertTrue(content.endswith("[comment]\n\n--\nStacosys"))
|
||||||
content = get_template_content("en", Template.DROP_COMMENT, original="[texte]")
|
content = self.get_template_content("en", Template.NEW_COMMENT, comment="[comment]")
|
||||||
assert content.startswith("Hi,\n\nThe comment will not be published.")
|
self.assertTrue(content.startswith("Hi,\n\nA new comment has been submitted"))
|
||||||
assert content.endswith("[texte]")
|
self.assertTrue(content.endswith("[comment]\n\n--\nStacosys"))
|
||||||
|
|
||||||
|
def test_notify_message(self):
|
||||||
|
content = self.get_template_content("fr", Template.NOTIFY_MESSAGE)
|
||||||
|
self.assertEqual("Nouveau commentaire", content)
|
||||||
|
content = self.get_template_content("en", Template.NOTIFY_MESSAGE)
|
||||||
|
self.assertEqual("New comment", content)
|
||||||
|
|
||||||
def test_new_comment():
|
def test_rss_title(self):
|
||||||
content = get_template_content("fr", Template.NEW_COMMENT, comment="[comment]")
|
content = self.get_template_content("fr", Template.RSS_TITLE_MESSAGE, site="[site]")
|
||||||
assert content.startswith("Bonjour,\n\nUn nouveau commentaire a été posté")
|
self.assertEqual("[site] : commentaires", content)
|
||||||
assert content.endswith("[comment]\n\n--\nStacosys")
|
content = self.get_template_content("en", Template.RSS_TITLE_MESSAGE, site="[site]")
|
||||||
content = get_template_content("en", Template.NEW_COMMENT, comment="[comment]")
|
self.assertEqual("[site] : comments", content)
|
||||||
assert content.startswith("Hi,\n\nA new comment has been submitted")
|
|
||||||
assert content.endswith("[comment]\n\n--\nStacosys")
|
|
||||||
|
|
||||||
|
|
||||||
def test_notify_message():
|
|
||||||
content = get_template_content("fr", Template.NOTIFY_MESSAGE)
|
|
||||||
assert content == "Nouveau commentaire"
|
|
||||||
content = get_template_content("en", Template.NOTIFY_MESSAGE)
|
|
||||||
assert content == "New comment"
|
|
||||||
|
|
||||||
|
|
||||||
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…
Add table
Reference in a new issue