@pytest.mark.django_db
def test_apiview_get_single(rf):
 view = UserAPIView.as_view()
 user = UserFactory.create(username='foo')
 request = create_api_request(rf)
 response = view(request, id=user.id)
 assert (response.status_code == 200)
 response_data = json.loads(response.content)
 assert isinstance(response_data, dict)
 assert (response_data['username'] == 'foo')
 assert ('email' not in response_data)
 with pytest.raises(Http404):
  view(request, id='777')

@ pytest . mark . django_db def test_apiview_get_single ( rf ) : view = UserAPIView . as_view ( ) user = UserFactory . create ( username = 'foo' ) request = create_api_request ( rf ) response = view ( request , id = user . id ) assert ( response . status_code == 200 ) response_data = json . loads ( response . content ) assert isinstance ( response_data , dict ) assert ( response_data [ 'username' ] == 'foo' ) assert ( 'email' not in response_data ) with pytest . raises ( Http404 ) : view ( request , id = '777' )
tests retrieving a single object using the api .