Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Passing current timestamp #249

Open
noorul opened this issue Jun 15, 2018 · 1 comment
Open

Question: Passing current timestamp #249

noorul opened this issue Jun 15, 2018 · 1 comment

Comments

@noorul
Copy link

noorul commented Jun 15, 2018

I have a use case to pass current timestamp as HTTP post. Also I would like to add some hours to that and post again. How can I achieve this?

@cdent
Copy link
Owner

cdent commented Jun 16, 2018

If it needs to the exact current time, that will be challenging as currently gabbi doesn't know what time it is. It also depends on how you need the date to be formatted. If you're okay with a number of seconds there may be some tricks you can do, but if you need to use formatted date strings, doing datetime math is not something that currently can be done within the yaml.

Depending on your environment you could set a timestamp in an environment variable and then reference that using the $ENVIRON susbtitution. Then in a subsequent test you might be able to use jsonpath_rw_ext to do some math, if the time showed up in the response.

A bit easier would be to have two static times in the environ, one for "now" and one for "later" and reference them with $ENVIRON, without the math.

If you're testing from with a test harness you might be able to set up a fixture that allows you make a request to a simple wsgi app that gives you the times you want that you can then use in a test to a different wsgi app. The simple wsgi app in gabbi's test do some things in this vein.

If the code you're trying to test is public somewhere and you can point me at it, I might be able to give you some other ideas on how to do what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants