1313
1414from patchwork .models import Patch
1515from patchwork .tests .unit .api import utils
16+ from patchwork .tests .utils import create_label
1617from patchwork .tests .utils import create_maintainer
1718from patchwork .tests .utils import create_patch
1819from patchwork .tests .utils import create_patches
@@ -54,6 +55,11 @@ def assertSerialized(self, patch_obj, patch_json):
5455 self .assertIn (patch_obj .get_absolute_url (), patch_json ['web_url' ])
5556 self .assertIn ('comments' , patch_json )
5657
58+ # list fields
59+
60+ for label in patch_obj .labels .all ():
61+ self .assertIn (label .name , patch_json ['labels' ])
62+
5763 # nested fields
5864
5965 self .assertEqual (patch_obj .submitter .id , patch_json ['submitter' ]['id' ])
@@ -257,14 +263,24 @@ def test_list_version_1_0(self):
257263 self .assertEqual (1 , len (resp .data ))
258264 self .assertIn ('url' , resp .data [0 ])
259265 self .assertNotIn ('web_url' , resp .data [0 ])
266+ self .assertNotIn ('labels' , resp .data [0 ])
267+
268+ def test_list_version_1_1 (self ):
269+ create_patch ()
270+
271+ resp = self .client .get (self .api_url (version = '1.1' ))
272+ self .assertEqual (status .HTTP_200_OK , resp .status_code )
273+ self .assertEqual (1 , len (resp .data ))
274+ self .assertIn ('web_url' , resp .data [0 ])
275+ self .assertNotIn ('labels' , resp .data [0 ])
260276
261277 def test_list_bug_335 (self ):
262278 """Ensure we retrieve the embedded series project in O(1)."""
263279 series = create_series ()
264280 create_patches (5 , series = series )
265281
266282 # Count, page IDs, patch rows and the constant-size prefetches.
267- with self .assertNumQueries (6 ):
283+ with self .assertNumQueries (7 ):
268284 self .client .get (self .api_url ())
269285
270286 @utils .store_samples ('patch-detail' )
@@ -297,6 +313,23 @@ def test_detail_version_1_0(self):
297313 self .assertIn ('url' , resp .data )
298314 self .assertNotIn ('web_url' , resp .data )
299315 self .assertNotIn ('comments' , resp .data )
316+ self .assertNotIn ('labels' , resp .data )
317+
318+ def test_detail_version_1_1 (self ):
319+ patch = create_patch ()
320+
321+ resp = self .client .get (self .api_url (item = patch .id , version = '1.1' ))
322+ self .assertIn ('url' , resp .data )
323+ self .assertIn ('web_url' , resp .data )
324+ self .assertIn ('comments' , resp .data )
325+ self .assertNotIn ('labels' , resp .data )
326+
327+ def test_detail_version_1_4 (self ):
328+ label = create_label ()
329+ patch = create_patch (labels = [label ])
330+
331+ resp = self .client .get (self .api_url (item = patch .id , version = '1.4' ))
332+ self .assertEqual (resp .data ['labels' ], [label .name ])
300333
301334 def test_detail_non_existent (self ):
302335 """Ensure we get a 404 for a non-existent patch."""
@@ -308,6 +341,15 @@ def test_detail_invalid(self):
308341 with self .assertRaises (NoReverseMatch ):
309342 self .client .get (self .api_url ('foo' ))
310343
344+ def test_detail_labels (self ):
345+ patch = create_patch ()
346+
347+ resp = self .client .get (self .api_url (item = patch .id , version = '1.4' ))
348+ self .assertIn ('url' , resp .data )
349+ self .assertIn ('web_url' , resp .data )
350+ self .assertIn ('comments' , resp .data )
351+ self .assertIn ('labels' , resp .data )
352+
311353 def test_create (self ):
312354 """Ensure creations are rejected."""
313355 project = create_project ()
0 commit comments