|
|
@@ -0,0 +1,542 @@
|
|
|
+import io
|
|
|
+import unittest
|
|
|
+
|
|
|
+from app import GatewayApp
|
|
|
+from public_gateway import PublicGatewayApp
|
|
|
+from services.output_presenter import OutputPresenter
|
|
|
+from tools.list_pending_goods_filter_options import (
|
|
|
+ ListPendingGoodsFilterOptionsTool,
|
|
|
+)
|
|
|
+from tools.query_pending_goods_list import QueryPendingGoodsListTool
|
|
|
+
|
|
|
+
|
|
|
+class PendingGoodsToolsTest(unittest.TestCase):
|
|
|
+ def test_registers_list_and_filter_on_local_and_public(self):
|
|
|
+ local = GatewayApp().registered_tool_names()
|
|
|
+ public = PublicGatewayApp(None, None).registered_tool_names()
|
|
|
+ self.assertEqual(local, public)
|
|
|
+ self.assertEqual(55, len(local))
|
|
|
+ self.assertIn('query_pending_goods_list', local)
|
|
|
+ self.assertIn('list_pending_goods_filter_options', local)
|
|
|
+ self.assertEqual(54, len(OutputPresenter.SAFE_TOOLS))
|
|
|
+
|
|
|
+ def test_list_schema_is_closed_and_filter_requires_type(self):
|
|
|
+ listed = QueryPendingGoodsListTool().metadata()
|
|
|
+ self.assertNotIn('required', listed['input_schema'])
|
|
|
+ self.assertFalse(listed['input_schema']['additionalProperties'])
|
|
|
+ self.assertIn('禁止使用:', listed['description'])
|
|
|
+ self.assertIn('list_pending_goods_filter_options', listed['description'])
|
|
|
+ options = ListPendingGoodsFilterOptionsTool().metadata()
|
|
|
+ self.assertEqual(['filter_type'], options['input_schema']['required'])
|
|
|
+ self.assertEqual(
|
|
|
+ ['客户名称', '起运国', '目的国'],
|
|
|
+ options['input_schema']['properties']['filter_type']['enum'],
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_presenter_accepts_twenty_two_string_columns(self):
|
|
|
+ presenter = OutputPresenter()
|
|
|
+ columns = [
|
|
|
+ {'key': key, 'name': name}
|
|
|
+ for key, name in OutputPresenter.PENDING_GOODS_COLUMNS
|
|
|
+ ]
|
|
|
+ record = {key: '' for key, _ in OutputPresenter.PENDING_GOODS_COLUMNS}
|
|
|
+ record['sku'] = 'A 1'
|
|
|
+ record['is_project_goods'] = '是'
|
|
|
+ record['is_pre_audit'] = '否'
|
|
|
+ result = presenter.present('query_pending_goods_list', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'msg': 'ok',
|
|
|
+ 'data': {'columns': columns, 'records': [record]},
|
|
|
+ 'meta': {'page': 1, 'limit': 20, 'has_more': False, 'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertFalse(result['is_error'])
|
|
|
+ self.assertEqual(21, len(result['structured_content']['headers']))
|
|
|
+ self.assertEqual('商品编号', result['structured_content']['headers'][0]['label'])
|
|
|
+ self.assertEqual('经过预审', result['structured_content']['headers'][20]['label'])
|
|
|
+ broken = dict(record)
|
|
|
+ broken['extra'] = 'x'
|
|
|
+ failed = presenter.present('query_pending_goods_list', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'msg': 'ok',
|
|
|
+ 'data': {'columns': columns, 'records': [broken]},
|
|
|
+ 'meta': {'page': 1, 'limit': 20, 'has_more': False, 'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertTrue(failed['is_error'])
|
|
|
+
|
|
|
+ def test_call_rejects_unknown_shipping_and_too_many_skus(self):
|
|
|
+ tool = QueryPendingGoodsListTool(api_client=object())
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(shipping_method='快递')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(skus=['S%s' % i for i in range(51)])
|
|
|
+ with self.assertRaises(RuntimeError):
|
|
|
+ QueryPendingGoodsListTool().call()
|
|
|
+
|
|
|
+ def test_call_forwards_closed_filters(self):
|
|
|
+ class Client:
|
|
|
+ def __init__(self):
|
|
|
+ self.payload = None
|
|
|
+
|
|
|
+ def call_tool(self, name, route, payload, request_id):
|
|
|
+ self.payload = (name, route, payload, request_id)
|
|
|
+ return {'ok': True}
|
|
|
+
|
|
|
+ client = Client()
|
|
|
+ tool = QueryPendingGoodsListTool(api_client=client)
|
|
|
+ self.assertEqual({'ok': True}, tool.call(
|
|
|
+ skus='A 1,B',
|
|
|
+ customer_id=8,
|
|
|
+ departure_country='cn',
|
|
|
+ destination_country='us',
|
|
|
+ shipping_method='海运',
|
|
|
+ goods_attrs=['普货', '带电', '普货'],
|
|
|
+ request_id='rq_forward',
|
|
|
+ ))
|
|
|
+ self.assertEqual(
|
|
|
+ ('query_pending_goods_list', '/mcp/tools/queryPendingGoodsList', {
|
|
|
+ 'page': 1,
|
|
|
+ 'limit': 20,
|
|
|
+ 'skus': ['A 1', 'B'],
|
|
|
+ 'customer_id': 8,
|
|
|
+ 'departure_country': 'CN',
|
|
|
+ 'destination_country': 'US',
|
|
|
+ 'shipping_method': '海运',
|
|
|
+ 'goods_attrs': ['普货', '带电'],
|
|
|
+ }, 'rq_forward'),
|
|
|
+ client.payload,
|
|
|
+ )
|
|
|
+ options = ListPendingGoodsFilterOptionsTool(api_client=client)
|
|
|
+ options.call(filter_type='起运国', keyword='美', request_id='rq_opt')
|
|
|
+ self.assertEqual('起运国', client.payload[2]['filter_type'])
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ options.call(filter_type='事业部')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ options.call(filter_type='客户名称', keyword='x' * 101)
|
|
|
+ with self.assertRaises(RuntimeError):
|
|
|
+ ListPendingGoodsFilterOptionsTool().call(filter_type='客户名称')
|
|
|
+ bare = QueryPendingGoodsListTool(api_client=client)
|
|
|
+ bare.call()
|
|
|
+ self.assertEqual({'page': 1, 'limit': 20}, client.payload[2])
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(skus=1)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(skus='A,,B,' + ('x' * 201))
|
|
|
+ self.assertEqual(['A'], tool._skus(['A', 'A', ' ']))
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(customer_id=True)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(departure_country='中国')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(goods_attrs='普货')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(goods_attrs=['木头'])
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(page=True)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ tool.call(limit=101)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ options.call(filter_type='客户名称', page=True)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ options.call(filter_type='客户名称', limit=0)
|
|
|
+
|
|
|
+ def test_presenter_rejects_malformed_rows(self):
|
|
|
+ presenter = OutputPresenter()
|
|
|
+ columns = [
|
|
|
+ {'key': key, 'name': name}
|
|
|
+ for key, name in OutputPresenter.PENDING_GOODS_COLUMNS
|
|
|
+ ]
|
|
|
+ record = {key: '' for key, _ in OutputPresenter.PENDING_GOODS_COLUMNS}
|
|
|
+ meta = {'page': 1, 'limit': 20, 'has_more': False, 'request_id': 'rq'}
|
|
|
+ base = {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'columns': columns, 'records': [record]},
|
|
|
+ 'meta': meta,
|
|
|
+ }
|
|
|
+ self.assertTrue(presenter.present('query_pending_goods_list', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'records': []},
|
|
|
+ 'meta': meta,
|
|
|
+ })['is_error'])
|
|
|
+ self.assertTrue(presenter.present('query_pending_goods_list', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': base['data'],
|
|
|
+ 'meta': {'page': 1, 'limit': 20, 'request_id': 'rq'},
|
|
|
+ })['is_error'])
|
|
|
+ bad_columns = [dict(column) for column in columns]
|
|
|
+ bad_columns[0] = {'key': 'sku', 'name': '错误'}
|
|
|
+ self.assertTrue(presenter.present('query_pending_goods_list', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'columns': bad_columns, 'records': [record]},
|
|
|
+ 'meta': meta,
|
|
|
+ })['is_error'])
|
|
|
+ bad_record = dict(record)
|
|
|
+ bad_record['sku'] = 1
|
|
|
+ self.assertTrue(presenter.present('query_pending_goods_list', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'columns': columns, 'records': [bad_record]},
|
|
|
+ 'meta': meta,
|
|
|
+ })['is_error'])
|
|
|
+
|
|
|
+ def test_cli_forwards_optional_filters(self):
|
|
|
+ class Client:
|
|
|
+ def __init__(self):
|
|
|
+ self.calls = []
|
|
|
+
|
|
|
+ def list_enabled_tools(self, request_id=''):
|
|
|
+ return {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {
|
|
|
+ 'tool_codes': [
|
|
|
+ 'query_pending_goods_list',
|
|
|
+ 'list_pending_goods_filter_options',
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ def call_tool(self, tool_code, route_path, payload, request_id):
|
|
|
+ self.calls.append(payload)
|
|
|
+ return {'code': 'MCP_0000', 'data': {}, 'meta': {}}
|
|
|
+
|
|
|
+ client = Client()
|
|
|
+ app = GatewayApp(api_client=client)
|
|
|
+ app.run_cli(
|
|
|
+ ['call', '--tool', 'query_pending_goods_list'],
|
|
|
+ stdout=io.StringIO(),
|
|
|
+ )
|
|
|
+ app.run_cli([
|
|
|
+ 'call', '--tool', 'query_pending_goods_list',
|
|
|
+ '--skus', 'A,B',
|
|
|
+ '--customer-id', '8',
|
|
|
+ '--departure-country', 'CN',
|
|
|
+ '--destination-country', 'US',
|
|
|
+ '--goods-shipping-method', '海运',
|
|
|
+ '--goods-attrs', '普货,带电',
|
|
|
+ ], stdout=io.StringIO())
|
|
|
+ app.run_cli([
|
|
|
+ 'call', '--tool', 'list_pending_goods_filter_options',
|
|
|
+ '--filter-type', '起运国',
|
|
|
+ '--keyword', '美',
|
|
|
+ ], stdout=io.StringIO())
|
|
|
+ self.assertEqual({'page': 1, 'limit': 20}, client.calls[0])
|
|
|
+ self.assertEqual(['A', 'B'], client.calls[1]['skus'])
|
|
|
+ self.assertEqual(8, client.calls[1]['customer_id'])
|
|
|
+ self.assertEqual('海运', client.calls[1]['shipping_method'])
|
|
|
+ self.assertEqual('起运国', client.calls[2]['filter_type'])
|
|
|
+
|
|
|
+ def test_open_and_submit_tools_and_presenter(self):
|
|
|
+ from tools.open_goods_audit import OpenGoodsAuditTool
|
|
|
+ from tools.submit_goods_audit import SubmitGoodsAuditTool
|
|
|
+
|
|
|
+ opened = OpenGoodsAuditTool().metadata()
|
|
|
+ submitted = SubmitGoodsAuditTool().metadata()
|
|
|
+ self.assertEqual(['sku'], opened['input_schema']['required'])
|
|
|
+ self.assertFalse(opened['input_schema']['additionalProperties'])
|
|
|
+ self.assertFalse(submitted['input_schema']['additionalProperties'])
|
|
|
+ self.assertIn('status', submitted['input_schema']['required'])
|
|
|
+
|
|
|
+ class Client:
|
|
|
+ def __init__(self):
|
|
|
+ self.payload = None
|
|
|
+
|
|
|
+ def call_tool(self, tool_code, route_path, payload, request_id):
|
|
|
+ self.payload = payload
|
|
|
+ return {'code': 'MCP_0000', 'data': {}, 'meta': {}}
|
|
|
+
|
|
|
+ client = Client()
|
|
|
+ self.assertEqual(
|
|
|
+ 'CUP-1',
|
|
|
+ OpenGoodsAuditTool(client).call('CUP-1') and client.payload['sku'],
|
|
|
+ )
|
|
|
+ OpenGoodsAuditTool(client).call(
|
|
|
+ ' CUP-1 ',
|
|
|
+ departure_country='中国',
|
|
|
+ destination_country='美国',
|
|
|
+ )
|
|
|
+ self.assertEqual('中国', client.payload['departure_country'])
|
|
|
+ self.assertEqual('美国', client.payload['destination_country'])
|
|
|
+ with self.assertRaises(RuntimeError):
|
|
|
+ OpenGoodsAuditTool().call('CUP-1')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ OpenGoodsAuditTool(client).call('')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ OpenGoodsAuditTool(client).call(True)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ OpenGoodsAuditTool(client).call('x' * 201)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ SubmitGoodsAuditTool(client).call('x' * 201, '30')
|
|
|
+ SubmitGoodsAuditTool(client).call(
|
|
|
+ 'CUP-1', '30',
|
|
|
+ departure_country='中国',
|
|
|
+ destination_country='美国',
|
|
|
+ audit_result='备注',
|
|
|
+ options={'results': []},
|
|
|
+ )
|
|
|
+ self.assertEqual('30', client.payload['status'])
|
|
|
+ self.assertEqual('CUP-1', client.payload['sku'])
|
|
|
+ self.assertEqual('备注', client.payload['audit_result'])
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ SubmitGoodsAuditTool(client).call('', '30')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ SubmitGoodsAuditTool(client).call(True, '30')
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ SubmitGoodsAuditTool(client).call('CUP-1', '10')
|
|
|
+ with self.assertRaises(RuntimeError):
|
|
|
+ SubmitGoodsAuditTool().call('CUP-1', '30')
|
|
|
+
|
|
|
+ presenter = OutputPresenter()
|
|
|
+ payload = self._audit_payload()
|
|
|
+ shown = presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_0000', 'data': payload,
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertFalse(shown['is_error'])
|
|
|
+ self.assertIn('2683', shown['text'])
|
|
|
+ saved = presenter.present('submit_goods_audit', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {
|
|
|
+ 'goods_id': '2683', 'status': '30', 'status_name': '审核通过',
|
|
|
+ },
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertEqual('审核通过', saved['structured_content']['审核结果'])
|
|
|
+ self.assertTrue(presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_0000', 'data': {'audit_sheet': {}},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })['is_error'])
|
|
|
+ bad_sheet = dict(payload)
|
|
|
+ bad_sheet['audit_sheet'] = []
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_sheet))
|
|
|
+ bad_attr = self._audit_payload()
|
|
|
+ bad_attr['audit_sheet']['goods_attr'] = {'is_battery': 'Y'}
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_attr))
|
|
|
+ bad_rows = self._audit_payload()
|
|
|
+ bad_rows['audit_sheet']['yf_clearance_data'] = {'not': 'list'}
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_rows))
|
|
|
+ bad_code = self._audit_payload()
|
|
|
+ bad_code['audit_sheet']['ys_clearance_data'][0]['adjust_hscode_data'] = [1]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_code))
|
|
|
+ bad_new = self._audit_payload()
|
|
|
+ bad_new['audit_sheet']['ys_clearance_data'][0]['is_new_hscode'] = '新'
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_new))
|
|
|
+ bad_text = self._audit_payload()
|
|
|
+ bad_text['audit_sheet']['goods_id'] = 2683
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_text))
|
|
|
+ bad_options = self._audit_payload()
|
|
|
+ bad_options['options'] = []
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_options))
|
|
|
+ bad_results = self._audit_payload()
|
|
|
+ bad_results['options']['results'] = {'value': '30'}
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_results))
|
|
|
+ bad_reject = self._audit_payload()
|
|
|
+ bad_reject['options']['reject_types'] = [{'value': '1', 'label': '甲'}]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_reject))
|
|
|
+ bad_choice = self._audit_payload()
|
|
|
+ bad_choice['options']['goods_types'] = [{'value': 1, 'label': '普货'}]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_choice))
|
|
|
+ bad_marks = self._audit_payload()
|
|
|
+ bad_marks['options']['cpsc_marks'] = {'Z': '1'}
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_marks))
|
|
|
+ empty_mark = self._audit_payload()
|
|
|
+ empty_mark['options']['cpsc_marks'] = {'Y': ''}
|
|
|
+ self.assertTrue(self._open_error(presenter, empty_mark))
|
|
|
+ bad_order = self._audit_payload()
|
|
|
+ bad_order['options']['sync_orders'] = [{'order_id': 1}]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_order))
|
|
|
+ bad_ref = self._audit_payload()
|
|
|
+ bad_ref['reference'] = {}
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_ref))
|
|
|
+ bad_file = self._audit_payload()
|
|
|
+ bad_file['reference']['files']['battery_file'] = 'x'
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_file))
|
|
|
+ bad_row = self._audit_payload()
|
|
|
+ bad_row['audit_sheet']['yf_clearance_data'] = ['row']
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_row))
|
|
|
+ bad_material = self._audit_payload()
|
|
|
+ bad_material['audit_sheet']['ys_clearance_data'][0]['material'] = 1
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_material))
|
|
|
+ bad_order_text = self._audit_payload()
|
|
|
+ bad_order_text['options']['sync_orders'] = [{
|
|
|
+ 'order_id': '5', 'order_number': 'SO1', 'status_name': 1,
|
|
|
+ }]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_order_text))
|
|
|
+ bad_image = self._audit_payload()
|
|
|
+ bad_image['reference']['image_url'] = None
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_image))
|
|
|
+ bad_files = self._audit_payload()
|
|
|
+ bad_files['reference']['files'] = []
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_files))
|
|
|
+ bad_item = self._audit_payload()
|
|
|
+ bad_item['reference']['files']['toy_file'] = ['file']
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_item))
|
|
|
+ bad_name = self._audit_payload()
|
|
|
+ bad_name['reference']['files']['fda_file'] = [{'name': 1, 'url': 'http'}]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_name))
|
|
|
+ bad_link = self._audit_payload()
|
|
|
+ bad_link['reference']['files']['fda_file'] = [{'name': 'a', 'url': None}]
|
|
|
+ self.assertTrue(self._open_error(presenter, bad_link))
|
|
|
+ self.assertTrue(presenter.present('submit_goods_audit', {
|
|
|
+ 'code': 'MCP_0000', 'data': {'goods_id': '1'},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })['is_error'])
|
|
|
+ self.assertTrue(presenter.present('submit_goods_audit', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'goods_id': '', 'status': '30', 'status_name': '审核通过'},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })['is_error'])
|
|
|
+ self.assertTrue(presenter.present('submit_goods_audit', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'goods_id': '1', 'status': '10', 'status_name': '审核通过'},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })['is_error'])
|
|
|
+ self.assertTrue(presenter.present('submit_goods_audit', {
|
|
|
+ 'code': 'MCP_0000',
|
|
|
+ 'data': {'goods_id': '1', 'status': '30', 'status_name': '别的'},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })['is_error'])
|
|
|
+
|
|
|
+ class CliClient:
|
|
|
+ def __init__(self):
|
|
|
+ self.calls = []
|
|
|
+
|
|
|
+ def list_enabled_tools(self, request_id=''):
|
|
|
+ return {'code': 'MCP_0000', 'data': {'tool_codes': [
|
|
|
+ 'open_goods_audit', 'submit_goods_audit',
|
|
|
+ ]}}
|
|
|
+
|
|
|
+ def call_tool(self, tool_code, route_path, payload, request_id):
|
|
|
+ self.calls.append(payload)
|
|
|
+ return {'code': 'MCP_0000', 'data': {}, 'meta': {}}
|
|
|
+
|
|
|
+ cli = CliClient()
|
|
|
+ app = GatewayApp(api_client=cli)
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ app.run_cli(['call', '--tool', 'open_goods_audit'], stdout=io.StringIO())
|
|
|
+ app.run_cli([
|
|
|
+ 'call', '--tool', 'open_goods_audit', '--sku', 'CUP-1',
|
|
|
+ '--departure-country', '中国', '--destination-country', '美国',
|
|
|
+ ], stdout=io.StringIO())
|
|
|
+ with self.assertRaises(ValueError):
|
|
|
+ app.run_cli([
|
|
|
+ 'call', '--tool', 'submit_goods_audit', '--sku', 'CUP-1',
|
|
|
+ ], stdout=io.StringIO())
|
|
|
+ app.run_cli([
|
|
|
+ 'call', '--tool', 'submit_goods_audit',
|
|
|
+ '--sku', 'CUP-1', '--audit-status', '25',
|
|
|
+ ], stdout=io.StringIO())
|
|
|
+ self.assertEqual('CUP-1', cli.calls[0]['sku'])
|
|
|
+ self.assertEqual('25', cli.calls[1]['status'])
|
|
|
+ many = presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_1401',
|
|
|
+ 'msg': '请填写商品编号',
|
|
|
+ 'data': {},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertIn('商品编号', many['text'])
|
|
|
+ many = presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_1401',
|
|
|
+ 'msg': '这个商品编号有多条,请补充起运国和目的国:客户甲,中国到美国',
|
|
|
+ 'data': {},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertIn('多条', many['text'])
|
|
|
+ missing = presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_1501',
|
|
|
+ 'msg': '商品不存在',
|
|
|
+ 'data': {},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertIn('商品不存在', missing['text'])
|
|
|
+ unknown = presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_1401',
|
|
|
+ 'msg': '别的参数错了',
|
|
|
+ 'data': {},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertTrue(unknown['is_error'])
|
|
|
+ other = presenter.present('submit_goods_audit', {
|
|
|
+ 'code': 'MCP_1501',
|
|
|
+ 'msg': '别的不可用',
|
|
|
+ 'data': {},
|
|
|
+ 'meta': {'request_id': 'rq'},
|
|
|
+ })
|
|
|
+ self.assertIn('目标数据不可用', other['text'])
|
|
|
+
|
|
|
+ def _open_error(self, presenter, data):
|
|
|
+ return presenter.present('open_goods_audit', {
|
|
|
+ 'code': 'MCP_0000', 'data': data, 'meta': {'request_id': 'rq'},
|
|
|
+ })['is_error']
|
|
|
+
|
|
|
+ def _audit_payload(self):
|
|
|
+ row = {
|
|
|
+ 'clearance_hscode': '1111.11',
|
|
|
+ 'material': '塑料',
|
|
|
+ 'material_ratio': '100',
|
|
|
+ 'kit_hscode': '',
|
|
|
+ 'adjust_hscode_data': ['9903'],
|
|
|
+ 'tax_rate': '1.00',
|
|
|
+ 'extra_tax': '',
|
|
|
+ 'is_new_hscode': '否',
|
|
|
+ 'kit_tax_rate': '0',
|
|
|
+ }
|
|
|
+ attr = {
|
|
|
+ key: False for key in (
|
|
|
+ 'is_battery', 'is_magnetic', 'is_wood', 'is_other', 'is_fda',
|
|
|
+ 'is_toy', 'is_ultra_limit', 'is_sensitive', 'is_food',
|
|
|
+ )
|
|
|
+ }
|
|
|
+ sheet = {
|
|
|
+ 'goods_id': '2683',
|
|
|
+ 'goods_clearance_id': '900',
|
|
|
+ 'shipping_method': '2',
|
|
|
+ 'goods_type': '1',
|
|
|
+ 'goods_category_id': '3',
|
|
|
+ 'category_ids': '8',
|
|
|
+ 'goods_attr': attr,
|
|
|
+ 'is_inspection_fee': 'N',
|
|
|
+ 'product_surcharge': '0',
|
|
|
+ 'tax_surcharge': '-1',
|
|
|
+ 'yf_cn_goodsname': '杯子',
|
|
|
+ 'yf_en_goodsname': 'cup',
|
|
|
+ 'yf_clearance_price': '1',
|
|
|
+ 'ys_clearance_price': '2',
|
|
|
+ 'yf_clearance_data': [dict(row)],
|
|
|
+ 'ys_clearance_data': [dict(row)],
|
|
|
+ 'is_fda_declaration': 'N',
|
|
|
+ 'is_epa_declaration': 'N',
|
|
|
+ 'is_act_declaration': 'N',
|
|
|
+ 'is_dot_declaration': 'N',
|
|
|
+ 'is_cpsc_declaration': 'N',
|
|
|
+ }
|
|
|
+ choice = {'value': '1', 'label': '甲'}
|
|
|
+ return {
|
|
|
+ 'audit_sheet': sheet,
|
|
|
+ 'options': {
|
|
|
+ 'results': [dict(choice)],
|
|
|
+ 'reject_types': [
|
|
|
+ {'value': '1', 'label': '甲', 'content': '原因'},
|
|
|
+ ],
|
|
|
+ 'product_surcharges': [dict(choice)],
|
|
|
+ 'goods_categories': [dict(choice)],
|
|
|
+ 'goods_marks': [dict(choice)],
|
|
|
+ 'cpsc_marks': {'Y': '12'},
|
|
|
+ 'shipping_methods': [dict(choice)],
|
|
|
+ 'goods_types': [dict(choice)],
|
|
|
+ 'tax_surcharges': [dict(choice)],
|
|
|
+ 'sync_orders': [{
|
|
|
+ 'order_id': '5',
|
|
|
+ 'order_number': 'SO1',
|
|
|
+ 'status_name': '已出库',
|
|
|
+ }],
|
|
|
+ },
|
|
|
+ 'reference': {
|
|
|
+ 'image_url': 'https://cdn/a.jpg',
|
|
|
+ 'recommended_grade': '一档',
|
|
|
+ 'recommended_keyword': '杯',
|
|
|
+ 'files': {
|
|
|
+ 'battery_file': [{'name': 'a.jpg', 'url': 'https://cdn/a.jpg'}],
|
|
|
+ 'fda_file': [],
|
|
|
+ 'toy_file': [],
|
|
|
+ 'other_file': [],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|