# Path: hoplite/client/helpers.py
# class ClientMixin(object):
#     def _json_data(self, kwargs):
#         if 'data' in kwargs:
#             kwargs['data'] = hoplite_dumps(kwargs['data'])
#         if not kwargs.get('headers', None):
#             kwargs['headers'] = {'Content-type': 'application/json'}
#         return kwargs
# 
#     def _raise_if_status_500(self, response):
#         if response.status_code == 500:
#             raise InternalServerError()
#         return response
# 
#     def _request(self, method, *args, **kwargs):
#         return self._raise_if_status_500(method(*args, **kwargs))
# 
#     def _jrequest(self, *args, **kwargs):
#         return self._request(*args, **kwargs)
# 
#     def jget(self, *args, **kwargs):
#         return self._jrequest(requests.get, *args, **kwargs)
# 
#     def jpost(self, *args, **kwargs):
#         return self._jrequest(requests.post, *args, **self._json_data(kwargs))
# 
#     def jput(self, *args, **kwargs):
#         return self._jrequest(requests.put, *args, **self._json_data(kwargs))
# 
#     def jpatch(self, *args, **kwargs):
#         return self._jrequest(requests.patch, *args, **self._json_data(kwargs))
# 
#     def jdelete(self, *args, **kwargs):
#         return self._jrequest(requests.delete, *args, **self._json_data(kwargs))
# 
# Path: hoplite/serializer.py
# def hoplite_dumps(obj, *args, **kwargs):
#     """
#     Serializes a dictionary into unicode(unless specified otherwise)
#     bson.json_util.dumps does exactly what hoplite needs, so that's what
#     we call
#     :param obj: Python dictionary to be serialized
#     :param args: Please refer to online documentation for bson.json_util.dumps
#         and json.dumps
#     :param kwargs: Please refer to online documentation for
#         bson.json_util.dumps and json.dumps
#     :return: serialized obj in unicode
#     """
#     return dumps(obj, *args, **kwargs)
# 
# Path: tests/utils.py
# class StatusCodeTestMixin(object):
#     def assertStatusCode(self, response, status_code):
#         """Assert the status code of a Flask test client response
# 
#         :param response: The test client response object
#         :param status_code: The expected status code
#         """
#         self.assertEquals(status_code, response.status_code)
#         return response
# 
#     def assertOk(self, response):
#         """Test that response status code is 200
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 200)
# 
#     def assertBadRequest(self, response):
#         """Test that response status code is 400
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 400)
# 
#     def assertForbidden(self, response):
#         """Test that response status code is 403
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 403)
# 
#     def assertNotFound(self, response):
#         """Test that response status code is 404
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 404)
# 
#     def assertContentType(self, response, content_type):
#         """Assert the content-type of a Flask test client response
# 
#         :param response: The test client response object
#         :param content_type: The expected content type
#         """
#         self.assertEquals(content_type, response.headers['Content-Type'])
#         return response
# 
#     def assertOkHtml(self, response):
#         """Assert the response status code is 200 and an HTML response
# 
#         :param response: The test client response object
#         """
#         return self.assertOk(
#             self.assertContentType(response, 'text/html; charset=utf-8'))
# 
#     def assertJson(self, response):
#         """Test that content returned is in JSON format
# 
#         :param response: The test client response object
#         """
#         return self.assertContentType(response, 'application/json')
# 
#     def assertOkJson(self, response):
#         """Assert the response status code is 200 and a JSON response
# 
#         :param response: The test client response object
#         """
#         return self.assertOk(self.assertJson(response))
# 
#     def assertBadJson(self, response):
#         """Assert the response status code is 400 and a JSON response
# 
#         :param response: The test client response object
#         """
#         return self.assertBadRequest(self.assertJson(response))
# 
# Path: hoplite/exceptions.py
# class InternalServerError(HopliteError):
#     def __init__(self, message="Something went wrong on the server"):
#         self.message = message
# 
#     def __str__(self):
#         return self.message


