コード例 #1
0
ファイル: test_client.py プロジェクト: GenePeeks/py-rest-orm
 def test_patch(self):
     client = RestClient()
     obj = {
         'body': 'In the end we are all humans, just...',
     }
     response = client.patch('http://jsonplaceholder.typicode.com/posts/1', obj)
     self.assertEqual(client._response.status_code, 200)
     self.assertEqual(response['id'], 1)
     self.assertEqual(response['body'], obj['body'])
     self.assertEqual(response['userId'], 1)
コード例 #2
0
 def test_patch(self):
     client = RestClient()
     obj = {
         'body': 'In the end we are all humans, just...',
     }
     response = client.patch('http://jsonplaceholder.typicode.com/posts/1',
                             obj)
     self.assertEqual(client._response.status_code, 200)
     self.assertEqual(response['id'], 1)
     self.assertEqual(response['body'], obj['body'])
     self.assertEqual(response['userId'], 1)
コード例 #3
0
ファイル: test_client.py プロジェクト: GenePeeks/py-rest-orm
 def test_put(self):
     client = RestClient()
     obj = {
         'title': 'The Great Gatsby',
         'body': 'In the end we are all humans, just...',
         'userId': 2
     }
     response = client.put('http://jsonplaceholder.typicode.com/posts/1', obj)
     self.assertEqual(client._response.status_code, 200)
     self.assertEqual(response['userId'], 2)
     self.assertEqual(response['title'], obj['title'])
コード例 #4
0
 def test_put(self):
     client = RestClient()
     obj = {
         'title': 'The Great Gatsby',
         'body': 'In the end we are all humans, just...',
         'userId': 2
     }
     response = client.put('http://jsonplaceholder.typicode.com/posts/1',
                           obj)
     self.assertEqual(client._response.status_code, 200)
     self.assertEqual(response['userId'], 2)
     self.assertEqual(response['title'], obj['title'])
コード例 #5
0
    def test_raises_exception(self):
        exs = (
            (500, exceptions.http.ServerErrorException),
            (405, exceptions.http.MethodNotAllowedException),
            (404, exceptions.http.NotFoundException),
            (403, exceptions.http.PermissionDeniedException),
            (401, exceptions.http.AuthorizationException),
            (400, exceptions.http.BadRequestException),
        )

        class MockResponse(object):
            def __init__(self, status_code):
                self.status_code = status_code
                self.content = ''

        client = RestClient()
        for code, ex in exs:
            response = MockResponse(code)
            self.assertRaises(ex, client.raise_exception, response)
コード例 #6
0
ファイル: test_client.py プロジェクト: GenePeeks/py-rest-orm
 def test_request_valid_method(self):
     client = RestClient()
     response = client.request('GET', 'http://jsonplaceholder.typicode.com/posts/1')
     self.assertEqual(response['id'], 1)
コード例 #7
0
ファイル: test_client.py プロジェクト: GenePeeks/py-rest-orm
 def test_delete(self):
     client = RestClient()
     client.delete('http://jsonplaceholder.typicode.com/posts/1')
     self.assertEqual(client._response.status_code, 200)
コード例 #8
0
ファイル: test_client.py プロジェクト: GenePeeks/py-rest-orm
 def test_get(self):
     client = RestClient()
     response = client.get('http://jsonplaceholder.typicode.com/posts/1')
     self.assertEqual(response['id'], 1)
コード例 #9
0
 def test_delete(self):
     client = RestClient()
     client.delete('http://jsonplaceholder.typicode.com/posts/1')
     self.assertEqual(client._response.status_code, 200)
コード例 #10
0
 def test_request_valid_method(self):
     client = RestClient()
     response = client.request(
         'GET', 'http://jsonplaceholder.typicode.com/posts/1')
     self.assertEqual(response['id'], 1)
コード例 #11
0
 def test_get(self):
     client = RestClient()
     response = client.get('http://jsonplaceholder.typicode.com/posts/1')
     self.assertEqual(response['id'], 1)
コード例 #12
0
 def test_request_invalid_method(self):
     client = RestClient()
     self.assertRaises(ValueError, client.request, 'INVALID',
                       'http://www.google.com/')