文档章节

RS UnitTest

anqiyouyou
 anqiyouyou
发布于 2017/06/26 14:37
字数 660
阅读 1
收藏 0

import os

import unittest

import tempfile

import unittest.mock as mock

from xml.dom.minidom import Document

from revitfarm.tests.basetest import BaseTest

from revitfarm.core.util.const import Const

from revitfarm.plugin.registry.autodesk.revit.regression.revitservertools import RevitServerTools

 

 

class revitservertools(BaseTest):

 

def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

self.logger = mock.MagicMock()

 

def setUp(self,):

with tempfile.TemporaryDirectory() as tmp_dir:

os.environ[Const.WORKER_APP_ROOT] = tmp_dir

local_job_package_root = os.path.join(tmp_dir, "GEN")

os.makedirs(local_job_package_root)

rs_onIIS_exe_path = os.path.join(local_job_package_root, "Regression", "_RegressionTools", "RSInstallUtils", "rsOnIIS.exe")

rs_path = os.path.join(local_job_package_root, "RevitServer", "Enterprise", "Releasex64")

rs_program = os.path.join(local_job_package_root, "Program")

version_id = "2018"

self.revitservertools = RevitServerTools(version_id, rs_onIIS_exe_path, rs_path, rs_program, logger=self.logger)

 

@mock.patch("revitfarm.plugin.registry.autodesk.revit.regression.revitservertools.gr")

def test_set_env(self, gr):

self.revitservertools.set_env("2018")

setEnv_cmd = '@reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v RSROLE' + '2018' + ' /t reg_expand_sz /d "Accelerator,Admin,Host" /f'

gr.run_simple_cmd.assert_called_once_with(setEnv_cmd, input=None, success_code=0, logger=self.logger)

 

@mock.patch("revitfarm.plugin.registry.autodesk.revit.regression.revitservertools.gr")

def test_rm_env(self, gr):

self.revitservertools.rm_env("2018")

rmEnv_cmd = '@reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v RSROLE' + '2018' + ' /f'

gr.run_simple_cmd.assert_called_once_with(rmEnv_cmd, input=None, success_code=0, logger=self.logger)

 

@mock.patch("revitfarm.plugin.registry.autodesk.revit.regression.revitservertools.gr")

def test_rsOnIIS_install(self, gr):

with tempfile.TemporaryDirectory() as tmp:

local_work_root = os.path.join(tmp, 'test_reg_job')

# rsOnIIS_exe_path = os.path.join(local_work_root, "Regression", "_RegressionTools", "RSInstallUtils", "rsOnIIS.exe")

rsOnIIS_exe_path = os.path.join(self.test_data_path, 'revitjob', 'test_revit_job.zip.rsOnIIS.exe')

rs_path = os.path.join(local_work_root, "RevitServer", "Enterprise", "Releasex64")

self.revitservertools.rsOnIIS_install('2018', rsOnIIS_exe_path, rs_path)

cmd_line = rsOnIIS_exe_path + " i=\"" + rs_path + "\" r=" + '2018' + " e"

gr.run_simple_cmd.assert_called_once_with(cmd_line, input=None, success_code=0, logger=self.logger)

 

@mock.patch("revitfarm.plugin.registry.autodesk.revit.regression.revitservertools.gr")

def test_rsOnIIS_uninstall(self, gr):

rsOnIIS_exe_path = os.path.join(self.test_data_path, 'revitjob', 'test_revit_job.zip.rsOnIIS.exe')

self.revitservertools.rsOnIIS_uninstall('2018', rsOnIIS_exe_path)

cmd_line = rsOnIIS_exe_path + " u"

gr.run_simple_cmd.assert_called_once_with(cmd_line, input=None, success_code=0, logger=self.logger)

 

def test_analyze_virtual_disk(self):

cmd = "R:\\APP\\RVT\\ECS\\pkg\\Regression\\RegressionTools\\RSInstallUtils\\rsOnIIS.exe u"

subst_result = ['R:\\: => C:\\Regfarm']

expect_result = 'C:\\Regfarm\\APP\RVT\\ECS\\pkg\\Regression\\RegressionTools\\RSInstallUtils\\rsOnIIS.exe u'

#self.revitservertools.analyze_virtual_disk(subst_result, cmd)

self.assertEqual(self.revitservertools.analyze_virtual_disk(subst_result, cmd), expect_result)

 

def test_find_word(self):

with tempfile.TemporaryDirectory() as tmp_dir:

rs_program = os.path.join(tmp_dir, "Program")

os.makedirs(rs_program)