from hoplite.client.helpers import ClientMixin
from hoplite.serializer import hoplite_dumps
from httmock import HTTMock, urlmatch, response, all_requests
from tests.utils import StatusCodeTestMixin
from hoplite.exceptions import InternalServerError
import unittest2
        with HTTMock(get):
            r = self.mixin.jget("http://localhost:5001/test")
            self.assertOk(r)

    def test_jpost(self):
        with HTTMock(post):
            r = self.mixin.jpost("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def test_jput(self):
        with HTTMock(put):
            r = self.mixin.jput("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def test_jpatch(self):
        with HTTMock(patch):
            r = self.mixin.jpatch("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def test_jdelete(self):
        with HTTMock(delete):
            r = self.mixin.jdelete("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def raises_on_500_status_code(self):
        with HTTMock(return_500):
            self.assertRaises(InternalServerError, self.mixin.jget("localhost"))
            self.assertRaises(InternalServerError, self.mixin.jpost("localhost"))
            self.assertRaises(InternalServerError, self.mixin.jput("localhost"))
            self.assertRaises(InternalServerError, self.mixin.jpatch("localhost"))

# Path: hoplite/client/helpers.py
# class ClientMixin(object):
#     def _json_data(self, kwargs):
#         if 'data' in kwargs:
#             kwargs['data'] = hoplite_dumps(kwargs['data'])
#         if not kwargs.get('headers', None):
#             kwargs['headers'] = {'Content-type': 'application/json'}
#         return kwargs
# 
#     def _raise_if_status_500(self, response):
#         if response.status_code == 500:
#             raise InternalServerError()
#         return response
# 
#     def _request(self, method, *args, **kwargs):
#         return self._raise_if_status_500(method(*args, **kwargs))
# 
#     def _jrequest(self, *args, **kwargs):
#         return self._request(*args, **kwargs)
# 
#     def jget(self, *args, **kwargs):
#         return self._jrequest(requests.get, *args, **kwargs)
# 
#     def jpost(self, *args, **kwargs):
#         return self._jrequest(requests.post, *args, **self._json_data(kwargs))
# 
#     def jput(self, *args, **kwargs):
#         return self._jrequest(requests.put, *args, **self._json_data(kwargs))
# 
#     def jpatch(self, *args, **kwargs):
#         return self._jrequest(requests.patch, *args, **self._json_data(kwargs))
# 
#     def jdelete(self, *args, **kwargs):
#         return self._jrequest(requests.delete, *args, **self._json_data(kwargs))
# 
# Path: hoplite/serializer.py
# def hoplite_dumps(obj, *args, **kwargs):
#     """
#     Serializes a dictionary into unicode(unless specified otherwise)
#     bson.json_util.dumps does exactly what hoplite needs, so that's what
#     we call
#     :param obj: Python dictionary to be serialized
#     :param args: Please refer to online documentation for bson.json_util.dumps
#         and json.dumps
#     :param kwargs: Please refer to online documentation for
#         bson.json_util.dumps and json.dumps
#     :return: serialized obj in unicode
#     """
#     return dumps(obj, *args, **kwargs)
# 
# Path: tests/utils.py
# class StatusCodeTestMixin(object):
#     def assertStatusCode(self, response, status_code):
#         """Assert the status code of a Flask test client response
# 
#         :param response: The test client response object
#         :param status_code: The expected status code
#         """
#         self.assertEquals(status_code, response.status_code)
#         return response
# 
#     def assertOk(self, response):
#         """Test that response status code is 200
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 200)
# 
#     def assertBadRequest(self, response):
#         """Test that response status code is 400
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 400)
# 
#     def assertForbidden(self, response):
#         """Test that response status code is 403
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 403)
# 
#     def assertNotFound(self, response):
#         """Test that response status code is 404
# 
#         :param response: The test client response object
#         """
#         return self.assertStatusCode(response, 404)
# 
#     def assertContentType(self, response, content_type):
#         """Assert the content-type of a Flask test client response
# 
#         :param response: The test client response object
#         :param content_type: The expected content type
#         """
#         self.assertEquals(content_type, response.headers['Content-Type'])
#         return response
# 
#     def assertOkHtml(self, response):
#         """Assert the response status code is 200 and an HTML response
# 
#         :param response: The test client response object
#         """
#         return self.assertOk(
#             self.assertContentType(response, 'text/html; charset=utf-8'))
# 
#     def assertJson(self, response):
#         """Test that content returned is in JSON format
# 
#         :param response: The test client response object
#         """
#         return self.assertContentType(response, 'application/json')
# 
#     def assertOkJson(self, response):
#         """Assert the response status code is 200 and a JSON response
# 
#         :param response: The test client response object
#         """
#         return self.assertOk(self.assertJson(response))
# 
#     def assertBadJson(self, response):
#         """Assert the response status code is 400 and a JSON response
# 
#         :param response: The test client response object
#         """
#         return self.assertBadRequest(self.assertJson(response))
# 
# Path: hoplite/exceptions.py
# class InternalServerError(HopliteError):
#     def __init__(self, message="Something went wrong on the server"):
#         self.message = message
# 
#     def __str__(self):
#         return self.message


# Path: tests/client/test_client_mixin.py
from hoplite.client.helpers import ClientMixin
from hoplite.serializer import hoplite_dumps
from httmock import HTTMock, urlmatch, response, all_requests
from tests.utils import StatusCodeTestMixin
from hoplite.exceptions import InternalServerError
import unittest2

        with HTTMock(get):
            r = self.mixin.jget("http://localhost:5001/test")
            self.assertOk(r)

    def test_jpost(self):
        with HTTMock(post):
            r = self.mixin.jpost("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def test_jput(self):
        with HTTMock(put):
            r = self.mixin.jput("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def test_jpatch(self):
        with HTTMock(patch):
            r = self.mixin.jpatch("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def test_jdelete(self):
        with HTTMock(delete):
            r = self.mixin.jdelete("http://localhost:5001/test", data=DATA)
            self.assertOk(r)

    def raises_on_500_status_code(self):
        with HTTMock(return_500):
            self.assertRaises(InternalServerError, self.mixin.jget("localhost"))
            self.assertRaises(InternalServerError, self.mixin.jpost("localhost"))
            self.assertRaises(InternalServerError, self.mixin.jput("localhost"))
            self.assertRaises(InternalServerError, self.mixin.jpatch("localhost"))

            self.assertRaises(InternalServerError, self.mixin.jdelete("localhost"))