-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportPythonFileTC.php
141 lines (117 loc) · 4.34 KB
/
exportPythonFileTC.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/* @file exportPythonFile.php
* @brief Allow to write the Python File using the TestCase ID and the Test Plan XML File
* From TestLink 1.9.12 XML TestSuite export
* @author Samuel Salas (2015)
* @version 01.01
*/
header('content-type: plain/text; charset=utf-8');
/* Receiving GET info */
$testCaseId = (int) $_GET["testcaseid"];
$testSuiteId = (int) $_GET["testsuiteid"];
$filename = "TestSuite".$testSuiteId."_Case".$testCaseId.".py";
header("Content-Disposition: attachment; filename=".$filename);
$testCaseId_str = (string) $_GET["testcaseid"];
$testSuiteId_str = (string) $_GET["testsuiteid"];
/**
* Need the IXR class for client
*/
define("THIRD_PARTY_CODE","../third_party");
require_once THIRD_PARTY_CODE . '/xml-rpc/class-IXR.php';
require_once 'config.php';
$server_url = TL_TESTLINK_SERVERURI . "/lib/api/xmlrpc/v1/xmlrpc.php";
$args=array();
$args["devKey"]=isset($_REQUEST['apiKey']) ? $_REQUEST['apiKey'] : TL_TESTLINK_API_KEY;
$args["testcaseid"]= (int) $_GET["testcaseid"];
$args["version"]=1;
$debug=true;
$clientIXR = new IXR_Client($server_url);
$client->debug=$debug;
if(!$clientIXR->query("tl.getTestCase", $args)) {
$client=null;
} else {
$client=$clientIXR->getResponse();
}
// ----------------------------
// Global functions
// ----------------------------
/** @brief Return string without tags and special chars
* @param $comment string to process
* @return Return the string without the special char in the array
*/
function extract_tagsAndSpecialChar($comment) {
$tag = array("<p>", "</p>", "\n", "\t");
$tmpStr1 = str_replace($tag, "", $comment);
// replace special chars
$tmpStr2 = str_replace("é", "é", $tmpStr1);
$tmpStr1 = str_replace("à", "à", $tmpStr2);
$tmpStr2 = str_replace("è", "è", $tmpStr1);
$tmpStr1 = str_replace(" ", " ", $tmpStr2);
$tmpStr2 = str_replace("ê", "ê", $tmpStr1);
$tmpStr1 = str_replace("â", "â", $tmpStr2);
$tmpStr2 = str_replace("ë", "ë", $tmpStr1);
$tmpStr1 = str_replace("î", "î", $tmpStr2);
$tmpStr2 = str_replace("ù", "ù", $tmpStr1);
$tmpStr1 = str_replace("ç", "ç", $tmpStr2);
return $tmpStr1;
}
// ----------------------------
// TEXT format functions
// ----------------------------
function function_python($word) {
return " def "
.$word
."(self):\r\n";
}
function class_python($word) {
return "class "
.$word
."(object):\r\n";
}
function comment_file_python($word) {
$retVal = '""" '."\r\n"
.' '.$word."\r\n"
.'"""'."\r\n";
return $retVal;
}
function comment_class_python($word) {
$retVal = " ".'""" '.$word."\r\n"
." ".'"""'."\r\n";
return $retVal;
}
function comment_def_python($word) {
$retVal = " ".'""" '.rtrim($word)."\r\n"
." ".'"""'."\r\n";
return $retVal;
}
// ----------------------------
// MAIN : writing the file
// ----------------------------
if ($client != null) {
$case = $client[0];
include("headerPython.txt");
// Filtering with the test case ID
$returnTxt = class_python("TestCase".$case["testcase_id"]);
$returnTxt .= comment_class_python($case["name"]);
$returnTxt .= function_python("__init__");
$returnTxt .= comment_def_python("Initialization of the class");
$returnTxt .= " pass\r\n\r\n";
$returnTxt .= function_python("setup");
$returnTxt .= comment_def_python("Put here actions before the first test case");
$returnTxt .= " pass\r\n\r\n";
$returnTxt .= function_python("teardown");
$returnTxt .= comment_def_python("Put here actions after the last test case");
$returnTxt .= " pass\r\n\r\n";
foreach($case["steps"] as $step) {
$returnTxt .= function_python("test_".(string) $step["step_number"]);
$tmpStr = extract_tagsAndSpecialChar((string) $step["actions"]);
$returnTxt .= comment_def_python($tmpStr);
$returnTxt .= " assert False #Expected result ".extract_tagsAndSpecialChar((string) $step["expected_results"]);
$returnTxt .= "\r\n\r\n";
}
} else {
$returnTxt .= "This page has not converted a Test Case Number from TestLink 1.9.12 into Nosetests Python scripts using the 'class' method.\r\n";
$returnTxt .= "Something went wrong - " . $clientIXR->getErrorCode() . " - " . $clientIXR->getErrorMessage();
}
echo $returnTxt;
?>