debug_ini = os.path.join(rs_program,"Debug.ini")

word = "RegressionTestServerBasedworkflow=1"

with open(debug_ini, "w+") as file:

file.write("[DebugModes]\nRegressionTestServerBasedworkflow=1\n[DebugTests]\nRegressionTest=2")

self.assertEqual(self.revitservertools.find_word(debug_ini, word), True)

 

def test_find_word_location(self):

with tempfile.TemporaryDirectory() as tmp_dir:

rs_program = os.path.join(tmp_dir, "Program")

os.makedirs(rs_program)

debug_ini = os.path.join(rs_program, "Debug.ini")

with open(debug_ini, "w+") as file:

file.write("[DebugModes]\nRegressionTestServerBasedWorkflow=1\n[DebugTests]\nRegressionTest=2")

self.assertEqual(self.revitservertools.find_word_location(debug_ini, "[DebugModes]"), 0)

self.assertEqual(self.revitservertools.find_word_location(debug_ini, "[DebugTests]"), 49)

 

def test_insert_text(self):

with tempfile.TemporaryDirectory() as tmp_dir:

rs_program = os.path.join(tmp_dir, "Program")

os.makedirs(rs_program)

debug_ini = os.path.join(rs_program, "Debug.ini")

word = "RegressionTestServerBasedworkflow=1"

expect_word = "[DebugMode]\n"+'RegressionTestServerBasedworkflow=1'+"\n"

with open(debug_ini,"w+") as file:

file.write("[DebugMode]\n")

self.assertEqual(self.revitservertools.insert_text(debug_ini,12,word),expect_word)

 

def test_remove_text(self):

with tempfile.TemporaryDirectory() as tmp_dir:

rs_program = os.path.join(tmp_dir, "Program")

os.makedirs(rs_program)

debug_ini = os.path.join(rs_program, "Debug.ini")

word = "RegressionTestServerBasedworkflow=1"

expect = "[DebugModes]\n\n[DebugTests]\nRegressionTest=2"

with open(debug_ini, "w+") as file:

file.write("[DebugModes]\nRegressionTestServerBasedworkflow=1\n[DebugTests]\nRegressionTest=2")

self.assertEqual(self.revitservertools.remove_text(debug_ini, word), expect)

 

def test_check_create_rsn(self):

with tempfile.TemporaryDirectory() as tmp_dir:

local_work_root = os.path.join(tmp_dir, 'test_reg_job')

rs_program = os.path.join(tmp_dir, "Program")

os.makedirs(rs_program)

rsn_ini = os.path.join(rs_program, "RSN.ini")

self.revitservertools.check_create_rsn(rsn_ini)

self.assertEqual(os.path.exists(rsn_ini), True)

with open(rsn_ini, "r") as rsn:

all_text = rsn.read()

self.assertEqual(all_text, "localhost")

 

def test_check_create_debug(self):

with tempfile.TemporaryDirectory() as tmp_dir:

rs_program = os.path.join(tmp_dir,"Program")

os.makedirs(rs_program)

debug_ini = os.path.join(rs_program, "Debug.ini")

self.revitservertools.check_create_debug(debug_ini)

with open(debug_ini, "r") as f:

all_text = f.read()

expect_result = "RegressionTestServerBasedWorkflow=1" in all_text

self.assertTrue(expect_result)

 

def test_get_version_id(self):

with tempfile.TemporaryDirectory() as tmp_dir:

service_path = os.path.join(tmp_dir, "Enterprise", "Release64", "Service", "RS.Service.Protected.Model")

os.makedirs(service_path)

web_config = os.path.join(service_path, "web.config")

doc = Document()

configuration = doc.createElement("configuration")

doc.appendChild(configuration)

runtime = doc.createElement("runtime")

configuration.appendChild(runtime)

assemblyBinding = doc.createElement("assemblyBinding")

assemblyBinding.setAttribute("xmlns", "urn:schemas-microsoft-com:asm.v1")

runtime.appendChild(assemblyBinding)

dependentAssembly = doc.createElement("dependentAssembly")

assemblyBinding.appendChild(dependentAssembly)

assemblyIdentity = doc.createElement("assemblyIdentity")

assemblyIdentity.setAttribute("name", "System.Web.Extensions")

assemblyIdentity.setAttribute("publicKeyToken", "31bf3856ad364e35")

assemblyBinding.appendChild(assemblyIdentity)

system_serviceModel = doc.createElement("system.serviceModel")

configuration.appendChild(system_serviceModel)

diagnostics = doc.createElement("diagnostics")

