def test_instance_put(self): self.http.respond_to('GET', '/people/1.json', {}, self.matz) self.http.respond_to('PUT', '/people/1/promote.json?position=Manager', self.json_headers, b'') self.assertEqual( connection.Response(200, b''), self.person.find(1).put('promote', b'body', position='Manager'))
def test_handle_valid_response(self): # 2xx and 3xx are valid responses. for code in [200, 299, 300, 399]: response = http_fake.FakeResponse(code, str(code)) self.http.set_response(response) self.assertEquals(self.connection._open('', ''), connection.Response(code, str(code)))
def _lookup_response(self, method, path, headers, data): path_only, query = self._split_path(path) for key, value in self._request_map.get(method, {}): if key == (path_only, query, headers, data): response_body, response_headers = value return connection.Response(200, response_body, response_headers) raise Error('Invalid or unknown request: %s %s\n%s' % (path, headers, data))
def test_instance_put_nested(self): self.http.respond_to('GET', '/people/1/addresses/1.xml', {}, self.addy) self.http.respond_to( 'PUT', '/people/1/addresses/1/normalize_phone.xml?locale=US', self.zero_length_content_headers, '', 204) self.assertEqual( connection.Response(204, ''), self.address.find(1, person_id=1).put('normalize_phone', locale='US'))
def test_instance_post(self): self.http.respond_to('POST', '/people/1/register.json', self.zero_length_content_headers, self.matz) matz = self.person({'id': 1, 'name': 'Matz'}) self.assertEqual(connection.Response(200, self.matz), matz.post('register'))
def test_instance_post_new(self): ryan = self.person({'name': 'Ryan'}) self.http.respond_to('POST', '/people/new/register.json', self.json_headers, b'') self.assertEqual(connection.Response(200, b''), ryan.post('register'))
def test_class_head(self): self.http.respond_to('HEAD', '/people/retrieve.json?name=Matz', {}, b'') self.assertEqual(connection.Response(200, b''), self.person.head('retrieve', name='Matz'))
def test_class_delete(self): self.http.respond_to('DELETE', '/people/deactivate.json?name=Matz', {}, b'') self.assertEqual(connection.Response(200, b''), self.person.delete('deactivate', name='Matz'))
def test_class_put_nested(self): self.http.respond_to('PUT', '/people/1/addresses/sort.json?by=name', self.zero_length_content_headers, b'') self.assertEqual(connection.Response(200, b''), self.address.put('sort', person_id=1, by='name'))
def test_class_put(self): self.http.respond_to('PUT', '/people/promote.json?name=Matz', self.json_headers, b'') self.assertEqual(connection.Response(200, b''), self.person.put('promote', b'atestbody', name='Matz'))
def test_class_post(self): self.http.respond_to('POST', '/people/hire.json?name=Matz', self.zero_length_content_headers, b'') self.assertEqual(connection.Response(200, b''), self.person.post('hire', name='Matz'))
def test_instance_post(self): self.http.respond_to('POST', '/people/1/register.xml', {}, self.matz) matz = self.person({'id': 1, 'name': 'Matz'}) self.assertEqual(connection.Response(200, self.matz), matz.post('register'))
def test_class_put_nested(self): self.http.respond_to('PUT', '/people/1/addresses/sort.xml?by=name', {}, '') self.assertEqual(connection.Response(200, ''), self.address.put('sort', person_id=1, by='name'))
def test_class_post(self): self.http.respond_to('POST', '/people/hire.xml?name=Matz', {}, '') self.assertEqual(connection.Response(200, ''), self.person.post('hire', name='Matz'))