forked from erp-dev/erp
feat: added plate order clone
This commit is contained in:
@@ -7,6 +7,7 @@ from rest_framework.test import APIClient
|
||||
from rest_framework import status
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from basic_info import models as basic_models
|
||||
from printing import models as printing_models
|
||||
from stateflow import models as stateflow_models
|
||||
@@ -108,6 +109,11 @@ class PrintingJobAPITestCase(TestCase):
|
||||
response = self.client.post('/api/v1/printing-jobs/', data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
# 新增字段:批量推进记录(稳定输出 key,默认空数组)
|
||||
self.assertIn('batch_advance_records', response.data)
|
||||
self.assertIsInstance(response.data['batch_advance_records'], list)
|
||||
self.assertEqual(len(response.data['batch_advance_records']), 0)
|
||||
|
||||
# 验证创建成功
|
||||
job = printing_models.PrintingJob.objects.filter(
|
||||
printing_order=self.printing_order,
|
||||
@@ -121,7 +127,7 @@ class PrintingJobAPITestCase(TestCase):
|
||||
def test_list_printing_jobs(self):
|
||||
"""测试获取款式明细列表"""
|
||||
# 创建测试数据
|
||||
printing_models.PrintingJob.objects.create(
|
||||
job1 = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
@@ -129,7 +135,7 @@ class PrintingJobAPITestCase(TestCase):
|
||||
size='50*60',
|
||||
pieces=10
|
||||
)
|
||||
printing_models.PrintingJob.objects.create(
|
||||
job2 = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=200,
|
||||
@@ -141,6 +147,12 @@ class PrintingJobAPITestCase(TestCase):
|
||||
response = self.client.get('/api/v1/printing-jobs/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(len(response.data), 2)
|
||||
|
||||
# 新增字段:批量推进记录(稳定输出 key)
|
||||
for item in response.data:
|
||||
self.assertIn('batch_advance_records', item)
|
||||
self.assertIsInstance(item['batch_advance_records'], list)
|
||||
self.assertEqual(len(item['batch_advance_records']), 0)
|
||||
|
||||
def test_retrieve_printing_job(self):
|
||||
"""测试获取款式明细详情"""
|
||||
@@ -160,6 +172,58 @@ class PrintingJobAPITestCase(TestCase):
|
||||
self.assertEqual(response.data['unit'], '米')
|
||||
self.assertIn('product_name', response.data)
|
||||
self.assertEqual(response.data['product_name'], self.product.name)
|
||||
|
||||
# 新增字段:批量推进记录(稳定输出 key)
|
||||
self.assertIn('batch_advance_records', response.data)
|
||||
self.assertIsInstance(response.data['batch_advance_records'], list)
|
||||
self.assertEqual(len(response.data['batch_advance_records']), 0)
|
||||
|
||||
def test_batch_advance_records_in_list_and_detail(self):
|
||||
"""测试 PrintingJob 序列化输出包含批量推进记录(有记录时返回明细,无记录返回空)"""
|
||||
job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
size='50*60',
|
||||
pieces=10,
|
||||
description='批量记录测试'
|
||||
)
|
||||
|
||||
# 创建一条批量推进记录并关联该 job
|
||||
record = printing_models.PrintingJobBatchAdvanceRecord.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
state=self.state1,
|
||||
created_by=self.user,
|
||||
parameters={'temperature': '25.5', 'operator': '张三'},
|
||||
)
|
||||
record.printing_jobs.add(job)
|
||||
|
||||
# list: 应包含 batch_advance_records
|
||||
response = self.client.get('/api/v1/printing-jobs/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
target = next(item for item in response.data if item['id'] == job.id)
|
||||
|
||||
self.assertIn('batch_advance_records', target)
|
||||
self.assertEqual(len(target['batch_advance_records']), 1)
|
||||
|
||||
rec = target['batch_advance_records'][0]
|
||||
self.assertEqual(rec['id'], record.id)
|
||||
self.assertEqual(rec['printing_order'], self.printing_order.id)
|
||||
self.assertEqual(rec['state'], self.state1.id)
|
||||
self.assertEqual(rec['state_id'], self.state1.id)
|
||||
self.assertEqual(rec['state_name'], self.state1.name)
|
||||
self.assertEqual(rec['created_by'], self.user.id)
|
||||
self.assertEqual(rec['created_by_username'], self.user.username)
|
||||
self.assertEqual(rec['created_by_name'], self.employee.name)
|
||||
self.assertEqual(rec['parameters']['temperature'], '25.5')
|
||||
self.assertEqual(rec['parameters']['operator'], '张三')
|
||||
|
||||
# detail: 同样应包含 batch_advance_records
|
||||
response = self.client.get(f'/api/v1/printing-jobs/{job.id}/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('batch_advance_records', response.data)
|
||||
self.assertEqual(len(response.data['batch_advance_records']), 1)
|
||||
|
||||
def test_update_printing_job(self):
|
||||
"""测试更新款式明细"""
|
||||
@@ -453,6 +517,9 @@ class PrintingJobAPITestCase(TestCase):
|
||||
job = printing_models.PrintingJob.objects.get(id=response.data['id'])
|
||||
self.assertIsNotNone(job.business_object)
|
||||
self.assertEqual(job.business_object.process, self.process)
|
||||
# 新逻辑:BusinessObject 绑定回 PrintingJob
|
||||
self.assertEqual(job.business_object.content_type_id, ContentType.objects.get_for_model(printing_models.PrintingJob).id)
|
||||
self.assertEqual(job.business_object.object_id, job.id)
|
||||
|
||||
def test_job_status_in_detail(self):
|
||||
"""测试任务详情包含状态字段"""
|
||||
|
||||
Reference in New Issue
Block a user