diagnostics.setAttribute("performanceCounters", "Off")

system_serviceModel.appendChild(diagnostics)

client = doc.createElement("client")

diagnostics.appendChild(client)

endpoint1 = doc.createElement("endpoint")

endpoint1.setAttribute("address", "net.tcp://localhost/ModelService2018/Files.svc/netTcp")

endpoint1.setAttribute("binding", "TcpStreamed")

endpoint2 = doc.createElement("endpoint")

endpoint2.setAttribute("address", "net.tcp://localhost/ModelService2018/Files.svc/upload")

endpoint2.setAttribute("binding", "TcpStreamed")

endpoint3 = doc.createElement("endpoint")

endpoint3.setAttribute("address", "net.tcp://localhost/ModelService2018/Files.svc/download")

endpoint3.setAttribute("binding", "TcpStreamed")

client.appendChild(endpoint1)

client.appendChild(endpoint2)

client.appendChild(endpoint3)

bindings = doc.createElement("bindings")

system_serviceModel.appendChild(bindings)

netTcpBinding = doc.createElement("netTcpBinding")

bindings.appendChild(netTcpBinding)

with open(web_config, "w+") as file:

file.write(doc.toprettyxml(indent=" "))

result = self.revitservertools.get_version_id(web_config)

self.assertEqual(result, "2018")

 

if __name__ == "__main__":

unittest.main()

© 著作权归作者所有

共有 人打赏支持
上一篇: RS code
下一篇: 页面加载等待
anqiyouyou
粉丝 0
博文 3
码字总数 1474
作品 0
QA/测试工程师
私信 提问
如何编译google test的例子?

本博客http://blog.csdn.net/livelylittlefish 贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正! How to build samples of Google Test? In the source of google...

晨曦之光
2012/03/09
383
0
python unittest 深入failfast及实际应用【示例】

failfast是TestResult的一个属性,缺省为False, 作用: 如果failfast为True,一旦测试集中有测试案例failed或发生error立即终止当前整个测试执行,跳过剩下所有测试案例 各种用法: 实现“短路测...

laugh2last
2015/09/10
584
0
Python自动单元测试实例

Python unittest模块的相关用法 待测源码类:widget.py #!/usr/bin/env python class Widget: 测试代码类:widget_unittest.py #!/usr/bin/env python import sysimport unittestfrom widget......

长平狐
2013/01/06
27
0
Python 各种测试框架简介(二):unittest

unittest 与 doctest 一样也是 Python 发行版自带的包。如果你听说过 PyUnit(OSC 开源项目页面中就有 PyUnit 的页面),那么这俩其实是同一个东西——PyUnit 是 unittest 的曾用名,因为 Py...

lionets
2014/05/25
0
1
Python 的单元测试之 unittest

Overview Basic example 随着项目的不断扩大,单元测试在保证开发效率、可维护性和软件质量等方面的地位越发举足轻重,是一本万利的举措。Python 常用 unittest module 编写单元测试,它包含...

koala bear
2014/07/06
0
0

没有更多内容

加载失败,请刷新页面

加载更多

延迟队列实现精准的订单超时取消--自我记录备份

订单的超时取消很多系统采用定时任务,实际上达不到要求。我用的是延迟队列,但缺点是只实现了基于jvm的,分布式采用的是修改之前去查询订单状态,以及分布式锁获取的方式来控制,这样获得锁...

checkboxMan
49分钟前
2
0
storm 环境搭建

1.下载解压 下载地址:http://storm.apache.org/downloads.html #下载wget https://www-us.apache.org/dist/storm/apache-storm-1.2.2/apache-storm-1.2.2.tar.gz#解压tar -zxf apache......

MrPei
今天
1
0
Python Base - 读写文件,字符串拼接,单引号

字符转义 读写文件cvs 字符串拼接,替换 import csvcsv_file_name = 'cardbin.csv'# insert into `card_bin_code` (name_of, code_of, card_no_prefix, bank_code) values ('中国银行......

园领T
今天
1
0
基于JQUERY BOOTSTRAP 最简单的loading遮罩层

<%--loading遮罩层--%><div class="modal fade" id="loadingModal" backdrop="static" keyboard="false">   <div style="width: 200px;height:20px; z-index: 20000; position: abs......

颖辉小居
今天
1
0
springboot+kafka

1,首先springboot对kafka的支持也很好,同样是在配置文件中配置好参数,然后就可以直接使用。先说一下,很简单,,,不要怕 2,我用的依赖是 <dependency> <groupId>org.springframewor...

我真是小菜鸡
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部