Reload
This commit is contained in:
parent
d3e990384d
commit
501f45525b
46 changed files with 993 additions and 35 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
5
tests/files/test1/test.mo.yaml
Normal file
5
tests/files/test1/test.mo.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
value: ${sample}
|
||||
nested: ${some.nested.value}
|
||||
custom: ${custom/field}
|
||||
uname: ${sample/username}
|
||||
invalid: ${double/slash/example}
|
||||
50
tests/test_mo.py
Normal file
50
tests/test_mo.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from app.services import Passwords
|
||||
from app.services.mo import Mo
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def target_path():
|
||||
p = Path('tests/files/test1/test.yaml')
|
||||
# posprzątaj przed testem, gdyby plik istniał z poprzednich uruchomień
|
||||
if p.exists():
|
||||
p.unlink()
|
||||
yield p
|
||||
# sprzątanie po teście
|
||||
if p.exists():
|
||||
p.unlink()
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def test1_content(target_path: Path):
|
||||
mo = Mo(Passwords())
|
||||
mo.process(Path('tests/files/test1/test.mo.yaml').absolute())
|
||||
|
||||
assert target_path.exists()
|
||||
|
||||
content = target_path.read_text()
|
||||
assert '${' not in content
|
||||
|
||||
yield yaml.load(content, Loader=yaml.FullLoader)
|
||||
|
||||
|
||||
class TestParsing:
|
||||
|
||||
def test_simple(self, test1_content: dict):
|
||||
assert test1_content['value'] == 'some_pass'
|
||||
|
||||
def test_nested(self, test1_content: dict):
|
||||
assert test1_content['nested'] == 'nested_pass'
|
||||
|
||||
def test_custom_field(self, test1_content: dict):
|
||||
assert test1_content['custom'] == 'custom_content'
|
||||
|
||||
def test_username_field(self, test1_content: dict):
|
||||
assert test1_content['uname'] == 'sample_username'
|
||||
|
||||
def test_invalid_key(self, test1_content: dict):
|
||||
assert test1_content.get('invalid') == 'None'
|
||||
Loading…
Add table
Add a link
Reference in a new issue