forked from erp-dev/erp
feat: added product image to printing jobs api
This commit is contained in:
@@ -1151,3 +1151,50 @@ class PrintingJobAPITestCase(TestCase):
|
||||
self.assertEqual(len(completed_states), 1)
|
||||
self.assertEqual(completed_states[0]['state_name'], self.state1.name)
|
||||
|
||||
def test_list_printing_jobs_with_product_image_url(self):
|
||||
"""测试列表接口返回产品图片 URL(mdy_image_url 优先)"""
|
||||
# 设置产品的 mdy_image_url
|
||||
self.product.mdy_image_url = 'https://example.com/product.jpg'
|
||||
self.product.save()
|
||||
|
||||
job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
size='50*60',
|
||||
pieces=10
|
||||
)
|
||||
|
||||
response = self.client.get('/api/v1/printing-jobs/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# 验证 product_image_url 字段存在且返回正确的 URL
|
||||
result = response.data['results'][0]
|
||||
self.assertIn('product_image_url', result)
|
||||
self.assertEqual(result['product_image_url'], 'https://example.com/product.jpg')
|
||||
|
||||
def test_list_printing_jobs_product_image_url_none(self):
|
||||
"""测试产品无图片时 product_image_url 返回 None"""
|
||||
# 确保产品没有图片
|
||||
self.product.mdy_image_url = None
|
||||
self.product.image = None
|
||||
self.product.description = None
|
||||
self.product.save()
|
||||
|
||||
job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
size='50*60',
|
||||
pieces=10
|
||||
)
|
||||
|
||||
response = self.client.get('/api/v1/printing-jobs/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# 验证 product_image_url 字段存在且为 None
|
||||
result = response.data['results'][0]
|
||||
self.assertIn('product_image_url', result)
|
||||
self.assertIsNone(result['product_image_url'])
|
||||
|
||||
Reference in New Issue
Block a user