Esempio n. 1
0
class Model(unittest.TestCase):
    def setUp(self):
        self.model = ProtocolBufferModel(MockProtocolBuffer)

    def test_no_body(self):
        headers = {}
        path_params = {}
        query_params = {}
        body = None

        headers, params, query, body = self.model.request(
            headers, path_params, query_params, body)

        self.assertEqual(headers['accept'], 'application/x-protobuf')
        self.assertTrue('content-type' not in headers)
        self.assertNotEqual(query, '')
        self.assertEqual(body, None)

    def test_body(self):
        headers = {}
        path_params = {}
        query_params = {}
        body = MockProtocolBuffer('data')

        headers, params, query, body = self.model.request(
            headers, path_params, query_params, body)

        self.assertEqual(headers['accept'], 'application/x-protobuf')
        self.assertEqual(headers['content-type'], 'application/x-protobuf')
        self.assertNotEqual(query, '')
        self.assertEqual(body, 'data')

    def test_good_response(self):
        resp = httplib2.Response({'status': '200'})
        resp.reason = 'OK'
        content = 'data'

        content = self.model.response(resp, content)
        self.assertEqual(content, MockProtocolBuffer('data'))

    def test_no_content_response(self):
        resp = httplib2.Response({'status': '204'})
        resp.reason = 'No Content'
        content = ''

        content = self.model.response(resp, content)
        self.assertEqual(content, MockProtocolBuffer())
class Model(unittest.TestCase):
    def setUp(self):
        self.model = ProtocolBufferModel(MockProtocolBuffer)

    def test_no_body(self):
        headers = {}
        path_params = {}
        query_params = {}
        body = None

        headers, params, query, body = self.model.request(
            headers, path_params, query_params, body)

        self.assertEqual(headers["accept"], "application/x-protobuf")
        self.assertTrue("content-type" not in headers)
        self.assertNotEqual(query, "")
        self.assertEqual(body, None)

    def test_body(self):
        headers = {}
        path_params = {}
        query_params = {}
        body = MockProtocolBuffer("data")

        headers, params, query, body = self.model.request(
            headers, path_params, query_params, body)

        self.assertEqual(headers["accept"], "application/x-protobuf")
        self.assertEqual(headers["content-type"], "application/x-protobuf")
        self.assertNotEqual(query, "")
        self.assertEqual(body, "data")

    def test_good_response(self):
        resp = httplib2.Response({"status": "200"})
        resp.reason = "OK"
        content = "data"

        content = self.model.response(resp, content)
        self.assertEqual(content, MockProtocolBuffer("data"))

    def test_no_content_response(self):
        resp = httplib2.Response({"status": "204"})
        resp.reason = "No Content"
        content = ""

        content = self.model.response(resp, content)
        self.assertEqual(content, MockProtocolBuffer())
class Model(unittest.TestCase):
  def setUp(self):
    self.model = ProtocolBufferModel(MockProtocolBuffer)

  def test_no_body(self):
    headers = {}
    path_params = {}
    query_params = {}
    body = None

    headers, params, query, body = self.model.request(
        headers, path_params, query_params, body)

    self.assertEqual(headers['accept'], 'application/x-protobuf')
    self.assertTrue('content-type' not in headers)
    self.assertNotEqual(query, '')
    self.assertEqual(body, None)

  def test_body(self):
    headers = {}
    path_params = {}
    query_params = {}
    body = MockProtocolBuffer('data')

    headers, params, query, body = self.model.request(
        headers, path_params, query_params, body)

    self.assertEqual(headers['accept'], 'application/x-protobuf')
    self.assertEqual(headers['content-type'], 'application/x-protobuf')
    self.assertNotEqual(query, '')
    self.assertEqual(body, 'data')

  def test_good_response(self):
    resp = httplib2.Response({'status': '200'})
    resp.reason = 'OK'
    content = 'data'

    content = self.model.response(resp, content)
    self.assertEqual(content, MockProtocolBuffer('data'))

  def test_no_content_response(self):
    resp = httplib2.Response({'status': '204'})
    resp.reason = 'No Content'
    content = ''

    content = self.model.response(resp, content)
    self.assertEqual(content, MockProtocolBuffer())
class Model(unittest.TestCase):
    def setUp(self):
        self.model = ProtocolBufferModel(MockProtocolBuffer)

    def test_no_body(self):
        headers = {}
        path_params = {}
        query_params = {}
        body = None

        headers, params, query, body = self.model.request(headers, path_params, query_params, body)

        self.assertEqual(headers["accept"], "application/x-protobuf")
        self.assertTrue("content-type" not in headers)
        self.assertNotEqual(query, "")
        self.assertEqual(body, None)

    def test_body(self):
        headers = {}
        path_params = {}
        query_params = {}
        body = MockProtocolBuffer("data")

        headers, params, query, body = self.model.request(headers, path_params, query_params, body)

        self.assertEqual(headers["accept"], "application/x-protobuf")
        self.assertEqual(headers["content-type"], "application/x-protobuf")
        self.assertNotEqual(query, "")
        self.assertEqual(body, "data")

    def test_good_response(self):
        resp = httplib2.Response({"status": "200"})
        resp.reason = "OK"
        content = "data"

        content = self.model.response(resp, content)
        self.assertEqual(content, MockProtocolBuffer("data"))

    def test_no_content_response(self):
        resp = httplib2.Response({"status": "204"})
        resp.reason = "No Content"
        content = ""

        content = self.model.response(resp, content)
        self.assertEqual(content, MockProtocolBuffer())
Esempio n. 5
0
 def setUp(self):
     self.model = ProtocolBufferModel(MockProtocolBuffer)
 def setUp(self):
     self.model = ProtocolBufferModel(MockProtocolBuffer)