WeChat Search [Daqi Test Open] focuses on this fellow who insists on sharing test development dries.
Continuing to test and develop the sharing of the real-world series, this article implements the editing function of the query function of the query platform. The main focus is on the logical implementation of the mail content labeling in the service-side update interface, and adapting and transforming the basis of the previous requirement added in the front-end.
TPMServerQuery Details Interface
Joint table queries are made on the data table request s and apps based on the query ID, and detailed information is returned. This interface is used for data backfilling in front-end jumps to edit the query page.
# testmanager.py @test_manager.route("/api/test/info", methods=['GET']) def getTestInfo(): test_id = request.args.get('id') resp_success = format.resp_format_success resp_failed = format.resp_format_failed if not test_id: resp_failed.message = 'Assumption ID Cannot be empty' return resp_failed connection = pool.connection() with connection.cursor() as cursor: # Query Product Information Table - Sort New and Old by Update Time sql = "SELECT A.id as appId, A.appId as appName, R.id,R.title,R.developer,R.tester,R.CcMail,R.version,R.type,R.scope,R.gitCode,R.wiki,R.more FROM request as R , apps as A where R.appId = A.id AND R.isDel=0 AND R.id={}".format(test_id) cursor.execute(sql) data = cursor.fetchall() if len(data) == 1: resp_success['data'] = data[0] return resp_success
Proposal Modification Interface
To propose an update interface, which is not handled in the same way as before. The main reason is that there is a special logic processing, which separates the interface code to make the structure clearer. This special processing logic needs to compare which of the following is changed, and then if the option to send is checked, it can be marked below. This makes it meaningful to modify the notification message. Logically, this is roughly:
1. Query to temporarily store A in a variable before changing data
2. Update the database with variable B
3. If you check Send E-mail, send content field values for AB comparison, different background highlighting or before and after labeling processing, the code uses the tag A. Some content changes to: B. Some content
@test_manager.route("/api/test/update", methods=['POST']) def updateReqeust(): # Get the passed data and convert it to JSON body = request.get_data() body = json.loads(body) # Define Default Return Body resp_success = format.resp_format_success resp_failed = format.resp_format_failed if 'appId' not in body: resp_failed['message'] = 'appId Query application cannot be empty' return resp_failed elif 'tester' not in body: resp_failed['message'] = 'tester Tester cannot be empty' return resp_failed elif 'developer' not in body: resp_failed['message'] = 'developer The presenter cannot be empty' return resp_failed elif 'title' not in body: resp_failed['message'] = 'title Question Title cannot be empty' return resp_failed # Linking databases using connection pools connection = pool.connection() with connection: with connection.cursor() as cursor: sql = "SELECT A.appId as appId, A.note as appName, R.id,R.title,R.developer,R.tester,R.CcMail,R.version,R.type,R.scope,R.gitCode,R.wiki,R.more FROM request as R , apps as A where R.appId = A.id AND R.isDel=0 AND R.id={}".format( body['id']) cursor.execute(sql) data = cursor.fetchall() if len(data) == 1: old_test_info = data[0] else: print('Existing data request query exception!') # Modify the value if it has an ID, otherwise add data with connection.cursor() as cursor: # Splice modify statement, no duplicate checking appId is required because the application name is not modifiable sqlUpdate = "UPDATE request SET title=%s,appId=%s,developer=%s,tester=%s,CcMail=%s,version=%s,`type`=%s," \ "scope=%s,gitCode=%s,wiki=%s,`more`=%s,updateUser=%s,`updateDate`= NOW() WHERE id=%s" cursor.execute(sqlUpdate, ( body["title"], body["appId"], body["developer"], body['tester'], body["CcMail"], body["version"], body["type"], body["scope"], body["gitCode"], body["wiki"], body["more"], body["updateUser"], body["id"])) # Submit Execution Save Update Data connection.commit() if 'isEmail' in body and body['isEmail'] == 'true': # New Successful Email Send if body['type'] == 1: rquest_type = 'functional testing' elif body['type'] == 2: rquest_type = 'performance testing' elif body['type'] == 3: rquest_type = 'Security Test' receivers = body["tester"].split(',') + body["developer"].split(',') if not body["CcMail"] is None: receivers = receivers + body["CcMail"].split(',') subject = '[Guess)' + body['title'] contents = [] contents.append('<strong>[Presentation application]</strong>') if old_test_info and old_test_info['appName'] != body['appName']: contents.append(old_test_info['appName'] + 'Change to:' + body['appName']) else: contents.append(body['appName']) contents.append('<strong>[Proposer]</strong>') if old_test_info and old_test_info['developer'] != body['developer']: contents.append(old_test_info['developer'] + 'Change to:' + body['developer']) else: contents.append(body['developer']) contents.append('<strong>[Probe Version]</strong>') if old_test_info and old_test_info['version'] != body['version']: contents.append(old_test_info['version'] + 'Change to:' + body['version']) else: contents.append(body['developer']) contents.append('<strong>[Test Content]</strong>') if old_test_info and old_test_info['scope'] != body['scope']: contents.append(old_test_info['scope'] + 'Change to:' + body['scope']) else: contents.append(body['scope']) contents.append('<strong>[Related Documents]</strong>') if old_test_info and old_test_info['wiki'] != body['wiki']: contents.append(old_test_info['wiki'] + 'Change to:' + body['wiki']) else: contents.append(body['wiki']) contents.append('<strong>[Supplementary Information]</strong>') if old_test_info and old_test_info['more'] != body['more']: contents.append(old_test_info['more'] + 'Change to:' + body['more']) else: contents.append(body['more']) reuslt = sendEmail(receivers, subject,contents) if reuslt: sendOk = 1 else: sendOk = 2 with connection.cursor() as cursor: # Update Emai Send Success 1-Success 2-Failure updateEmail = "UPDATE request SET sendEmail=%s, updateUser=%s,`updateDate`= NOW() WHERE id=%s" cursor.execute(updateEmail, (sendOk, body["updateUser"], body['id'])) # Successful submission of modified mail connection.commit() else: print('Don't send mail!') return resp_success
These are the two interfaces used in this function. Please use tools such as postman to verify them.
TPMWeb
Define Request Interface
First define the back-end interface requests, then just add two requests to test.js from the last share
Edit jump and get with parameters
Add a click event to the menu list page and implement the method, this time using URL with parameters. If you don't know several ways to jump Vue $router, refer to the previous article Test Development [Tip Platform] #13 Remote Search and Routing $route Use for New Tip Requirements In addition to giving UPDATE to the action parameter value, a jump also needs to give the ID of the selected edit data to be used for the query after the jump. Of course, a row of data can be implicitly passed to it via param, but this is not recommended.
The commit page does not use the whole row of data from the previous page, mainly considering that the page may refresh the browser, if it is implicit data will be lost, and the parameters in the URL will not, can be retrieved again, you can try to make a difference. Here, the original action and new parameter id judgment need to be obtained, and the query initialization of the proposed information.
Proposal Detailed Backfill Processing
The code logic for getTestInfo is to implement a query and bind the required field values to a requestForm, and this code also requires two special processes that require special attention:
1. The applied ID remote search drop-down box bindings require code-triggered queries, and user Label-value backfills
2.Delay 200-300 seconds to bind appId, or there will be a small problem when you don't jump to the page, that is, show the appId first, then show a process of appName, you can comment out the setTimeout, directly this.requestForm.appId = data.appId for comparison.
getTestInfo() { apiTestInfo(this.testId).then(response => { const data = response.data this.requestForm.id = data.id this.requestForm.title = data.title this.requestForm.developer = data.developer this.requestForm.tester = data.tester this.requestForm.CcMail = data.CcMail this.requestForm.version = data.version this.requestForm.type = data.type this.requestForm.scope = data.scope this.requestForm.gitCode = data.gitCode this.requestForm.wiki = data.wiki this.requestForm.more = data.more this.requestForm.appName = data.appName this.requestForm.isEmail = false this.remoteMethod(data.appName) // this.requestForm.appId = data.appId setTimeout(() => { this.requestForm.appId = data.appId }, 300) }) }
Page Support Modification
The template section requires changes or additions as shown in Figure 3 in order to support the implementation of the modification function
1. Display the title according to the jump action
2. Judgment is a change of action, showing ID information, state is not changeable
3. Add a modify button, use v-if to judge the action, or use a button directly to judge the text description, for example
<el-button type="primary" @click="onSubmit">{}</el-button>
Modify data submission
The last modification to the proposed edit page is the submission of data, which, like ADD logic, only changes the next request API.
Debugging Test
Is code written or a system test is required to verify functionality
CASE-1: Create a new hypothesis to verify that the added functionality is affected by the new modified functionality.
CASE-2: Modify the newly created suggestion, check the data query backfill, especially if the service application displays correctly, modify some field values, and submit changes;
CASE-3: Check that all messages are received properly, and modify whether messages are labeled as expected.
Leave a small optimization job at the end of the article. Can you format your email with the HTML template knowledge explained earlier to make it look better?
[Code Update]
-
Address: https://github.com/mrzcode/TestProjectManagement
-
TAG: TPMShare15
Stick to the originality, practice and dry goods. If you find it useful, click on the recommendation, and also welcome to pay attention to my blog Park and WeChat Public Number.