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

Fix the json generation of SomethingLike #36

Closed
jeanbaptistepriez opened this issue Jul 12, 2017 · 0 comments · Fixed by #37
Closed

Fix the json generation of SomethingLike #36

jeanbaptistepriez opened this issue Jul 12, 2017 · 0 comments · Fixed by #37

Comments

@jeanbaptistepriez
Copy link
Contributor

jeanbaptistepriez commented Jul 12, 2017

Hello,

There is a small issue (on pact-python==0.6.2) when we try to generate those kind of interactions:

SomethingLike({
   'username': Term('.+', 'admin'),
   'email': ''
})

This raises :

Finding files... done.
Importing test modules ... [2017-07-12 17:43:58] INFO  WEBrick 1.3.1
[2017-07-12 17:43:58] INFO  ruby 2.2.2 (2015-04-13) [x86_64-darwin13]
[2017-07-12 17:43:58] INFO  WEBrick::HTTPServer#start: pid=14167 port=1234
done.

======================================================================
ERROR: test_sign_in (__init__.UserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/EliX/git/test/api/__init__.py", line 35, in test_sign_in
    with pact:
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/pact/pact.py", line 238, in __enter__
    self.setup()
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/pact/pact.py", line 116, in setup
    json={"interactions": self._interactions})
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/requests/api.py", line 124, in put
    return request('put', url, data=data, **kwargs)
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/requests/sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/requests/sessions.py", line 407, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/requests/models.py", line 305, in prepare
    self.prepare_body(data, files, json)
  File "/Users/EliX/anaconda/lib/python2.7/site-packages/requests/models.py", line 445, in prepare_body
    body = complexjson.dumps(json)
  File "/Users/EliX/anaconda/lib/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/Users/EliX/anaconda/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/EliX/anaconda/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/Users/EliX/anaconda/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <pact.matchers.Term object at 0x105931a90> is not JSON serializable

The problem is in file pact/matchers.py on line 120:

return {
  'json_class': 'Pact::SomethingLike',
  'contents': self.matcher}

https://github.com/pact-foundation/pact-python/blob/master/pact/matchers.py#L120

It should be

return {
  'json_class': 'Pact::SomethingLike',
  'contents': from_term(self.matcher)}

This fix should manage when self.matcher is a python dictionary.

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

Successfully merging a pull request may close this issue.

1 participant