-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Started unit testing with tox/pytest
Include system test TODO: Needs more tests (coverage at 12% now)
- Loading branch information
1 parent
54468f2
commit c2520ea
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[paths] | ||
source = | ||
src | ||
*/site-packages | ||
|
||
[run] | ||
branch = true | ||
parallel = true | ||
source = | ||
dnstemple | ||
|
||
[report] | ||
show_missing = true | ||
precision = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ __pycache__/ | |
build/ | ||
dist/ | ||
.idea | ||
.tox/ | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from mock import patch, call | ||
import time | ||
|
||
import dnstemple | ||
|
||
|
||
@patch('dnstemple.time.gmtime') | ||
def test_today(mock_gmtime): | ||
mock_gmtime.return_value = (2021, 11, 18, 11, 21, 17, 4, 322, False) | ||
assert dnstemple.soa_serial_for_today() == 2021111800 | ||
|
||
|
||
@patch('dnstemple.time.time') | ||
def test_now(mock_time): | ||
mock_time.return_value = 1637231137 | ||
assert dnstemple.soa_serial_for_now() == 1637231137 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from mock import patch, call, mock_open | ||
|
||
import dnstemple | ||
|
||
|
||
@patch('builtins.open', new_callable=mock_open, read_data='../some/path') | ||
def test_config(mock_file): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from mock import patch, call | ||
from pytest import raises | ||
|
||
import dnstemple | ||
|
||
|
||
def test_expand_none(): | ||
assert dnstemple.expand_variables( | ||
'a.zone', '@\tTXT\t"test"', {'variables': {}}) == '@\tTXT\t"test"' | ||
|
||
|
||
def test_expand_one(): | ||
assert dnstemple.expand_variables( | ||
'a.zone', '{one}\tTXT\t"test"', {'variables': {'one': 'eins'}}) == 'eins\tTXT\t"test"' | ||
|
||
|
||
def test_expand_two(): | ||
assert dnstemple.expand_variables( | ||
'a.zone', '{one}\tTXT\t"{two}"', {'variables': {'one': 'eins', 'two': 'zwei'}}) == 'eins\tTXT\t"zwei"' | ||
|
||
|
||
def test_expand_bad(): | ||
with raises(SystemExit, match=r'Unknown variable'): | ||
assert dnstemple.expand_variables( | ||
'a.zone', '{one}\tTXT\t"{three}"', {'variables': {'one': 'eins', 'two': 'zwei'}}) == 'eins\tTXT\t"zwei"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# tox (https://tox.readthedocs.io/) is a tool for running tests | ||
# in multiple virtualenvs. This configuration file will run the | ||
# test suite on all supported python versions. To use it, "pip install tox" | ||
# and then run "tox" from this directory. | ||
|
||
[tox] | ||
envlist = py36, py37, py38, py39, py310, pypy3, system | ||
isolated_build = True | ||
|
||
[testenv] | ||
deps = | ||
pytest | ||
mock | ||
importlib_metadata | ||
dnspython | ||
PyYAML | ||
commands = | ||
pytest | ||
|
||
[testenv:py39] | ||
deps = | ||
pytest | ||
pytest-cov | ||
mock | ||
importlib_metadata | ||
dnspython | ||
PyYAML | ||
commands = | ||
pytest --cov | ||
|
||
[testenv:system] | ||
deps = | ||
importlib_metadata | ||
dnspython | ||
PyYAML | ||
allowlist_externals = make | ||
commands = | ||
make test |