Ejemplo n.º 1
0
    def GetTotalErrors(self):
        if (self.TotalErrors == 0):
            self.TotalErrors = string_utilities._unicode(
                file.LoadFile(conf.core_path + "templates/inc_rep_1." +
                              self.GetType()))

        return (self.TotalErrors)
Ejemplo n.º 2
0
    def GetTimeStat(self):
        if (self.TimeStat == 0):
            self.TimeStat = string_utilities._unicode(
                file.LoadFile(conf.core_path + "templates/inc_3." +
                              self.GetType()))

        return (self.TimeStat)
Ejemplo n.º 3
0
    def GetTableFooter(self):
        if (self.TableFooter == 0):
            self.TableFooter = string_utilities._unicode(
                file.LoadFile(conf.core_path + "templates/inc_2." +
                              self.GetType()))

        return (self.TableFooter)
Ejemplo n.º 4
0
def FindStringInFile(SearchString, FilePath):
    if (file.FileExists(SearchString)):
        FileContent = file.LoadFile(FilePath)
        if (string.find(FileContent, SearchString) != -1):
            return (1)
        else:
            return (0)
    else:
        return (0)
Ejemplo n.º 5
0
def FileMatchesRegexp(RegexpPattern, FilePath):
    if (file.FileExists(SearchString)):
        RegexpObject = re.compile(RegexpPattern, re.MULTILINE | re.UNICODE)
        FileContent = file.LoadFile(FilePath)
        if (RegexpObject.match(FileContent) == None):
            return (0)
        else:
            return (1)
    else:
        return (0)
