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