2020-09-09 15:23:07 +00:00
|
|
|
"""test example flows in docs"""
|
|
|
|
from glob import glob
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
from django.test import TransactionTestCase
|
|
|
|
|
|
|
|
from passbook.flows.transfer.importer import FlowImporter
|
|
|
|
|
|
|
|
|
|
|
|
class TestTransferDocs(TransactionTestCase):
|
|
|
|
"""Empty class, test methods are added dynamically"""
|
|
|
|
|
|
|
|
|
2020-11-15 21:42:02 +00:00
|
|
|
def pbflow_tester(file_name: str) -> Callable:
|
2020-09-09 15:23:07 +00:00
|
|
|
"""This is used instead of subTest for better visibility"""
|
|
|
|
|
|
|
|
def tester(self: TestTransferDocs):
|
|
|
|
with open(file_name, "r") as flow_json:
|
|
|
|
importer = FlowImporter(flow_json.read())
|
|
|
|
self.assertTrue(importer.validate())
|
|
|
|
self.assertTrue(importer.apply())
|
|
|
|
|
|
|
|
return tester
|
|
|
|
|
|
|
|
|
2020-11-15 21:42:02 +00:00
|
|
|
for flow_file in glob("website/static/flows/*.pbflow"):
|
2020-09-09 15:23:07 +00:00
|
|
|
method_name = Path(flow_file).stem.replace("-", "_").replace(".", "_")
|
2020-11-15 21:42:02 +00:00
|
|
|
setattr(TestTransferDocs, f"test_flow_{method_name}", pbflow_tester(flow_file))
|