@@ -323,7 +323,7 @@ def test_filter_missing_rvalue(self):
323323 msg = response .content .decode ("utf-8" ))
324324 dja_response = response .json ()
325325 self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
326- "missing filter[headline] test value " )
326+ "missing value for query parameter filter[headline]" )
327327
328328 def test_filter_missing_rvalue_equal (self ):
329329 """
@@ -335,7 +335,61 @@ def test_filter_missing_rvalue_equal(self):
335335 msg = response .content .decode ("utf-8" ))
336336 dja_response = response .json ()
337337 self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
338- "missing filter[headline] test value" )
338+ "missing value for query parameter filter[headline]" )
339+
340+ def test_filter_single_relation (self ):
341+ """
342+ test for filter with a single relation
343+ e.g. filterset-entries?filter[authors.id]=1
344+ looks for entries written by (at least) author.id=1
345+ """
346+ response = self .client .get (self .fs_url , data = {'filter[authors.id]' : 1 })
347+
348+ self .assertEqual (response .status_code , 200 ,
349+ msg = response .content .decode ("utf-8" ))
350+ dja_response = response .json ()
351+
352+ ids = [k ['id' ] for k in dja_response ['data' ]]
353+
354+ expected_ids = [str (k .id ) for k in self .entries .filter (authors__id = 1 )]
355+
356+ self .assertEqual (set (ids ), set (expected_ids ))
357+
358+ def test_filter_repeated_relations (self ):
359+ """
360+ test for filters with repeated relations
361+ e.g. filterset-entries?filter[authors.id]=1&filter[authors.id]=2
362+ looks for entries written by (at least) author.id=1 AND author.id=2
363+ """
364+ response = self .client .get (self .fs_url , data = {'filter[authors.id]' : [1 , 2 ]})
365+
366+ self .assertEqual (response .status_code , 200 ,
367+ msg = response .content .decode ("utf-8" ))
368+ dja_response = response .json ()
369+
370+ ids = [k ['id' ] for k in dja_response ['data' ]]
371+
372+ expected_ids = [str (k .id ) for k in self .entries .filter (authors__id = 1 ).filter (authors__id = 2 )]
373+
374+ self .assertEqual (set (ids ), set (expected_ids ))
375+
376+ def test_filter_in (self ):
377+ """
378+ test for the in filter
379+ e.g. filterset-entries?filter[authors.id.in]=1,2
380+ looks for entries written by (at least) author.id=1 OR author.id=2
381+ """
382+ response = self .client .get (self .fs_url , data = {'filter[authors.id.in]' : '1,2' })
383+
384+ self .assertEqual (response .status_code , 200 ,
385+ msg = response .content .decode ("utf-8" ))
386+ dja_response = response .json ()
387+
388+ ids = [k ['id' ] for k in dja_response ['data' ]]
389+
390+ expected_ids = [str (k .id ) for k in self .entries .filter (authors__id__in = [1 , 2 ])]
391+
392+ self .assertEqual (set (ids ), set (expected_ids ))
339393
340394 def test_search_keywords (self ):
341395 """
@@ -488,7 +542,7 @@ def test_param_invalid(self):
488542 self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
489543 "invalid query parameter: garbage" )
490544
491- def test_param_duplicate (self ):
545+ def test_param_duplicate_sort (self ):
492546 """
493547 Test a duplicated query parameter:
494548 `?sort=headline&page[size]=3&sort=bodyText` is not allowed.
@@ -504,6 +558,17 @@ def test_param_duplicate(self):
504558 self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
505559 "repeated query parameter not allowed: sort" )
506560
561+ def test_param_duplicate_page (self ):
562+ """
563+ test a duplicated page[size] query parameter
564+ """
565+ response = self .client .get (self .fs_url , data = {'page[size]' : [1 , 2 ]})
566+ self .assertEqual (response .status_code , 400 ,
567+ msg = response .content .decode ("utf-8" ))
568+ dja_response = response .json ()
569+ self .assertEqual (dja_response ['errors' ][0 ]['detail' ],
570+ "repeated query parameter not allowed: page[size]" )
571+
507572 def test_many_params (self ):
508573 """
509574 Test that filter params aren't ignored when many params are present
0 commit comments