Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ AUTHORS
ChangeLog
*.egg-info
.eggs

.idea/
33 changes: 32 additions & 1 deletion mockserver_friendly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import collections
import json
from enum import Enum

import requests


class RetrievedObjects(Enum):
logs = 'logs'
requests = 'requests'
recorded_expectations = 'recorded_expectations'
active_expectations = 'active_expectations'


class RetrievedFormat(Enum):
java = 'java'
json = 'json'
log_entries = 'log_entries'


class MockServerFriendlyClient(object):
def __init__(self, base_url):
self.base_url = base_url
Expand All @@ -24,7 +38,7 @@ def stub(self, request, response, timing=None, time_to_live=None):
_Option("timeToLive", time_to_live, formatter=_to_time_to_live)
)))

def expect(self, request, response, timing, time_to_live=None):
def expect(self, request, response, timing=None, time_to_live=None):
self.stub(request, response, timing, time_to_live)
self.expectations.append((request, timing))

Expand All @@ -36,6 +50,23 @@ def verify(self):
}))
assert result.status_code == 202, result.content.decode('UTF-8').replace('\n', '\r\n')

def retrieve(self, obj_type, response_format, body):
"""
Retrieve different objects from the mock server

:param obj_type: see `RetrievedObjects`
:param response_format: see `RetrievedFormat`
:param body: dict, pass params here, like: ```{"path": "/some/path"}```
:return: Response from the `requests`
"""
return self._call(
command='retrieve?type={obj_type}&format={response_format}'.format(
obj_type=obj_type,
response_format=response_format
),
data=json.dumps(body)
)


def request(method=None, path=None, querystring=None, body=None, headers=None, cookies=None):
return _non_null_options_to_dict(
Expand Down