@@ -1133,9 +1133,9 @@ def test_custom_status(self):
11331133 },
11341134 expected_code = 201 ,
11351135 )
1136- self .assertEqual (response .data ['status' ], self .status .logical_key )
1137- self .assertEqual (response .data ['status_custom_key' ], self .status .key )
1138- pk = response .data ['pk' ]
1136+ self .assertEqual (response .data [0 ][ 'status' ], self .status .logical_key )
1137+ self .assertEqual (response .data [0 ][ 'status_custom_key' ], self .status .key )
1138+ pk = response .data [0 ][ 'pk' ]
11391139
11401140 # Update the stock item with another custom status code via the API
11411141 response = self .patch (
@@ -1167,8 +1167,8 @@ def test_custom_status(self):
11671167 },
11681168 expected_code = 201 ,
11691169 )
1170- self .assertEqual (response .data ['status' ], self .status .logical_key )
1171- self .assertEqual (response .data ['status_custom_key' ], self .status .logical_key )
1170+ self .assertEqual (response .data [0 ][ 'status' ], self .status .logical_key )
1171+ self .assertEqual (response .data [0 ][ 'status_custom_key' ], self .status .logical_key )
11721172
11731173 # Test case with wrong key
11741174 response = self .patch (
@@ -1216,7 +1216,7 @@ def test_create_default_location(self):
12161216 self .list_url , data = {'part' : 4 , 'quantity' : 10 }, expected_code = 201
12171217 )
12181218
1219- self .assertEqual (response .data ['location' ], 2 )
1219+ self .assertEqual (response .data [0 ][ 'location' ], 2 )
12201220
12211221 # What if we explicitly set the location to a different value?
12221222
@@ -1225,7 +1225,7 @@ def test_create_default_location(self):
12251225 data = {'part' : 4 , 'quantity' : 20 , 'location' : 1 },
12261226 expected_code = 201 ,
12271227 )
1228- self .assertEqual (response .data ['location' ], 1 )
1228+ self .assertEqual (response .data [0 ][ 'location' ], 1 )
12291229
12301230 # And finally, what if we set the location explicitly to None?
12311231
@@ -1235,7 +1235,7 @@ def test_create_default_location(self):
12351235 expected_code = 201 ,
12361236 )
12371237
1238- self .assertEqual (response .data ['location' ], None )
1238+ self .assertEqual (response .data [0 ][ 'location' ], None )
12391239
12401240 def test_stock_item_create (self ):
12411241 """Test creation of a StockItem via the API."""
@@ -1306,7 +1306,7 @@ def test_stock_item_create_with_supplier_part(self):
13061306 # Reload part, count stock again
13071307 part_4 = part .models .Part .objects .get (pk = 4 )
13081308 self .assertEqual (part_4 .available_stock , current_count + 3 )
1309- stock_4 = StockItem .objects .get (pk = response .data ['pk' ])
1309+ stock_4 = StockItem .objects .get (pk = response .data [0 ][ 'pk' ])
13101310 self .assertEqual (stock_4 .purchase_price , Money ('123.450000' , 'USD' ))
13111311
13121312 # POST with valid supplier part, no pack size defined
@@ -1330,7 +1330,7 @@ def test_stock_item_create_with_supplier_part(self):
13301330 # Reload part, count stock again
13311331 part_4 = part .models .Part .objects .get (pk = 4 )
13321332 self .assertEqual (part_4 .available_stock , current_count + 12 )
1333- stock_4 = StockItem .objects .get (pk = response .data ['pk' ])
1333+ stock_4 = StockItem .objects .get (pk = response .data [0 ][ 'pk' ])
13341334 self .assertEqual (stock_4 .purchase_price , Money ('123.450000' , 'USD' ))
13351335
13361336 # POST with valid supplier part, WITH pack size defined - but ignore
@@ -1352,7 +1352,7 @@ def test_stock_item_create_with_supplier_part(self):
13521352 # Reload part, count stock again
13531353 part_4 = part .models .Part .objects .get (pk = 4 )
13541354 self .assertEqual (part_4 .available_stock , current_count + 3 )
1355- stock_4 = StockItem .objects .get (pk = response .data ['pk' ])
1355+ stock_4 = StockItem .objects .get (pk = response .data [0 ][ 'pk' ])
13561356 self .assertEqual (stock_4 .purchase_price , Money ('123.450000' , 'USD' ))
13571357
13581358 # POST with valid supplier part, WITH pack size defined and used
@@ -1374,7 +1374,7 @@ def test_stock_item_create_with_supplier_part(self):
13741374 # Reload part, count stock again
13751375 part_4 = part .models .Part .objects .get (pk = 4 )
13761376 self .assertEqual (part_4 .available_stock , current_count + 3 * 100 )
1377- stock_4 = StockItem .objects .get (pk = response .data ['pk' ])
1377+ stock_4 = StockItem .objects .get (pk = response .data [0 ][ 'pk' ])
13781378 self .assertEqual (stock_4 .purchase_price , Money ('1.234500' , 'USD' ))
13791379
13801380 def test_creation_with_serials (self ):
@@ -1450,15 +1450,15 @@ def test_default_expiry(self):
14501450
14511451 response = self .post (self .list_url , data , expected_code = 201 )
14521452
1453- self .assertIsNone (response .data ['expiry_date' ])
1453+ self .assertIsNone (response .data [0 ][ 'expiry_date' ])
14541454
14551455 # Second test - create a new StockItem with an explicit expiry date
14561456 data ['expiry_date' ] = '2022-12-12'
14571457
14581458 response = self .post (self .list_url , data , expected_code = 201 )
14591459
1460- self .assertIsNotNone (response .data ['expiry_date' ])
1461- self .assertEqual (response .data ['expiry_date' ], '2022-12-12' )
1460+ self .assertIsNotNone (response .data [0 ][ 'expiry_date' ])
1461+ self .assertEqual (response .data [0 ][ 'expiry_date' ], '2022-12-12' )
14621462
14631463 # Third test - create a new StockItem for a Part which has a default expiry time
14641464 data = {'part' : 25 , 'quantity' : 10 }
@@ -1468,13 +1468,13 @@ def test_default_expiry(self):
14681468 # Expected expiry date is 10 days in the future
14691469 expiry = datetime .now ().date () + timedelta (10 )
14701470
1471- self .assertEqual (response .data ['expiry_date' ], expiry .isoformat ())
1471+ self .assertEqual (response .data [0 ][ 'expiry_date' ], expiry .isoformat ())
14721472
14731473 # Test result when sending a blank value
14741474 data ['expiry_date' ] = None
14751475
14761476 response = self .post (self .list_url , data , expected_code = 201 )
1477- self .assertEqual (response .data ['expiry_date' ], expiry .isoformat ())
1477+ self .assertEqual (response .data [0 ][ 'expiry_date' ], expiry .isoformat ())
14781478
14791479 def test_purchase_price (self ):
14801480 """Test that we can correctly read and adjust purchase price information via the API."""
@@ -1843,7 +1843,7 @@ def test_delete(self):
18431843 expected_code = 201 ,
18441844 )
18451845
1846- pk = response .data ['pk' ]
1846+ pk = response .data [0 ][ 'pk' ]
18471847
18481848 self .assertEqual (StockItem .objects .count (), n + 1 )
18491849
0 commit comments