Ejemplo n.º 6
0
def RunTests():
    # чистим директорию с логами
    file.ClearDirectory(conf.tests_path + "../logs")

    # Начинаем искать все манифесты
    Manifests = utilities.GetManifests()
    TestCounter = utilities.GetTestCount(Manifests)

    ReportBuilder = log_builder.LogBuilder()
    ReportBuilder.Set(
        "table_header", {
            "#test_count#":
            str(TestCounter),
            "#file#":
            string_utilities._unicode(lang.GetString("file"), 'utf-8'),
            "#avg_execution_time#":
            string_utilities._unicode(lang.GetString("avg_execution_time"),
                                      'utf-8'),
            "#execution_time#":
            string_utilities._unicode(lang.GetString("execution_time"),
                                      'utf-8'),
            "#result#":
            string_utilities._unicode(lang.GetString("result"), 'utf-8'),
            "#tester#":
            string_utilities._unicode(lang.GetString("tester"), 'utf-8'),
            "#testers_email#":
            string_utilities._unicode(lang.GetString("testers_email"),
                                      'utf-8'),
            "#description#":
            string_utilities._unicode(lang.GetString("description"), 'utf-8')
        })
    StartTime = time.time()
    ReportBuilder.Set(
        "time_stat", {
            "#autotesting_start_time_label#":
            string_utilities._unicode(
                lang.GetString("autotesting_start_time_label")),
            "#autotesting_start_time#":
            time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time()))
        })

    i = 0
    Success = 0
    Error = 0
    TesterSuccess = {}
    TesterError = {}
    Testers = []
    TestersEmails = []

    # Пробегаем по всем найденным тестам и запускаем их
    for ManifestPath in Manifests:
        # загружаем манифест
        Manifest = config_processor.SAXConfigProcessor()
        Manifest.LoadConfig(ManifestPath)

        if (utilities.NeedToRun(
                str(Manifest.GetTagByName("label").GetAttributeValue("value")),
                str(
                    Manifest.GetTagByName("author").GetAttributeValue(
                        "email"))) == 0):
            continue

        # чистим рабочую директорию
        file.ClearDirectory(conf.workspace_path)

        # тут просто подсвечиваем выполняемый автотест, чтобы не казалось что все зависло
        utilities.PrintStr(ManifestPath)

        SubTestsCount = 0
        SubTestsCount = utilities.GetSubTestCount(Manifest)

        for j in range(SubTestsCount):
            # запускаем каждый подтест
            if (utilities.TestIdInList(j, Manifest) == 0):
                continue
            Log = utilities.RunTest(j, Manifest, ManifestPath)
            LogFile = Log[0]
            TestName = Log[1]

            if (Manifest.GetTagByName("type").GetAttributeValue(
                    "value", "py") == 'unittest'):
                if (str(LogFile).lower().find("failed") == -1):
                    ErrorFlag = 1
                else:
                    ErrorFlag = 0
            else:
                if (str(LogFile).lower().find("test passed") == -1):
                    ErrorFlag = 1
                else:
                    ErrorFlag = 0
            RowColor = log_builder.GetRowColor(i, ErrorFlag)

            # формируем необходимые данные
            if (not str(
                    Manifest.GetTagByName("author").GetAttributeValue("name"))
                    in TesterError.keys()):
                TesterError[Manifest.GetTagByName("author").GetAttributeValue(
                    "name")] = 0
                TesterSuccess[Manifest.GetTagByName(
                    "author").GetAttributeValue("name")] = 0
                Testers.append(
                    Manifest.GetTagByName("author").GetAttributeValue("name"))
                TestersEmails.append(
                    Manifest.GetTagByName("author").GetAttributeValue("email"))

            if (ErrorFlag):
                Error = Error + 1
                TesterError[Manifest.GetTagByName("author").GetAttributeValue(
                    "name")] = TesterError[Manifest.GetTagByName(
                        "author").GetAttributeValue("name")] + 1
            else:
                Success = Success + 1
                TesterSuccess[Manifest.GetTagByName(
                    "author").GetAttributeValue(
                        "name")] = TesterSuccess[Manifest.GetTagByName(
                            "author").GetAttributeValue("name")] + 1

            Data = {
                "#row_id#": str(i),
                "#row_color#": RowColor,
                "#test_id#": "%(#)05d" % {
                    "#": i
                },
                "#script_path#": os.path.basename(ManifestPath) + TestName
            }

            LogFileName = file.GetRandomFileName()
            LogFilePath = "./logs/" + LogFileName + ".html"

            LogOpenProtocol = ''
            if (LogFilePath.find(':') != -1):
                LogOpenProtocol = 'file://'

            Data["#test_log_file_name#"] = ReportBuilder.GetLogFileName()

            if ("-blank" in sys.argv):
                LogTarget = 'target="_blank"'
            else:
                LogTarget = ''

            LogFile = string_utilities.ProcessLog(LogFile)

            if (utilities.ApplyHTMLFormatToLog(Manifest)):
                LogFile = LogFile.replace("\n", "<br>").replace(" ", "&nbsp;")

            if ("-external" in sys.argv):
                if (ErrorFlag == 1):
                    Data[
                        "#log#"] = 'ERROR&nbsp;[<a href="' + LogOpenProtocol + LogFilePath + '" ' + LogTarget + '>log</a>]'
                else:
                    Data[
                        "#log#"] = 'TEST&nbsp;PASSED&nbsp;[<a href="' + LogOpenProtocol + LogFilePath + '" ' + LogTarget + '>log</a>]'
            else:
                Data["#log#"] = LogFile

            Data["#tester#"] = Manifest.GetTagByName(
                "author").GetAttributeValue("name")
            Data["#email#"] = Manifest.GetTagByName(
                "author").GetAttributeValue("email")
            Data["#dsc#"] = Manifest.GetTagByName(
                "description").GetAttributeValue("value")
            Data["#total_execution_time#"] = str(Log[2])
            Data["#avg_execution_time#"] = str(Log[3])

            if ("-external" in sys.argv):
                file.WriteFile(
                    LogFilePath,
                    string_utilities.MassiveReplace(
                        file.LoadFile(conf.core_path +
                                      "templates/separate_log_1." +
                                      ReportBuilder.GetType()), Data))
                file.WriteFile(LogFilePath, LogFile)
                file.WriteBinaryFile(
                    LogFilePath,
                    string_utilities.StrToBytes(
                        string_utilities.MassiveReplace(
                            file.LoadFile(conf.core_path +
                                          "templates/separate_log_2." +
                                          ReportBuilder.GetType()), Data)))

            ReportBuilder.Set("report_row", Data)
            i = i + 1

    Data = {
        "#total_statistics#":
        string_utilities._unicode(lang.GetString("total_statistics"), 'utf-8'),
        "#total_tests#":
        string_utilities._unicode(lang.GetString("total_tests"), 'utf-8'),
        "#total_error_tests#":
        string_utilities._unicode(lang.GetString("total_error_tests"),
                                  'utf-8'),
        "#total_success_tests#":
        string_utilities._unicode(lang.GetString("total_success_tests"),
                                  'utf-8'),
        "#per_tester_statistics#":
        string_utilities._unicode(lang.GetString("per_tester_statistics"),
                                  'utf-8'),
        "#total_tests_count#":
        str(i),
        "#total_error_tests_count#":
        str(Error),
        "#total_success_tests_count#":
        str(Success)
    }

    if (i == 0):
        # тестов нет
        Data["#prs_error#"] = str(0.0 / 1.0)
        Data["#prs_success#"] = str(100.0 / 1.0)
    else:
        Data["#prs_error#"] = str(Error / (i * 1.0) * 100.0)
        Data["#prs_success#"] = str(Success / (i * 1.0) * 100.0)

    ReportBuilder.Set("total_errors", Data)

    for TesterName in Testers:
        ReportBuilder.Set(
            "individual_errors", {
                "#tester_name#":
                TesterName,
                "#tester_error_count#":
                str(TesterError[TesterName]),
                "#tester_success_count#":
                str(TesterSuccess[TesterName]),
                "#tester_error#":
                string_utilities._unicode(lang.GetString("tester_error"),
                                          'utf-8'),
                "#tester_success#":
                string_utilities._unicode(lang.GetString("tester_success"),
                                          'utf-8')
            })

    ReportBuilder.Set(
        "time_stat", {
            "#autotesting_end_time_label#":
            string_utilities._unicode(
                lang.GetString("autotesting_end_time_label"), 'utf-8'),
            "#autotesting_end_time#":
            time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time())),
            "#autotesting_time_label#":
            string_utilities._unicode(lang.GetString("autotesting_time_label"),
                                      'utf-8'),
            "#autotesting_time#":
            time.strftime("%H:%M:%S", time.gmtime(time.time() - StartTime))
        })

    # осуществляем финальную чистку рабочей директории
    file.ClearDirectory(conf.workspace_path)

    ReportBuilder.Compile()

    utilities.ProcessShowLogCommand(ReportBuilder)

    utilities.SendLogsByEmail(ReportBuilder, TestersEmails)

    utilities.SendLogsByFtp(ReportBuilder)

    print("done")
