Merge pull request #11 from kianby/feature-coverage

Feature coverage
This commit is contained in:
Yax 2022-12-02 09:02:08 +01:00 committed by GitHub
commit c9238330e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 3032 additions and 5548 deletions

View file

@ -1,8 +1,8 @@
all: black test typehint lint all: black test typehint lint
black: black:
poetry run isort --multi-line 3 --profile black stacosys/ poetry run isort --multi-line 3 --profile black stacosys/ tests/
poetry run black stacosys/ poetry run black --target-version py311 stacosys/ tests/
test: test:
poetry run coverage run -m --source=stacosys pytest poetry run coverage run -m --source=stacosys pytest

75
poetry.lock generated
View file

@ -136,35 +136,6 @@ category = "dev"
optional = false optional = false
python-versions = "*" python-versions = "*"
[[package]]
name = "flake8"
version = "6.0.0"
description = "the modular source code checker: pep8 pyflakes and co"
category = "dev"
optional = false
python-versions = ">=3.8.1"
[package.dependencies]
mccabe = ">=0.7.0,<0.8.0"
pycodestyle = ">=2.10.0,<2.11.0"
pyflakes = ">=3.0.0,<3.1.0"
[[package]]
name = "flake8-black"
version = "0.3.5"
description = "flake8 plugin to call black as a code style validator"
category = "dev"
optional = false
python-versions = ">=3.7"
[package.dependencies]
black = ">=22.1.0"
flake8 = ">=3"
tomli = "*"
[package.extras]
develop = ["build", "twine"]
[[package]] [[package]]
name = "flask" name = "flask"
version = "2.2.2" version = "2.2.2"
@ -339,14 +310,6 @@ python-versions = ">=3.6"
dev = ["pre-commit", "tox"] dev = ["pre-commit", "tox"]
testing = ["pytest", "pytest-benchmark"] testing = ["pytest", "pytest-benchmark"]
[[package]]
name = "pycodestyle"
version = "2.10.0"
description = "Python style guide checker"
category = "dev"
optional = false
python-versions = ">=3.6"
[[package]] [[package]]
name = "pydal" name = "pydal"
version = "20221110.1" version = "20221110.1"
@ -355,14 +318,6 @@ category = "main"
optional = false optional = false
python-versions = "*" python-versions = "*"
[[package]]
name = "pyflakes"
version = "3.0.1"
description = "passive checker of Python programs"
category = "dev"
optional = false
python-versions = ">=3.6"
[[package]] [[package]]
name = "pylint" name = "pylint"
version = "2.15.7" version = "2.15.7"
@ -454,14 +409,6 @@ urllib3 = ">=1.21.1,<1.27"
socks = ["PySocks (>=1.5.6,!=1.5.7)"] socks = ["PySocks (>=1.5.6,!=1.5.7)"]
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
[[package]]
name = "tomli"
version = "2.0.1"
description = "A lil' TOML parser"
category = "dev"
optional = false
python-versions = ">=3.7"
[[package]] [[package]]
name = "tomlkit" name = "tomlkit"
version = "0.11.6" version = "0.11.6"
@ -524,7 +471,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "~3.11" python-versions = "~3.11"
content-hash = "eae5d8539c8fd2e80b005124c5439a61310128f7427bdc20affa92dec85085ee" content-hash = "7ee7b17fa42c245160e4e376453b3d6cea354551dd40342ee57d59b6d71ea31d"
[metadata.files] [metadata.files]
astroid = [ astroid = [
@ -641,14 +588,6 @@ dill = [
docopt = [ docopt = [
{file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"},
] ]
flake8 = [
{file = "flake8-6.0.0-py2.py3-none-any.whl", hash = "sha256:3833794e27ff64ea4e9cf5d410082a8b97ff1a06c16aa3d2027339cd0f1195c7"},
{file = "flake8-6.0.0.tar.gz", hash = "sha256:c61007e76655af75e6785a931f452915b371dc48f56efd765247c8fe68f2b181"},
]
flake8-black = [
{file = "flake8-black-0.3.5.tar.gz", hash = "sha256:9e93252b1314a8eb3c2f55dec54a07239e502b12f57567f2c105f2202714b15e"},
{file = "flake8_black-0.3.5-py3-none-any.whl", hash = "sha256:4948a579fdddd98fbf935fd94255dfcfce560c4ddc1ceee08e3f12d6114c8619"},
]
flask = [ flask = [
{file = "Flask-2.2.2-py3-none-any.whl", hash = "sha256:b9c46cc36662a7949f34b52d8ec7bb59c0d74ba08ba6cb9ce9adc1d8676d9526"}, {file = "Flask-2.2.2-py3-none-any.whl", hash = "sha256:b9c46cc36662a7949f34b52d8ec7bb59c0d74ba08ba6cb9ce9adc1d8676d9526"},
{file = "Flask-2.2.2.tar.gz", hash = "sha256:642c450d19c4ad482f96729bd2a8f6d32554aa1e231f4f6b4e7e5264b16cca2b"}, {file = "Flask-2.2.2.tar.gz", hash = "sha256:642c450d19c4ad482f96729bd2a8f6d32554aa1e231f4f6b4e7e5264b16cca2b"},
@ -796,17 +735,9 @@ pluggy = [
{file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"},
{file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"},
] ]
pycodestyle = [
{file = "pycodestyle-2.10.0-py2.py3-none-any.whl", hash = "sha256:8a4eaf0d0495c7395bdab3589ac2db602797d76207242c17d470186815706610"},
{file = "pycodestyle-2.10.0.tar.gz", hash = "sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053"},
]
pydal = [ pydal = [
{file = "pydal-20221110.1.tar.gz", hash = "sha256:7c3e891c70f8d8918e36276f210a1959bb7badf3b276f47191986ffcf5b6a390"}, {file = "pydal-20221110.1.tar.gz", hash = "sha256:7c3e891c70f8d8918e36276f210a1959bb7badf3b276f47191986ffcf5b6a390"},
] ]
pyflakes = [
{file = "pyflakes-3.0.1-py2.py3-none-any.whl", hash = "sha256:ec55bf7fe21fff7f1ad2f7da62363d749e2a470500eab1b555334b67aa1ef8cf"},
{file = "pyflakes-3.0.1.tar.gz", hash = "sha256:ec8b276a6b60bd80defed25add7e439881c19e64850afd9b346283d4165fd0fd"},
]
pylint = [ pylint = [
{file = "pylint-2.15.7-py3-none-any.whl", hash = "sha256:1d561d1d3e8be9dd880edc685162fbdaa0409c88b9b7400873c0cf345602e326"}, {file = "pylint-2.15.7-py3-none-any.whl", hash = "sha256:1d561d1d3e8be9dd880edc685162fbdaa0409c88b9b7400873c0cf345602e326"},
{file = "pylint-2.15.7.tar.gz", hash = "sha256:91e4776dbcb4b4d921a3e4b6fec669551107ba11f29d9199154a01622e460a57"}, {file = "pylint-2.15.7.tar.gz", hash = "sha256:91e4776dbcb4b4d921a3e4b6fec669551107ba11f29d9199154a01622e460a57"},
@ -830,10 +761,6 @@ requests = [
{file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"},
{file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"},
] ]
tomli = [
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
]
tomlkit = [ tomlkit = [
{file = "tomlkit-0.11.6-py3-none-any.whl", hash = "sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b"}, {file = "tomlkit-0.11.6-py3-none-any.whl", hash = "sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b"},
{file = "tomlkit-0.11.6.tar.gz", hash = "sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73"}, {file = "tomlkit-0.11.6.tar.gz", hash = "sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73"},

View file

@ -4,7 +4,6 @@ version = "3.3"
description = "STAtic COmmenting SYStem" description = "STAtic COmmenting SYStem"
authors = ["Yax"] authors = ["Yax"]
readme = "README.md" readme = "README.md"
include = ["run.py"]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "~3.11" python = "~3.11"
@ -22,8 +21,8 @@ pylint = "^2.15"
mypy = "^0.991" mypy = "^0.991"
pytest = "^7.2.0" pytest = "^7.2.0"
coveralls = "^3.3.1" coveralls = "^3.3.1"
flake8-black = "^0.3.4"
pytest-cov = "^4.0.0" pytest-cov = "^4.0.0"
black = "^22.10.0"
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]

File diff suppressed because it is too large Load diff

View file

@ -33,11 +33,6 @@ class Config:
_cfg = configparser.ConfigParser() _cfg = configparser.ConfigParser()
# def __new__(cls):
# if not hasattr(cls, "instance"):
# cls.instance = super(Config, cls).__new__(cls)
# return cls.instance
def load(self, config_pathname): def load(self, config_pathname):
self._cfg.read(config_pathname) self._cfg.read(config_pathname)

View file

@ -6,9 +6,8 @@ import logging
import pytest import pytest
from stacosys.db import database, dao from stacosys.db import dao, database
from stacosys.interface import api from stacosys.interface import api, app
from stacosys.interface import app
def init_test_db(): def init_test_db():

View file

@ -6,29 +6,42 @@ import pytest
from stacosys.service import config from stacosys.service import config
from stacosys.service.configuration import ConfigParameter from stacosys.service.configuration import ConfigParameter
EXPECTED_DB_SQLITE_FILE = "sqlite://db.sqlite" EXPECTED_DB = "sqlite://db.sqlite"
EXPECTED_HTTP_PORT = 8080 EXPECTED_HTTP_PORT = 8080
EXPECTED_LANG = "fr" EXPECTED_LANG = "fr"
@pytest.fixture @pytest.fixture
def init_config(): def init_config():
config.put(ConfigParameter.DB, EXPECTED_DB_SQLITE_FILE) config.put(ConfigParameter.DB, EXPECTED_DB)
config.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT) config.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
def test_split_key():
section, param = config._split_key(ConfigParameter.HTTP_PORT)
assert section == "http" and param == "port"
def test_exists(init_config): def test_exists(init_config):
assert config.exists(ConfigParameter.DB) assert config.exists(ConfigParameter.DB)
def test_get(init_config): def test_get(init_config):
assert config.get(ConfigParameter.DB) == EXPECTED_DB_SQLITE_FILE assert config.get(ConfigParameter.DB) == EXPECTED_DB
assert config.get(ConfigParameter.HTTP_HOST) == "" assert config.get(ConfigParameter.HTTP_HOST) == ""
assert config.get(ConfigParameter.HTTP_PORT) == str(EXPECTED_HTTP_PORT) assert config.get(ConfigParameter.HTTP_PORT) == str(EXPECTED_HTTP_PORT)
assert config.get_int(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT assert config.get_int(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
config.get_bool(ConfigParameter.DB) config.get_bool(ConfigParameter.DB)
def test_put(init_config): def test_put(init_config):
assert not config.exists(ConfigParameter.LANG) assert not config.exists(ConfigParameter.LANG)
config.put(ConfigParameter.LANG, EXPECTED_LANG) config.put(ConfigParameter.LANG, EXPECTED_LANG)
assert config.exists(ConfigParameter.LANG) assert config.exists(ConfigParameter.LANG)
assert config.get(ConfigParameter.LANG) == EXPECTED_LANG assert config.get(ConfigParameter.LANG) == EXPECTED_LANG
def test_check(init_config):
success, error = config.check()
assert not success and error

View file

@ -1,22 +1,48 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import time
import pytest import pytest
from stacosys.db import dao from stacosys.db import dao, database
from stacosys.db import database from stacosys.model.comment import Comment
@pytest.fixture @pytest.fixture
def setup_db(): def setup_db():
database.configure("sqlite:memory://db.sqlite") database.configure("sqlite:memory://db.sqlite")
def test_dao_published(setup_db): def equals_comment(comment: Comment, other):
return (
comment.id == other.id
and comment.author_gravatar == other.author_gravatar
and comment.author_name == other.author_name
and comment.author_site == other.author_site
and comment.content == other.content
and comment.created == other.created
and comment.notified == other.notified
and comment.published == other.published
)
# test count published
def test_find_comment_by_id(setup_db):
assert dao.find_comment_by_id(1) is None
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1")
assert c1.id is not None
find_c1 = dao.find_comment_by_id(c1.id)
assert find_c1
assert equals_comment(c1, find_c1)
c1.id = find_c1.id
dao.delete_comment(c1)
assert dao.find_comment_by_id(c1.id) is None
def test_dao_published(setup_db):
assert 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")
assert 0 == dao.count_published_comments("") assert 0 == dao.count_published_comments("")
assert 1 == len(dao.find_not_published_comments())
dao.publish_comment(c1) dao.publish_comment(c1)
assert 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")
@ -24,20 +50,19 @@ def test_dao_published(setup_db):
assert 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)
assert 0 == len(dao.find_not_published_comments())
# count published
assert 1 == dao.count_published_comments("/post1") assert 1 == dao.count_published_comments("/post1")
assert 2 == dao.count_published_comments("/post2") assert 2 == dao.count_published_comments("/post2")
# test find published # find published
assert 0 == len(dao.find_published_comments_by_url("/")) assert 0 == len(dao.find_published_comments_by_url("/"))
assert 1 == len(dao.find_published_comments_by_url("/post1")) assert 1 == len(dao.find_published_comments_by_url("/post1"))
assert 2 == len(dao.find_published_comments_by_url("/post2")) assert 2 == len(dao.find_published_comments_by_url("/post2"))
dao.delete_comment(c1)
assert 0 == len(dao.find_published_comments_by_url("/post1"))
def test_dao_notified(setup_db): def test_dao_notified(setup_db):
# test count notified
assert 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")
assert 1 == len(dao.find_not_notified_comments()) assert 1 == len(dao.find_not_notified_comments())
@ -51,3 +76,48 @@ def test_dao_notified(setup_db):
dao.notify_comment(c3) dao.notify_comment(c3)
assert 0 == len(dao.find_not_notified_comments()) assert 0 == len(dao.find_not_notified_comments())
def create_comment(url, author_name, content):
return dao.create_comment(url, author_name, "", "", content)
def test_find_recent_published_comments(setup_db):
comments = []
comments.append(create_comment("/post", "Adam", "Comment 1"))
comments.append(create_comment("/post", "Arf", "Comment 2"))
comments.append(create_comment("/post", "Arwin", "Comment 3"))
comments.append(create_comment("/post", "Bill", "Comment 4"))
comments.append(create_comment("/post", "Bo", "Comment 5"))
comments.append(create_comment("/post", "Charles", "Comment 6"))
comments.append(create_comment("/post", "Dan", "Comment 7"))
comments.append(create_comment("/post", "Dwayne", "Comment 8"))
comments.append(create_comment("/post", "Erl", "Comment 9"))
comments.append(create_comment("/post", "Jay", "Comment 10"))
comments.append(create_comment("/post", "Kenny", "Comment 11"))
comments.append(create_comment("/post", "Lord", "Comment 12"))
rows = dao.find_recent_published_comments()
assert len(rows) == 0
# publish every second
for comment in comments:
dao.publish_comment(comment)
time.sleep(1)
rows = dao.find_recent_published_comments()
assert len(rows) == 10
authors = [row.author_name for row in rows]
assert authors == [
"Lord",
"Kenny",
"Jay",
"Erl",
"Dwayne",
"Dan",
"Charles",
"Bo",
"Bill",
"Arwin",
]

View file

@ -6,8 +6,7 @@ import logging
import pytest import pytest
from stacosys.db import database from stacosys.db import database
from stacosys.interface import app from stacosys.interface import app, form
from stacosys.interface import form
@pytest.fixture @pytest.fixture

View file

@ -2,8 +2,10 @@
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import pytest import pytest
from stacosys.service import mailer from stacosys.service import mailer
def test_configure_and_check(): def test_configure_and_check():
mailer.configure_smtp("localhost", 2525, "admin", "admin") mailer.configure_smtp("localhost", 2525, "admin", "admin")
mailer.configure_destination("admin@mydomain.com") mailer.configure_destination("admin@mydomain.com")

View file

@ -3,5 +3,6 @@
from stacosys.service import rss from stacosys.service import rss
def test_configure(): def test_configure():
rss.configure("comments.xml", "blog", "http", "blog.mydomain.com") rss.configure("comments.xml", "blog", "http", "blog.mydomain.com")