예제 #1
0
 def test_get_member(self):
     request = DummyRequest(path='/thing/1.json')
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.get_member()
     self.assertTrue(isinstance(response, Response))
     self.assertEqual(response.status_int, 200)
예제 #2
0
 def test_get_member_specific_fields(self):
     request = DummyRequest(path='/thing/1.json', params={'$fields': '["id"]'})
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.get_member()
     member = json.loads(response.body)['results'][0]
     self.assert_(member.keys() == ['id'])
예제 #3
0
 def test_unwrapped_response(self):
     request = DummyRequest(path='/thing/1.json', params={'$wrap': 'false'})
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     self.assertFalse(view.wrap)
     response = view.get_member()
     member = json.loads(response.body)[0]
     self.assert_('id' in member and 'val' in member)
예제 #4
0
 def test_delete_member(self):
     request = DummyRequest(method='DELETE', path='/thing/1',)
     request.matchdict = {'id': 1, 'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.delete_member()
     self.assertTrue(isinstance(response, Response))
     self.assertEqual(response.status_int, 204)
     self.assertRaises(HTTPNotFound, view.get_member)
예제 #5
0
 def test_accept_application_json(self):
     request = DummyRequest(path='/thing/1')
     request.accept = MIMEAccept('application/json')
     request.matchdict = {'id': 1}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.get_member()
     self.assertEqual(response.content_type, 'application/json')
     member = json.loads(response.body)['results'][0]
     self.assertEqual(member['id'], 1)
예제 #6
0
 def test_update_member(self):
     request = DummyRequest(
         method='PUT', path='/thing/1', post={'val': 'ONE'},
         content_type='application/x-www-form-urlencoded')
     request.matchdict = {'id': 1}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.update_member()
     self.assertTrue(isinstance(response, Response))
     self.assertEqual(response.status_int, 204)
예제 #7
0
 def test_create_member_from_json(self):
     context = _dummy_context_factory()
     request = DummyRequest(
         path='/thing', body='{"val": "four"}',
         content_type='application/json')
     view = RESTfulView(context, request)
     response = view.create_member()
     self.assertEqual(response.status_int, 201)
     self.assert_(context.get_member(4) is not None)
예제 #8
0
 def test_update_nonexistent_member(self):
     request = DummyRequest(
         method='PUT', path='/thing/42', post={'val': 'Forty-two'},
         content_type='application/x-www-form-urlencoded')
     request.matchdict = {'id': 42}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.update_member()
     self.assertEqual(response.status_int, 201)
     self.assert_('Location' in response.headers)
     self.assertEqual(response.headers['Location'], '/thing/42')
예제 #9
0
 def test_create_member(self):
     context = _dummy_context_factory()
     request = DummyRequest(
         path='/thing', post={'val': 'four'},
         content_type='application/x-www-form-urlencoded')
     view = RESTfulView(context, request)
     response = view.create_member()
     self.assert_(context.get_member(4) is not None)
     self.assertTrue(isinstance(response, Response))
     self.assertEqual(response.status_int, 201)
예제 #10
0
 def test_get_collection_with_kwargs(self):
     context = _dummy_context_factory()
     request = DummyRequest(
         path='/thing.json',
         params={'$$': '{"filters":{"val":"three"}}'})
     request.matchdict = {'renderer': 'json'}
     view = RESTfulView(context, request)
     response = view.get_collection()
     results = json.loads(response.body)['results']
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0]['val'], 'three')
예제 #11
0
 def test_get_collection(self):
     request = DummyRequest(path='/thing.json')
     request.matchdict = {'renderer': 'json'}
     view = RESTfulView(_dummy_context_factory(), request)
     response = view.get_collection()
     self.assertTrue(isinstance(response, Response))