文档章节

RS UnitTest

anqiyouyou
 anqiyouyou
发布于 2017/06/26 14:37
字数 660
阅读 4
收藏 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
519
0
python unittest 深入failfast及实际应用【示例】

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

laugh2last
2015/09/10
584
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
Selenium Webdriver 学习(1)--install

step 1 首先当然是安装,这边先要安装python www.python.org/download里面有两个版本可以选,一个是python3, 一个是python2,由于之前一直在用2,所以仍然选择2.7.11 step 2 安装setup-too...

terry_hding
2016/01/07
69
0

没有更多内容

加载失败,请刷新页面

加载更多

Gensim?

Gensim是一款开源的第三方Python工具包,用于从原始的非结构化的文本中,无监督地学习到文本隐层的主题向量表达。它支持包括TF-IDF,LSA,LDA,和word2vec在内的多种主题模型算法,支持流式训...

火力全開
18分钟前
0
0
图片验证码

图片验证码,线上登录是最常见的场景,也有发送手机验证码之前进行图片验证码的验证。 图片验证码很大程度上防止机器人撞库登录或频繁发起短信验证码从而使系统暂时性"瘫痪"。 以下是项目中用...

貔貅叔
21分钟前
1
0
科班出身程序员和培训出来的程序员区别在哪?

科班出身只是代表你要从事的职业和你的专业是一致的,代表着你具备了得天独厚的优势,至于是不是优势看你上班好不好学,平时逃课没,上班是认真听还是玩手机。一般而言科班出来的理论性比较强...

java菜分享
22分钟前
0
0
java框架学习日志-8(AOP简介)

小王被委托开发一款游戏,程序分为启动页面,登陆页面,战斗页面等。小王就采用了面向对象编程思想(OOP),把整个程序分解成下图 这种就是传统的自上而下的编程,或者说纵向的编程,负责启动...

白话
22分钟前
2
0
简易ZK分布式锁实现与测试

分布式锁创建以及销毁 public class ZKLock { private String node; public String path = "/lock"; ZkClient zkClient = new ZkClient("192.168.0.239"); public......

zzx10
23分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部