文档章节

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()

© 著作权归作者所有

共有 人打赏支持
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 各种测试框架简介(二):unittest

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

lionets
2014/05/25
0
1
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

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

koala bear
2014/07/06
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

arts-week5

Algorithm 824. Goat Latin - LeetCode 152. Maximum Product Subarray - LeetCode 110. Balanced Binary Tree - LeetCode 67. Two Sum II - Input array is sorted - LeetCode 665. Non-dec......

yysue
22分钟前
0
0
iOS开发之AddressBook框架详解

iOS开发之AddressBook框架详解 一、写在前面 首先,AddressBook框架是一个已经过时的框架,iOS9之后官方提供了Contacts框架来进行用户通讯录相关操作。尽管如此,AddressBook框架依然是一个非...

珲少
52分钟前
1
0
两年摸爬滚打 Spring Boot,总结了这 16 条最佳实践

Spring Boot是最流行的用于开发微服务的Java框架。在本文中,我将与你分享自2016年以来我在专业开发中使用Spring Boot所采用的最佳实践。这些内容是基于我的个人经验和一些熟知的Spring Boot...

Java填坑之路
今天
4
0
《Spring5学习》04 - 面向切面编程

一、Spring面向切面编程的基本概念 面向切面编程(即AOP):把项目中需要再多处使用的功能比如日志、安全和事务等集中到一个类中处理,而不用在每个需要用到该功能的地方显式调用。 横切关注...

老韭菜
今天
2
0
day61-20180819-流利阅读笔记

跑道没了,它们还在跑:澳门赛狗业的遗孤 Daniel 2018-08-19 1.今日导读 相信你早就知道香港有个赛马会,可是你听说过香港的邻居澳门原本有个赛狗会吗?其实,对于澳门人来说,赛狗这项活动历...

aibinxiao
今天
15
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部