Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
d87bb67d
Commit
d87bb67d
authored
Feb 10, 2015
by
Carlton Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Failing test case for #1488
parent
7b639c0c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
tests/test_filters.py
+50
-0
No files found.
tests/test_filters.py
View file @
d87bb67d
...
@@ -429,6 +429,56 @@ class SearchFilterTests(TestCase):
...
@@ -429,6 +429,56 @@ class SearchFilterTests(TestCase):
reload_module
(
filters
)
reload_module
(
filters
)
class
AttributeModel
(
models
.
Model
):
label
=
models
.
CharField
(
max_length
=
32
)
class
SearchFilterModelM2M
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
20
)
text
=
models
.
CharField
(
max_length
=
100
)
attributes
=
models
.
ManyToManyField
(
AttributeModel
)
class
SearchFilterM2MSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
SearchFilterModelM2M
class
SearchFilterM2MTests
(
TestCase
):
def
setUp
(
self
):
# Sequence of title/text/attributes is:
#
# z abc [1, 2, 3]
# zz bcd [1, 2, 3]
# zzz cde [1, 2, 3]
# ...
for
idx
in
range
(
3
):
label
=
'w'
*
(
idx
+
1
)
AttributeModel
(
label
=
label
)
for
idx
in
range
(
10
):
title
=
'z'
*
(
idx
+
1
)
text
=
(
chr
(
idx
+
ord
(
'a'
))
+
chr
(
idx
+
ord
(
'b'
))
+
chr
(
idx
+
ord
(
'c'
))
)
SearchFilterModelM2M
(
title
=
title
,
text
=
text
)
.
save
()
SearchFilterModelM2M
.
objects
.
get
(
title
=
'zz'
)
.
attributes
.
add
(
1
,
2
,
3
)
def
test_m2m_search
(
self
):
class
SearchListView
(
generics
.
ListAPIView
):
queryset
=
SearchFilterModelM2M
.
objects
.
all
()
serializer_class
=
SearchFilterM2MSerializer
filter_backends
=
(
filters
.
SearchFilter
,)
search_fields
=
(
'=title'
,
'text'
,
'attributes__label'
)
view
=
SearchListView
.
as_view
()
request
=
factory
.
get
(
'/'
,
{
'search'
:
'zz'
})
response
=
view
(
request
)
self
.
assertEqual
(
len
(
response
.
data
),
1
)
class
OrderingFilterModel
(
models
.
Model
):
class
OrderingFilterModel
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
20
)
title
=
models
.
CharField
(
max_length
=
20
)
text
=
models
.
CharField
(
max_length
=
100
)
text
=
models
.
CharField
(
max_length
=
100
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment