Ejemplo n.º 1
0
 def test_request(self):
     """
     Makes a request and decodes JSON responses.
     """
     def _response_for(method, url, params, headers, data):
         self.assertThat(method, Equals(u'GET'))
         self.assertThat(url, Equals(b'http://example.com/get_json'))
         self.assertThat(
             headers,
             ContainsDict(
                 {b'Accept': Equals([b'application/json'])}))
         return 200, {}, json.dumps({u'arst': u'arst'})
     resource = StringStubbingResource(_response_for)
     treq = StubTreq(resource)
     self.assertThat(
         json_request(treq.request, b'GET', b'http://example.com/get_json'),
         succeeded(
             Equals({u'arst': u'arst'})))
Ejemplo n.º 2
0
 def test_overwrite_accept(self):
     """
     If an existing ``Accept`` header exists it is overwritten.
     """
     def _response_for(method, url, params, headers, data):
         self.assertThat(method, Equals(u'GET'))
         self.assertThat(url, Equals(b'http://example.com/get_json'))
         self.assertThat(
             headers,
             ContainsDict(
                 {b'Accept': Equals([b'application/json'])}))
         return 200, {}, json.dumps({u'arst': u'arst'})
     resource = StringStubbingResource(_response_for)
     treq = StubTreq(resource)
     self.assertThat(
         json_request(treq.request, b'GET', b'http://example.com/get_json',
                      headers={b'Accept': b'text/plain'}),
         succeeded(
             Equals({u'arst': u'arst'})))