@pytest.mark.django_db
def test_apiview_search(rf):
 view = UserAPIView.as_view()
 UserFactory.create(username='foo', full_name='Foo Bar')
 UserFactory.create(username='foobar', full_name='Foo Bar')
 UserFactory.create(username='foobarbaz', full_name='Foo Bar')
 request = create_api_request(rf, url='/?q=bar')
 response = view(request)
 response_data = json.loads(response.content)
 assert (response.status_code == 200)
 assert (len(response_data['models']) == 3)
 request = create_api_request(rf, url='/?q=baz')
 response = view(request)
 response_data = json.loads(response.content)
 assert (response.status_code == 200)
 assert (len(response_data['models']) == 1)
 request = create_api_request(rf, url='/?q=BaZ')
 response = view(request)
 response_data = json.loads(response.content)
 assert (response.status_code == 200)
 assert (len(response_data['models']) == 1)

@ pytest . mark . django_db def test_apiview_search ( rf ) : view = UserAPIView . as_view ( ) UserFactory . create ( username = 'foo' , full_name = 'Foo Bar' ) UserFactory . create ( username = 'foobar' , full_name = 'Foo Bar' ) UserFactory . create ( username = 'foobarbaz' , full_name = 'Foo Bar' ) request = create_api_request ( rf , url = '/?q=bar' ) response = view ( request ) response_data = json . loads ( response . content ) assert ( response . status_code == 200 ) assert ( len ( response_data [ 'models' ] ) == 3 ) request = create_api_request ( rf , url = '/?q=baz' ) response = view ( request ) response_data = json . loads ( response . content ) assert ( response . status_code == 200 ) assert ( len ( response_data [ 'models' ] ) == 1 ) request = create_api_request ( rf , url = '/?q=BaZ' ) response = view ( request ) response_data = json . loads ( response . content ) assert ( response . status_code == 200 ) assert ( len ( response_data [ 'models' ] ) == 1 )
tests filtering through a search query .