vfaronov / turq

Mock HTTP server
ISC License
68 stars 13 forks source link

multi-rule files in start turq #11

Open XiaoboHe opened 7 years ago

XiaoboHe commented 7 years ago

Hi vfaronov,

I just wonder how to start turq with multi-rule files? Thanks!

I start turq with command in the following, may be it is not supported.

# data is dir, and some rule files in it
# start turq with rule dir
turq --no-editor --rules /data/

# start truq with fuzzy style
turq --no-editor --rules /data/*.py
vfaronov commented 7 years ago

Hi! This is currently not supported. You need to put all initial rules into one file.

Is there any specific reason why you need multiple files in your situation?

XiaoboHe commented 7 years ago

in case, if there is a large number of mock interfaces which are provided different applications, how to manage the single config file with large size?

In my opinion, mock can be configured in diff files by diff dimensions.

vfaronov commented 7 years ago

You can work around this with your shell. For example, this works in Bash:

turq --no-editor --rules <( cat /data/*.py )

But maybe you’re right and Turq should be able to handle this by itself. I will think about this for the next version.

wlyssespereira commented 6 years ago

Hello vfaronov,

What about making imports in the rules file? Assuming the rules / file.py file The instruction: import rules.file

Thank you.

vfaronov commented 6 years ago

@wlyssespereira This will not work, because Turq rules are executed in a special Python scope (all the magic names like route and GET), which is unavailable to the module being imported.

wlyssespereira commented 6 years ago

Hello again vfaronov,

I made a little technical adjustment to solve this problem. Follow the code:

wlyssespereira commented 6 years ago

source.py.txt

vfaronov commented 6 years ago

@wlyssespereira Thank you for your suggestion. But I don’t think messing with imports is a good idea for Turq. Above I showed how to load multiple Python files into Turq. If you need something more complex or strange, such as different modules, it’s likely that Turq just isn’t for you.

wlyssespereira commented 6 years ago

@vfaronov, I fully agree, thank you very much for the attention and congratulations for the project.