From 349e536d144a253e11b3b772303564933e050de0 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 9 Sep 2020 17:23:07 +0200 Subject: [PATCH] flows/tests: add tests to ensure flows in documentation are valid --- passbook/flows/tests/test_transfer_docs.py | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 passbook/flows/tests/test_transfer_docs.py diff --git a/passbook/flows/tests/test_transfer_docs.py b/passbook/flows/tests/test_transfer_docs.py new file mode 100644 index 000000000..9208c9c6e --- /dev/null +++ b/passbook/flows/tests/test_transfer_docs.py @@ -0,0 +1,31 @@ +"""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""" + + +def generic_view_tester(file_name: str) -> Callable: + """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 + + +for flow_file in glob("docs/flow/examples/*.json"): + method_name = Path(flow_file).stem.replace("-", "_").replace(".", "_") + setattr( + TestTransferDocs, f"test_flow_{method_name}", generic_view_tester(flow_file) + )