Added creation of a python stack class

This commit is contained in:
NissimHadar 2018-07-27 09:04:37 -07:00
parent 78cf29619e
commit be79fa9e31
2 changed files with 49 additions and 2 deletions

View file

@ -28,9 +28,9 @@ TestRailInterface::TestRailInterface() {
_testRailSelectorWindow.setProject(24);
}
// Creates the testrail.py script
// This is the file linked to from http://docs.gurock.com/testrail-api2/bindings-python
void TestRailInterface::createTestRailDotPyScript(const QString& outputDirectory) {
// Create the testrail.py script
// This is the file linked to from http://docs.gurock.com/testrail-api2/bindings-python
QFile file(outputDirectory + "/testrail.py");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__),
@ -135,6 +135,46 @@ void TestRailInterface::createTestRailDotPyScript(const QString& outputDirectory
file.close();
}
// Creates a Stack class
void TestRailInterface::createStackDotPyScript(const QString& outputDirectory) {
QFile file(outputDirectory + "/stack.py");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__),
"Could not create \'stack.py\'");
exit(-1);
}
QTextStream stream(&file);
stream << "class Stack:\n";
stream << "\tdef __init__(self):\n";
stream << "\t\tself.items = []\n";
stream << "\n";
stream << "\tdef isEmpty(self):\n";
stream << "\t\treturn self.items == []\n";
stream << "\n";
stream << "\tdef push(self, item):\n";
stream << "\t\tself.items.append(item)\n";
stream << "\n";
stream << "\tdef pop(self):\n";
stream << "\t\treturn self.items.pop()\n";
stream << "\n";
stream << "\tdef peek(self):\n";
stream << "\t\treturn self.items[len(self.items)-1]\n";
stream << "\n";
stream << "\tdef size(self):\n";
stream << "\t\treturn len(self.items)\n";
stream << "\n";
file.close();
}
void TestRailInterface::requestDataFromUser() {
_testRailSelectorWindow.exec();
@ -145,6 +185,7 @@ void TestRailInterface::requestDataFromUser() {
_url = _testRailSelectorWindow.getURL();
_user = _testRailSelectorWindow.getUser();
_password = _testRailSelectorWindow.getPassword();
_project = _testRailSelectorWindow.getProject();
}
void TestRailInterface::createAddSectionsPythonScript(const QString& outputDirectory) {
@ -163,10 +204,13 @@ void TestRailInterface::createAddSectionsPythonScript(const QString& outputDirec
stream << "client.user = \'" << _user << "\'\n";
stream << "client.password = \'" << _password << "\'\n\n";
// top-level section
stream << "data = { \'name\': \'"
<< "Test Suite - " << QDateTime::currentDateTime().toString("yyyy-MM-ddTHH:mm") << "\'}\n";
stream << "section = client.send_post(\'add_section/\' + str(" << QString::number(_project) << "), data)";
file.close();
}
@ -176,6 +220,7 @@ void TestRailInterface::createTestSuitePython(const QString& testDirectory,
const QString& branch) {
createTestRailDotPyScript(outputDirectory);
createStackDotPyScript(outputDirectory);
requestDataFromUser();
createAddSectionsPythonScript(outputDirectory);
}

View file

@ -38,6 +38,7 @@ public:
QDomElement processTest(const QString& fullDirectory, const QString& test, const QString& user, const QString& branch, const QDomElement& element);
void createTestRailDotPyScript(const QString& outputDirectory);
void createStackDotPyScript(const QString& outputDirectory);
void requestDataFromUser();
void createAddSectionsPythonScript(const QString& outputDirectory);
@ -49,6 +50,7 @@ private:
QString _url;
QString _user;
QString _password;
int _project;
};
#endif