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

Validate date #109

Open
jbouzekri opened this issue Nov 14, 2015 · 9 comments
Open

Validate date #109

jbouzekri opened this issue Nov 14, 2015 · 9 comments

Comments

@jbouzekri
Copy link

Hi,

A lot of API manipulate date.

How can I use native functionnality of your tool to do it ? Or do I need to write my own extension ?

Thx

Regards

@svanoort
Copy link
Owner

Hi @jbouzekri,
Could you be more specific about your date handling needs? I'm assuming JSON API responses, but XML is also allowed too. The challenge with dates is that they are usually expressed as one of many string formats; in many cases, the best solution is to treat them as strings and use the regex comparator to validate date responses. However, it would certainly be reasonable to add more date handling facilities (especially generator functions for sample data).

Cheers,
Sam

@jbouzekri
Copy link
Author

Sorry for the late reply.
In my case I have 3 use cases I would like to test :

  • I provide a subscription and I have some API endpoints which increase or decrease an expiration date by a fixed amount (timedelta)
  • I have the created_at and updated_at attributes managed by the ORM
  • and a bunch of other dates like last_connection_date, ...

Regards

@svanoort
Copy link
Owner

Okay, so here's what I'm thinking, does this sound about right?

  • A new comparator 'valid_date_format', which takes input string A (from a query) and tries to parse it using the expected time/date format format (argument B) and returns False if it won't parse
  • Possible a new 'between' comparator that checks a value falls inside start/end of a range
  • A new validator type: 'between_dates' which extends the between operator, and takes start/end values plus a format string
validators:
 - 'between_dates': {query: 'document.1.createdDate', start: '01-01-2015', end: '07-07-2015', format: 'MM-DD-YYYY'}

Long term, it's time to start considering adding an embedded expression language to the framework for more complex operations (or at least something that concisely supports function transformations on inputs). Potentially just escape out and allow raw python, although that has security implications. (Open to thoughts here!).

@jbouzekri
Copy link
Author

This would be a good start to manipulate date.
The only thing missing for this first version would be a reference to today or utcnow.

@svanoort
Copy link
Owner

Do you mean in the between_dates validator? If not, please explain further.

@jbouzekri
Copy link
Author

For example : by allowing a start:'utcnow', you could test that the date is in the future.
Or in the eq validator.

@svanoort
Copy link
Owner

@jbouzekri Hmm, okay -- as with any date handling, there are edge cases to be aware of but getting a basic implementation together is quite reasonable now that we've split it into reasonable pieces.

Right now, we can tentatively schedule this feature for the 1.7.0 release aimed for late December, but it's likely it might slip into the next release after that; there is currently quite a bit of work left on large & critical features (Python 3 support, improved parsing and variable use, and Unicode handling fixes).

If you'd like to help make it happen sooner, I'd certainly welcome a PR to add it to the PyRestTest core, and there should be a number of existing examples in the code that you can use as starting points!

@svanoort svanoort added this to the 1.7.0 - Python 3 + Parsing/Configuration Internals milestone Nov 30, 2015
@svanoort
Copy link
Owner

On second thought, make that January, just in case.

@jbouzekri
Copy link
Author

This is not urgent. I have use cases related to dates but it can wait. As you have said you have nicely split the task in simpler ones. I cannot promise I will be able to work on a PR before January too but if I have the time, I will gladly work on it. Thanks for your feedback as always.

@svanoort svanoort modified the milestones: 1.8.0 Feature additions after first refactorings, 1.7.0 - Python 3 + Parsing/Configuration Internals Dec 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants