test: Changed unittest to pytest
This commit is contained in:
parent
02217ae977
commit
fea7838ead
1 changed files with 27 additions and 16 deletions
|
|
@ -1,24 +1,35 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from app.services import Passwords
|
||||
from app.services.mo import Mo
|
||||
|
||||
|
||||
class TestMo(TestCase):
|
||||
def test_process(self):
|
||||
target_path = Path('tests/files/test1/test.yaml')
|
||||
mo = Mo(Passwords())
|
||||
mo.process(Path('tests/files/test1/test.mo.yaml').absolute())
|
||||
self.assertTrue(os.path.exists(target_path))
|
||||
with open(target_path, 'r') as f:
|
||||
content = f.read()
|
||||
self.assertFalse(content.__contains__('${'))
|
||||
self.assertFalse(content.__contains__('%{'))
|
||||
parsed = yaml.load(content, Loader=yaml.FullLoader)
|
||||
self.assertEqual('some_pass', parsed['value'])
|
||||
self.assertEqual('nested_pass', parsed['nested'])
|
||||
self.assertEqual('custom_content', parsed['custom'])
|
||||
@pytest.fixture
|
||||
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()
|
||||
|
||||
|
||||
def test_process(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
|
||||
assert '%{' not in content
|
||||
|
||||
parsed = yaml.load(content, Loader=yaml.FullLoader)
|
||||
assert parsed['value'] == 'some_pass'
|
||||
assert parsed['nested'] == 'nested_pass'
|
||||
assert parsed['custom'] == 'custom_content'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue