First stab at testing
See https://git.autonomic.zone/decentral1se/xbotlib/issues/6.
This commit is contained in:
parent
30a6cbe806
commit
0c5f6b7016
15
.drone.yml
15
.drone.yml
|
@ -1,12 +1,27 @@
|
|||
---
|
||||
matrix:
|
||||
include:
|
||||
- IMAGE: 3.6-stretch
|
||||
TOXENV: py36
|
||||
|
||||
- IMAGE: 3.7-stretch
|
||||
TOXENV: py37
|
||||
|
||||
- IMAGE: 3.8-buster
|
||||
TOXENV: py38
|
||||
|
||||
- IMAGE: 3.9-buster
|
||||
TOXENV: py39
|
||||
|
||||
- IMAGE: 3.9-buster
|
||||
TOXENV: lint
|
||||
|
||||
- IMAGE: 3.9-buster
|
||||
TOXENV: sort
|
||||
|
||||
- IMAGE: 3.9-buster
|
||||
TOXENV: format
|
||||
|
||||
- IMAGE: 3.9-buster
|
||||
TOXENV: type
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ skip = ".tox"
|
|||
legacy_tox_ini = """
|
||||
[tox]
|
||||
envlist =
|
||||
{py36,py37,py38}
|
||||
{py36,py37,py38,py39}
|
||||
lint
|
||||
sort
|
||||
format
|
||||
|
@ -60,25 +60,25 @@ deps =
|
|||
pytest
|
||||
pytest-cov
|
||||
pytest-mock
|
||||
commands = pytest test.py --cov={toxinidir}/xbotlib.py --no-cov-on-fail {posargs}
|
||||
commands = pytest test_xbotlib.py --cov=xbotlib --no-cov-on-fail {posargs}
|
||||
|
||||
[testenv:lint]
|
||||
skipdist = True
|
||||
deps = flake8
|
||||
commands = flake8 {posargs:--max-line-length 80} xbotlib.py
|
||||
commands = flake8 {posargs:--max-line-length 80} xbotlib.py test_xbotlib.py
|
||||
|
||||
[testenv:sort]
|
||||
skipdist = True
|
||||
deps = isort
|
||||
commands = isort {posargs:-c} xbotlib.py
|
||||
commands = isort {posargs:-c} xbotlib.py test_xbotlib.py
|
||||
|
||||
[testenv:format]
|
||||
skipdist = True
|
||||
deps = black
|
||||
commands = black {posargs:--check} xbotlib.py
|
||||
commands = black {posargs:--check} xbotlib.py test_xbotlib.py
|
||||
|
||||
[testenv:type]
|
||||
skipdist = True
|
||||
deps = mypy
|
||||
commands = mypy {posargs:--ignore-missing-imports} xbotlib.py
|
||||
commands = mypy {posargs:--ignore-missing-imports} xbotlib.py test_xbotlib.py
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
"""Unit tests for xbotlib module."""
|
||||
|
||||
from pytest import fixture
|
||||
|
||||
from xbotlib import Config, SimpleMessage
|
||||
|
||||
|
||||
@fixture
|
||||
def message():
|
||||
class MockFrom:
|
||||
@property
|
||||
def bare(self):
|
||||
return "foo@muc.vvvvvvaria.org"
|
||||
|
||||
return {
|
||||
"body": "mockbot: foobar",
|
||||
"from": MockFrom(),
|
||||
"to": "other_tester",
|
||||
"type": "chat",
|
||||
"mucnick": "mockbot",
|
||||
"oob": {"url": "https://foo.com"},
|
||||
}
|
||||
|
||||
|
||||
@fixture
|
||||
def bot():
|
||||
class MockBot:
|
||||
@property
|
||||
def nick(self):
|
||||
return "mockbot"
|
||||
|
||||
@property
|
||||
def log(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
return MockBot()
|
||||
|
||||
|
||||
@fixture
|
||||
def config():
|
||||
return Config(
|
||||
"test",
|
||||
{
|
||||
"test": {
|
||||
"account": "foo@vvvvvvaria.org",
|
||||
"password": "SecretPasswordZ",
|
||||
"nick": "foo",
|
||||
"avatar": "avatar.png",
|
||||
"redis_url": "redis://localhost:6379/0",
|
||||
"rooms": "foo, bar, baz",
|
||||
"no_auto_join": True,
|
||||
"port": 8080,
|
||||
"template": "index.html.j2",
|
||||
"serve": True,
|
||||
"storage": "file",
|
||||
"storage_file": "foo.json",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_simple_message(message, bot):
|
||||
sm = SimpleMessage(message, bot)
|
||||
assert sm.message == message
|
||||
assert sm.bot == bot
|
||||
assert sm.text == "mockbot: foobar"
|
||||
assert sm.content == "foobar"
|
||||
# TODO*decentral1se): how to test test this?
|
||||
# assert sm.sender == "tester"
|
||||
assert sm.room == "foo@muc.vvvvvvaria.org"
|
||||
assert sm.receiver == "other_tester"
|
||||
assert sm.type == "chat"
|
||||
assert sm.nick == "mockbot"
|
||||
assert sm.url == "https://foo.com"
|
||||
|
||||
|
||||
def test_empty_config():
|
||||
config = Config("test", {})
|
||||
assert config.account is None
|
||||
|
||||
|
||||
def test_config(config):
|
||||
assert config.account == "foo@vvvvvvaria.org"
|
||||
assert config.password == "SecretPasswordZ"
|
||||
assert config.nick == "foo"
|
||||
assert config.avatar == "avatar.png"
|
||||
assert config.redis_url == "redis://localhost:6379/0"
|
||||
assert config.rooms == ["foo", "bar", "baz"]
|
||||
assert config.no_auto_join
|
||||
assert config.port == 8080
|
||||
assert config.template == "index.html.j2"
|
||||
assert config.serve
|
||||
assert config.storage == "file"
|
||||
assert config.storage_file == "foo.json"
|
Loading…
Reference in New Issue