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' ])
@@ -232,6 +238,16 @@ def test_list_version_1_0(self):
232238 self .assertEqual (1 , len (resp .data ))
233239 self .assertIn ('url' , resp .data [0 ])
234240 self .assertNotIn ('web_url' , resp .data [0 ])
241+ self .assertNotIn ('labels' , resp .data [0 ])
242+
243+ def test_list_version_1_1 (self ):
244+ create_patch ()
245+
246+ resp = self .client .get (self .api_url (version = '1.1' ))
247+ self .assertEqual (status .HTTP_200_OK , resp .status_code )
248+ self .assertEqual (1 , len (resp .data ))
249+ self .assertIn ('web_url' , resp .data [0 ])
250+ self .assertNotIn ('labels' , resp .data [0 ])
235251
236252 def test_list_bug_335 (self ):
237253 """Ensure we retrieve the embedded series project in O(1)."""
@@ -271,6 +287,23 @@ def test_detail_version_1_0(self):
271287 self .assertIn ('url' , resp .data )
272288 self .assertNotIn ('web_url' , resp .data )
273289 self .assertNotIn ('comments' , resp .data )
290+ self .assertNotIn ('labels' , resp .data )
291+
292+ def test_detail_version_1_1 (self ):
293+ patch = create_patch ()
294+
295+ resp = self .client .get (self .api_url (item = patch .id , version = '1.1' ))
296+ self .assertIn ('url' , resp .data )
297+ self .assertIn ('web_url' , resp .data )
298+ self .assertIn ('comments' , resp .data )
299+ self .assertNotIn ('labels' , resp .data )
300+
301+ def test_detail_version_1_4 (self ):
302+ label = create_label ()
303+ patch = create_patch (labels = [label ])
304+
305+ resp = self .client .get (self .api_url (item = patch .id , version = '1.4' ))
306+ self .assertEqual (resp .data ['labels' ], [label .name ])
274307
275308 def test_detail_non_existent (self ):
276309 """Ensure we get a 404 for a non-existent patch."""
@@ -282,6 +315,15 @@ def test_detail_invalid(self):
282315 with self .assertRaises (NoReverseMatch ):
283316 self .client .get (self .api_url ('foo' ))
284317
318+ def test_detail_labels (self ):
319+ patch = create_patch ()
320+
321+ resp = self .client .get (self .api_url (item = patch .id , version = '1.4' ))
322+ self .assertIn ('url' , resp .data )
323+ self .assertIn ('web_url' , resp .data )
324+ self .assertIn ('comments' , resp .data )
325+ self .assertIn ('labels' , resp .data )
326+
285327 def test_create (self ):
286328 """Ensure creations are rejected."""
287329 project = create_project ()
0 commit comments