Closed mefellows closed 3 years ago
I am facing the same issue on my project. I have tried adding headers but it does not seem to work. The workaround I am using is datetime.now().isoformat()
but it doesn't allow the datetime format checks.
Yep.
That should work, all these matchers are @DawoudSheraz is sugar over the Term
matcher (accepts a regex and an example value).
So in your case, something like this should work:
// regex from matchers.py
regex = r'^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3(' \
r'[12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-' \
r'9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2' \
r'[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d' \
r'([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$'
expected = {
'id': "27",
'name': 'Margharita',
'type': 'Pizza',
'date': Term(
regex, datetime.datetime(
2000, 2, 1, 12, 30, 0, 0
).isoformat()
)
}
You can see the problem here: https://github.com/pact-foundation/pact-python/blob/d348a9c9b1126fa6beb417293db0964f2284686c/pact/matchers.py#L332
Basically, the return values of the generated examples are functions, not values:
>>> import datetime
>>> datetime.datetime( 2000, 2, 1, 12, 30, 0, 0 )
datetime.datetime(2000, 2, 1, 12, 30)
>>> datetime.datetime( 2000, 2, 1, 12, 30, 0, 0 ).isoformat()
'2000-02-01T12:30:00'
Right, makes sense.
although this should have been caught within the tests.
Repro code base: https://github.com/pactflow/example-consumer-python/blob/issue/matcher-not-serialisable/tests/consumer/test_products_consumer.py#L48
Steps to repro:
Error: