so im using python and want to keep my mappings in...
# help
t
so im using python and want to keep my mappings in separate python files, for example
wiremock_mappings/some_thing.py
would contain something like
Copy code
Mapping(
    request=MappingRequest(method=HttpMethods.GET, url="/some/thing"),
    response=MappingResponse(status=200, body="Hello, world!", headers=("Content-Type", "text/plain")),
)
i can write custom code to load up files from the folder and add them as mappings, but does that already exist somewhere i can leverage? seems like it might be a common use case. i see i can do JSON files and specify a folder, but specifically id like to keep them as python files to be more flexible.
l
Hopefully someone in the community can help here. I don’t use python a great deal so won’t be much use to you here I am afraid.
I have cross posted to the python channel for you in case someone there can help.
t
thanks 😃 ive got something hacky working, but figured theres a cleaner way
Copy code
def add_mappings_from_folder():
    mappings_folder = f"{settings.app_dir}/../sample_app/wiremock_mappings/"
    import os
    for module in os.listdir(mappings_folder):
        if module == '__init__.py' or module[-3:] != '.py':
            continue
        __import__(f"sample_app.wiremock_mappings.{module[:-3]}", locals(), globals())
    del module