Ejemplo n.º 7
0
 def Parse(self, theFilePath):
     self.feed(file.LoadFile(theFilePath))
     self.close()
Ejemplo n.º 8
0
def ProcessHelpCommand():
    # Понеслась отработка скрипта
    if ("-help" in sys.argv):
        # Выводим мануал
        print(file.LoadFile(conf.core_path + "templates/man"))
        sys.exit(0)
Ejemplo n.º 9
0
def SendLogsByEmail(LogObject, TestersEmails):
    import lang
    try:
        if ('-send_logs' in sys.argv):
            if (sys.version_info[0] < 2 or
                (sys.version_info[0] == 2 and sys.version_info[1] <= 1)):
                print(
                    'Sending logs via email is not provided for Python v 2.1 and lower'
                )
                return

            # создаем архив с логами
            Logs = GetFiles(conf.workspace_path + '../logs/')

            Archive = zipfile.ZipFile(
                conf.workspace_path + LogObject.GetLogFileName(1) + '.zip',
                'w')

            for Log in Logs:
                LogsFileName = os.path.split(Log)[1]

                Archive.write(Log, 'logs/' + LogsFileName)

            Archive.write(
                conf.workspace_path + '../' + LogObject.GetLogFileName(),
                LogObject.GetLogFileName())

            Archive.close()

            # отправляем логи
            From = 'run.py@localhost'

            # архив с логами готов, теперь можно запускать письмо
            RawMessage = file.LoadFile(conf.core_path +
                                       'templates/autotest_log.eml')
            RawMessage = RawMessage.replace('#from#', From)
            RawMessage = RawMessage.replace(
                '#subject#', lang.GetString('testing_mail_subject'))
            RawMessage = RawMessage.replace(
                '#autotest_log_file_name#',
                LogObject.GetLogFileName(1) + '.zip')

            LogArchiveContent = base64.b64encode(
                file.LoadBinaryFile(conf.workspace_path +
                                    LogObject.GetLogFileName(1) + '.zip'))
            LogArchiveContent = string_utilities.BytesToStr(
                LogArchiveContent, 'utf-8')

            for i in range(0, math.ceil(len(LogArchiveContent) / 80) - 1):
                SubString = LogArchiveContent[i * 80:(i + 1) * 80]
                RawMessage = RawMessage.replace(
                    '#autotest_log_content#',
                    SubString + "\r\n#autotest_log_content#")

            RawMessage = RawMessage.replace('#autotest_log_content#', '')

            MailServer = smtplib.SMTP()
            MailServer.connect(conf.email_server_host, conf.email_server_port)

            for To in TestersEmails:
                Message = RawMessage.replace('#to#', To)
                MailServer.sendmail(From, To, Message)

            if (conf.extra_emails != ''):
                for To in conf.extra_emails.split(','):
                    Message = RawMessage.replace('#to#', To)
                    MailServer.sendmail(From, To, Message)

            MailServer.quit()

            os.unlink(conf.workspace_path + LogObject.GetLogFileName(1) +
                      '.zip')
    except:
        print('An error occured while sending logs via email')
Ejemplo n.º 10
0
 def GetReportRows(self):
     return (string_utilities._unicode(
         file.LoadFile(conf.core_path + "templates/inc_4." +
                       self.GetType())))
Ejemplo n.º 11
0
 def GetIndividualErrors(self):
     return (string_utilities._unicode(
         file.LoadFile(conf.core_path + "templates/inc_rep_2." +
                       self.GetType())))