def __init__(self): # Connect to the server unless already connected if TCMS._connection is not None: return # Try system settings when the config does not exist in user directory if not os.path.exists(self._path): self._path = "/etc/tcms.conf" if not os.path.exists(self._path): raise Exception("Config file '%s' not found" % self._path) config = ConfigParser() config.read(self._path) # Make sure the server URL is set try: config['tcms']['url'] is not None except (KeyError, AttributeError): raise Exception("No url found in %s" % self._path) if strtobool(config['tcms'].get('use_kerberos', 'False')): # use Kerberos TCMS._connection = TCMSKerbXmlrpc(None, None, config['tcms']['url']).server return try: # use password authentication TCMS._connection = TCMSXmlrpc(config['tcms']['username'], config['tcms']['password'], config['tcms']['url']).server except KeyError: raise Exception("username/password required in %s" % self._path) return
def test_add_case_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testruns.add_testcaserun') rpc_client = TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestRun.add_case(self.test_run.pk, self.test_case.pk) exists = TestCaseRun.objects.filter(run=self.test_run.pk, case=self.test_case.pk).exists() self.assertFalse(exists)
def test_add_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testplans.add_testplantag') rpc_client = TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestPlan.add_tag(self.plans[0].pk, self.tag1.name) # tags were not modified tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag1.pk).exists() self.assertFalse(tag_exists)
import requests import sys import os import json import xmltodict from time import sleep from tcms_api.xmlrpc import TCMSXmlrpc from tcms_api.mutable import TestRun, TestCaseRunStatus from plivo.tcms_utils import get_max_id # Login to running KIWI server. with open('xml-rpc.txt') as file: server = file.read().strip() TCMSXmlrpc('plivo', 'root', 'http://' + server + '/xml-rpc/') # Authenticating Jenkins home_dir = os.path.expanduser('~') credential_dir = os.path.join(home_dir, '.credentials') credential_path = os.path.join(credential_dir, 'plivo_auth.json') with open(credential_path) as file: credentials = json.loads(file.read()) username, password = credentials['jenkins_id'], credentials['jenkins_password'] def _parse_jenkin_output(job_name): try: r = requests.get('http://jenkins.qa.plivodev.com/job/' + job_name + '/ws/output.xml', auth=(username, password)) doc = xmltodict.parse(r.text) except Exception as e: