mo processing test
This commit is contained in:
parent
e14180cbe7
commit
9166790de9
5 changed files with 31 additions and 3 deletions
|
|
@ -6,6 +6,10 @@ from injectable import injectable, autowired, Autowired
|
|||
|
||||
from app.services import Passwords
|
||||
|
||||
class DotTemplate(Template):
|
||||
# Pozwala na kropki w nazwach placeholderów, np. ${user.name.first}
|
||||
idpattern = r'[_a-zA-Z][_a-zA-Z0-9.]*'
|
||||
|
||||
|
||||
@injectable
|
||||
class Mo:
|
||||
|
|
@ -17,7 +21,7 @@ class Mo:
|
|||
raw = ''
|
||||
with open(mo_file, "r") as mo:
|
||||
raw = mo.read()
|
||||
tpl = Template(raw)
|
||||
tpl = DotTemplate(raw)
|
||||
rendered = tpl.substitute(self._passwords.get_values(tpl.get_identifiers()))
|
||||
de_mo_ified = str(mo_file).replace(".mo", "")
|
||||
with open(de_mo_ified, "w") as mo:
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ class Passwords:
|
|||
path = key_parts[:-2] if len(key_parts) > 2 else None
|
||||
entry_name = key_parts[-2]
|
||||
field_name = key_parts[-1]
|
||||
kp_entry = self._kp_org.find_entries(path=path, first=True, name=entry_name)[0]
|
||||
output[k] = kp_entry[field_name]
|
||||
kp_entry = self._kp_org.find_entries(path=path, first=True, title=entry_name)[0]
|
||||
output[k] = kp_entry[field_name] # TODO: TypeError: 'Entry' object is not subscriptable
|
||||
return output
|
||||
|
||||
def save(self):
|
||||
|
|
|
|||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
3
tests/files/test1/test.mo.yaml
Normal file
3
tests/files/test1/test.mo.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
value: ${sample.password}
|
||||
nested: ${some.nested.value.password}
|
||||
custom: ${custom.field}
|
||||
21
tests/test_mo.py
Normal file
21
tests/test_mo.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
|
||||
from app.services import Passwords
|
||||
from app.services.mo import Mo
|
||||
|
||||
|
||||
class TestMo(TestCase):
|
||||
def test_process(self):
|
||||
mo = Mo(Passwords())
|
||||
mo.process(Path('tests/files/test1/test.mo.yaml').absolute())
|
||||
self.assertTrue(os.path.exists('tests/files/test1/test.mo'))
|
||||
with open('tests/files/test1/test.mo', 'r') as f:
|
||||
content = f.read()
|
||||
self.assertFalse(content.__contains__('${'))
|
||||
"""
|
||||
value: some_oass
|
||||
nested: nested_pass
|
||||
custom: custom_content
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue