@@ -82,27 +82,95 @@ def test_valid_offset_limit(self):
82
82
@pytest .mark .xfail ((sys .version_info .major , sys .version_info .minor ) == (2 , 7 ),
83
83
reason = "python2.7 fails to generate DeprecationWarrning for unknown reason" )
84
84
def test_limit_offset_deprecation (self ):
85
- with pytest .warns (DeprecationWarning ) as record :
85
+ with pytest .warns (PendingDeprecationWarning ) as record :
86
86
pagination .LimitOffsetPagination ()
87
- assert len (record ) == 2
87
+ assert len (record ) == 1
88
88
assert 'LimitOffsetPagination will change in release 3.0' in str (record [0 ].message )
89
- assert 'JsonApiLimitOffsetPagination will be replaced by LimitOffsetPagination' \
90
- in str (record [1 ].message )
89
+
90
+ @pytest .mark .xfail ((sys .version_info .major , sys .version_info .minor ) == (2 , 7 ),
91
+ reason = "python2.7 fails to generate DeprecationWarrning for unknown reason" )
92
+ def test_jsonapi_limit_offset_deprecation (self ):
93
+ with pytest .warns (PendingDeprecationWarning ) as record :
94
+ pagination .JsonApiLimitOffsetPagination ()
95
+ assert len (record ) == 1
96
+ assert 'JsonApiLimitOffsetPagination will be renamed to LimitOffsetPagination' \
97
+ in str (record [0 ].message )
98
+
99
+ class MyInheritedLimitOffsetPagination (pagination .LimitOffsetPagination ):
100
+ """
101
+ Inherit the default values
102
+ """
103
+ pass
104
+
105
+ class MyOverridenLimitOffsetPagination (pagination .LimitOffsetPagination ):
106
+ """
107
+ Explicitly set max_limit to the "old" values.
108
+ """
109
+ max_limit = None
110
+
111
+ def test_my_limit_offset_deprecation (self ):
112
+ with pytest .warns (PendingDeprecationWarning ) as record :
113
+ self .MyInheritedLimitOffsetPagination ()
114
+ assert len (record ) == 1
115
+ assert 'LimitOffsetPagination will change in release 3.0' in str (record [0 ].message )
116
+
117
+ with pytest .warns (None ) as record :
118
+ self .MyOverridenLimitOffsetPagination ()
119
+ assert len (record ) == 0
91
120
92
121
93
- # TODO: This test fails under py27 but it's not clear why so just leave it out for now.
94
122
class TestPageNumber :
95
123
"""
96
124
Unit tests for `pagination.JsonApiPageNumberPagination`.
97
- TODO: add unit tests for changing query parameter names, limits, etc.
98
125
"""
99
126
100
127
@pytest .mark .xfail ((sys .version_info .major , sys .version_info .minor ) == (2 , 7 ),
101
128
reason = "python2.7 fails to generate DeprecationWarrning for unknown reason" )
102
129
def test_page_number_deprecation (self ):
103
- with pytest .warns (DeprecationWarning ) as record :
130
+ with pytest .warns (PendingDeprecationWarning ) as record :
104
131
pagination .PageNumberPagination ()
105
- assert len (record ) == 2
132
+ assert len (record ) == 1
106
133
assert 'PageNumberPagination will change in release 3.0' in str (record [0 ].message )
107
- assert 'JsonApiPageNumberPagination will be replaced by PageNumberPagination' \
108
- in str (record [1 ].message )
134
+
135
+ @pytest .mark .xfail ((sys .version_info .major , sys .version_info .minor ) == (2 , 7 ),
136
+ reason = "python2.7 fails to generate DeprecationWarrning for unknown reason" )
137
+ def test_jsonapi_page_number_deprecation (self ):
138
+ with pytest .warns (PendingDeprecationWarning ) as record :
139
+ pagination .JsonApiPageNumberPagination ()
140
+ assert len (record ) == 1
141
+ assert 'JsonApiPageNumberPagination will be renamed to PageNumberPagination' \
142
+ in str (record [0 ].message )
143
+
144
+ class MyInheritedPageNumberPagination (pagination .PageNumberPagination ):
145
+ """
146
+ Inherit the default values
147
+ """
148
+ pass
149
+
150
+ class MyOverridenPageNumberPagination (pagination .PageNumberPagination ):
151
+ """
152
+ Explicitly set page_query_param and page_size_query_param to the "old" values.
153
+ """
154
+ page_query_param = "page"
155
+ page_size_query_param = "page_size"
156
+
157
+ @pytest .mark .xfail ((sys .version_info .major , sys .version_info .minor ) == (2 , 7 ),
158
+ reason = "python2.7 fails to generate DeprecationWarrning for unknown reason" )
159
+ def test_my_page_number_deprecation (self ):
160
+ with pytest .warns (PendingDeprecationWarning ) as record :
161
+ self .MyInheritedPageNumberPagination ()
162
+ assert len (record ) == 1
163
+ assert 'PageNumberPagination will change in release 3.0' in str (record [0 ].message )
164
+
165
+ with pytest .warns (None ) as record :
166
+ self .MyOverridenPageNumberPagination ()
167
+ assert len (record ) == 0
168
+
169
+ @pytest .mark .xfail ((sys .version_info .major , sys .version_info .minor ) == (2 , 7 ),
170
+ reason = "python2.7 fails to generate DeprecationWarrning for unknown reason" )
171
+ def test_my_jsonapi_page_number_deprecation (self ):
172
+ with pytest .warns (PendingDeprecationWarning ) as record :
173
+ pagination .JsonApiPageNumberPagination ()
174
+ assert len (record ) == 1
175
+ assert 'JsonApiPageNumberPagination will be renamed to PageNumberPagination' \
176
+ in str (record [0 ].message )
0 commit comments