Package tlib :: Package base :: Module SpiraModerator
[hide private]
[frames] | no frames]

Source Code for Module tlib.base.SpiraModerator

  1  from suds.xsd.doctor import Import, ImportDoctor 
  2  import suds 
  3  from SoapRequestor import SoapRequestor 
  4   
  5   
6 -class SpiraModerator(object):
7 """ 8 Helper class to connect and manipulate the data in SpiraTest 9 """ 10 11 client = None #: Soap client to connect to Spira Soap API 12 username = "ypgAutoTester" #: Automation User username (restricted access to SpiraTest) 13 password = "@ut0t3$t3r" #: Automation User password 14 tests = None #: Holds retrieved tests from Automation test set in Spiratest 15 logger = None #: logger to send loggin information to. Logger comes from pytest test definitions 16 my_soap = None 17
18 - def __init__(self, logger):
19 """ 20 Constructor for class 21 22 Args : 23 logger : (logger) instance of a logging object configured in testing project 24 25 """ 26 27 self.logger = logger 28 wsdl_file = "http://mtljiraqcprod01.ad.ypg.com/SpiraTeam/Services/v4_0/ImportExport.svc?wsdl" 29 schema_url = 'http://schemas.microsoft.com/2003/10/Serialization/Arrays' 30 schema_import = Import(schema_url) 31 schema_doctor = ImportDoctor(schema_import) 32 33 self.my_soap = SoapRequestor(self.logger, wsdl_file, schema_doctor)
34
35 - def test_connect(self):
36 """ 37 Authenticates client with SpiraTest. 38 39 Returns : (bool) if connection was successful 40 """ 41 42 result = False 43 try: 44 result = self.my_soap.client.service.Connection_Authenticate(self.username, self.password) 45 except suds.WebFault, e: 46 self.logger.error(str(e)) 47 48 self.logger.info("The connection to Spira returned :" + str(result)) 49 50 return result
51
52 - def update_test_case(self, project_id, test_case_id, test_start, test_end, test_status_id, runner_msg, 53 stack_trace, test_set_id):
54 """ 55 Updates a specified test cases with a specified projects Automation test set with the results of the test execution 56 57 Args : 58 project_id : (int) Unique project id from within SpiraTest 59 test_case_id : (int) Unique test case id from within SpiraTest 60 test_start : (datetime) Time at which the test case started its execution. Doesn't seem to affect Spiratest. 61 test_end : (datetime) Time at which the test case ended its execution. Doesn't seem to affect Spiratest. 62 runner_msg : (str) Parameters that were used in test execution 63 stack_trace : (str) Error message returned from failed test cases 64 65 """ 66 67 self.my_soap.client.service.TestRun_RecordAutomated2(self.username, self.password, project_id, None, 68 test_case_id, None, test_set_id, None, None, test_start, 69 test_end, test_status_id, "None", None, 1, 70 runner_msg, stack_trace, 1)
71
72 - def get_project_id(self, proj_name):
73 """ 74 Gets the Unique prject id from spiratest for a given project name. Name comes from project's config file 75 76 Args : proj_name : (str) Name of project under test 77 78 Returns : (int) project id 79 """ 80 81 self.my_soap.client.service.Connection_Authenticate(self.username, self.password) 82 project_list = self.my_soap.client.service.Project_Retrieve() 83 84 project = (proj for proj in project_list[0] if proj["Name"] == proj_name).next() 85 self.logger.info("Project Id returned is " + str(project.ProjectId)) 86 87 return project.ProjectId
88
89 - def get_tests_from_set(self, test_set_id, proj_id):
90 """ 91 Fetches a list of test cases for a given test set id in SpiraTest and stores them in class var "tests" 92 93 Args : 94 test_set_id : (int) Automation test set id from Spiratest for project under test 95 proj_id : (int) project id from Spiratest for project under test 96 97 """ 98 99 self.my_soap.client.service.Connection_Authenticate(self.username, self.password) 100 self.my_soap.client.service.Connection_ConnectToProject(proj_id) 101 test_set = self.my_soap.client.service.TestCase_RetrieveByTestSetId(test_set_id) 102 self.tests = test_set[0]
103
104 - def get_test_case_id(self, test_name):
105 """ 106 Gets the unique test case id from SpiraTest for the test case name supplied 107 108 Args : testName : (str) Test case name found in SpiraTest and used in test case decorated to label 109 automated test_support 110 111 Returns : (int) test case id 112 """ 113 114 my_test = (test for test in self.tests if test["Name"] == test_name).next() 115 116 return my_test.TestCaseId
117