def test_reconnect_fails_when_invalid(self): v1good = None self.addDetail('address', text_content(PublicTestServerConnection.address)) self.addDetail('instance', text_content(PublicTestServerConnection.instance)) # Connect correctly first try: v1good = V1Meta( instance_url=PublicTestServerConnection.instance_url, password=PublicTestServerConnection.token, use_password_as_token=True, ) items = v1good.Story.select('Name').page(size=1) items.first() #run the query except Exception as e: assert_that( False, Equals(True), message= "Error running query from good connection, cannot perform test: " + str(e)) v1bad = None username = self.getUniqueString() #garbage password = self.getUniqueString() #garbage self.addDetail('bad-username', text_content(username)) self.addDetail('bad-password', text_content(password)) try: v1bad = V1Meta( instance_url=PublicTestServerConnection.instance_url, username=username, password=password, use_password_as_token=False, ) items = v1bad.Story.select('Name').page(size=1) items.first() #run the query except HTTPError as e: assert_that( e.code, Equals(401), message="Connection failed for reasons other than authorization" ) else: assert_that( False, Equals(True), message="Second connection succeeded with bad credentials")
def get_defects(user, pwd, ids): defects = [] with V1Meta(instance_url=VENTYX_PROD, username=user, password=pwd) as v1: for defect in v1.Defect.filter(ids): defects.append(defect) return defects
def test_meta_connect_instance_and_address(self): v1 = None self.addDetail('address', text_content(PublicTestServerConnection.address)) self.addDetail('instance', text_content(PublicTestServerConnection.instance)) self.addDetail('username', text_content(PublicTestServerConnection.username)) try: v1 = V1Meta( address=PublicTestServerConnection.address, instance=PublicTestServerConnection.instance, username=PublicTestServerConnection.username, password=PublicTestServerConnection.password, ) except Exception as e: assert_that(False, Equals(True), message="Error trying to create connection: " + str(e)) try: items = v1.Story.select('Name').page(size=1) items.first() #run the query except Exception as e: assert_that(False, Equals(True), message="Error running query from connection: " + str(e))
def test_meta_connect_oauth_ignores_username(self): v1 = None username = self.getUniqueString() #garbage self.addDetail('address', text_content(PublicTestServerConnection.address)) self.addDetail('instance', text_content(PublicTestServerConnection.instance)) self.addDetail('username', text_content(username)) try: v1 = V1Meta( instance_url=PublicTestServerConnection.instance_url, username=username, password=PublicTestServerConnection.token, use_password_as_token=True, ) except Exception as e: assert_that(False, Equals(True), message="Error trying to create connection: " + str(e)) try: items = v1.Story.select('Name').page(size=1) items.first() #run the query except Exception as e: assert_that(False, Equals(True), message="Error running query from connection: " + str(e))
def test_connect_fails_when_invalid(self): v1bad = None username = self.getUniqueString() #garbage password = self.getUniqueString() #garbage self.addDetail('address', text_content(PublicTestServerConnection.address)) self.addDetail('instance', text_content(PublicTestServerConnection.instance)) self.addDetail('bad-username', text_content(username)) self.addDetail('bad-password', text_content(password)) try: v1bad = V1Meta( instance_url=PublicTestServerConnection.instance_url, username=username, password=password, use_password_as_token=False, ) # we have to try to use it to get it to connect and fail items = v1bad.Story.select('Name').page(size=1) items.first() #run the query except HTTPError as e: assert_that( e.code, Equals(401), message="Connection failed for reasons other than authorization" ) else: assert_that(False, Equals(True), message="Connection succeeded with bad credentials")
def get_meta(self): if not hasattr(self, '_meta'): self._meta = V1Meta(address=self.address, instance=self.instance, username=self.username, password=self.password) return self._meta
def test_meta_connect_instance_url_overrides_separate(self): v1 = None address = self.getUniqueString() #garbage instance = self.getUniqueString() #garbage self.addDetail('address', text_content(PublicTestServerConnection.address)) self.addDetail('instance-url', text_content(PublicTestServerConnection.instance_url)) self.addDetail('instance', text_content(address)) self.addDetail('username', text_content(instance)) try: v1 = V1Meta( instance_url=PublicTestServerConnection.instance_url, address=address, instance=instance, username=PublicTestServerConnection.username, password=PublicTestServerConnection.password, ) except Exception as e: assert_that(False, Equals(True), message="Error trying to create connection: " + str(e)) try: items = v1.Story.select('Name').page(size=1) items.first() #run the query except Exception as e: assert_that(False, Equals(True), message="Error running query from connection: " + str(e))
def get_stories(user, pwd, ids): stories = [] with V1Meta(instance_url='https://www11.v1host.com/VentyxProd', username=user, password=pwd) as v1: for story in v1.Story.filter(ids): stories.append(story) return stories
def get_versionone_connection(config): settings_saved = True username = config['versionone'].get('username') if not username: settings_saved = False username = input('VersionOne Username: '******'versionone'].get('instance_url') if not url: settings_saved = False url = input('VersionOne Instance URL ' '(ex: http://www.v1host.com/MyInstance100/): ') if not settings_saved: save = input('Save VersionOne username and instance URL? (N/y): ') if response_was_yes(save): config['versionone']['username'] = username config['versionone']['instance_url'] = url password = keyring.get_password( 'versionone_to_jira_reflector', 'versionone', ) if not password: password = getpass.getpass('VersionOne Password: '******'Save VersionOne password to system keychain? (N/y): ') if response_was_yes(save): keyring.set_password( 'versionone_to_jira_reflector', 'versionone', password, ) parsed_address = parse.urlparse(url) address = parsed_address.netloc path_parts = filter(None, parsed_address.path.split('/')) if not path_parts: raise ConfigurationError( "Could not identify a VersionOne instance name from '%s'." % (url, )) instance = path_parts[0] logger.debug( 'Connecting to VersionOne with the following params: ' 'Address: %s; Instance: %s; Username: %s', address, instance, username, ) connection = V1Meta(address, instance, username, password, scheme='https') return connection
import sys from v1pysdk import V1Meta try: server, instance_path, username, password = sys.argv[1:5] except ValueError: print("Please supply command line arguments") v1 = V1Meta(server, instance_path, username, password) story = v1.Story.create(Name="New Story", Scope="Scope:0" #Scope = v1.Scope.where(Name="Product XYZ").first() ) attachment = v1.Attachment.create(Name="New attachment", Content="", ContentType="application/octet-stream", Filename="test.dat", Asset=story) # right now, every access to the "file_data" property causes an HTTP request. # in the future the SDK needs to cache this on reads and do dirty tracking / # commit managment for writes. attachment.file_data = '\x00\xFF' * 20000 print len(attachment.file_data)
from v1pysdk import V1Meta v1 = V1Meta() for t in v1.AssetType.select('Name').where(Name='Story'): print t for s in v1.Story.select('Name'): print s.CreateDate # fetched on demand print s.Name
from v1pysdk import V1Meta v1 = V1Meta( address = 'www14.v1host.com', instance = 'v1sdktesting', username = '******', password = '******' ) term="Actuals.Value.@Sum" for task in v1.Task.select("Name",term): if('Actuals.Value.@Sum' in task.data): print task['Name'] print task['Actuals.Value.@Sum']
def parsedate(d): return datetime.datetime.strptime(d, "%Y-%m-%d") def as_of_times(start, end, hoursper=6): current = start while current <= end: yield current current += datetime.timedelta(hours=hoursper) if __name__ == "__main__": username, password, sprintName, outputFolder = sys.argv[1:5] with V1Meta('www7.v1host.com', 'V1Production', username, password) as v1: timebox = (v1.Timebox.where(Name=sprintName).select( "BeginDate", "EndDate").first()) startdate = parsedate(timebox.BeginDate) enddate = parsedate(timebox.EndDate) + datetime.timedelta(days=1) individual_times = as_of_times(startdate, enddate) select_list = [select_template.format(status) for status in statuses] results = (v1.Timebox.asof(individual_times).where( Name=sprintName).select(*select_list)) outfilename = os.path.join(outputFolder, sprintName + ".dat") with open(outfilename, "w") as outfile: writer = csv.writer(outfile, delimiter="|") writer.writerow(['# Date'] + statuses) for result in results: row = [result.data[select_term] for select_term in select_list] writer.writerow([result.data['AsOf']] + row)
] select_template = "Workitems:PrimaryWorkitem[Status.Name='{0}'].Estimate.@Sum" def parsedate(d): return datetime.datetime.strptime(d, "%Y-%m-%d") def as_of_times(start, end, hoursper=6): current = start while current <= end: yield current current += datetime.timedelta(hours=hoursper) if __name__=="__main__": username, password, sprintName, outputFolder = sys.argv[1:3] with V1Meta(instance_url="https://www7.v1host.com/V1Production", username=username, password=password) as v1: timebox = (v1.Timebox .where(Name=sprintName) .select("BeginDate", "EndDate") .first()) startdate = parsedate(timebox.BeginDate) enddate = parsedate(timebox.EndDate) + datetime.timedelta(days=1) individual_times = as_of_times(startdate, enddate) select_list = [ select_template.format(status) for status in statuses] results = (v1.Timebox .asof(individual_times) .where(Name=sprintName) .select(*select_list)) outfilename = os.path.join(outputFolder, sprintName + ".dat") with open(outfilename, "w") as outfile: writer = csv.writer(outfile, delimiter="|")
import time from v1pysdk import V1Meta meta = V1Meta() t0 = time.time() def process_queries(queries): for query in (meta.asset_class(type.Name) for type in meta.AssetType): for asset in query: try: asset._v1_refresh() yield str(asset) except Exception as e: yield 'Error! %s(%s)'%(asset._v1_asset_type_name, asset._v1_oid) all_assets = list(process_queries()) t1 = time.time() elapsed = t1 - t0 count = len(all_assets) print "%d assets in %0.4fs (%0.4fs/asset)"%(count, elapsed, elapsed/count) out = open('output.txt', 'w').write('\n'.join([str(a) for a in all_assets]))
import sys from v1pysdk import V1Meta try: url, username, password = sys.argv[1:3] except ValueError: print("Please supply command line arguments") v1 = V1Meta(instance_url=url, username=username, password=password) story = v1.Story.create(Name="New Story", Scope="Scope:0" #Scope = v1.Scope.where(Name="Product XYZ").first() ) attachment = v1.Attachment.create(Name="New attachment", Content="", ContentType="application/octet-stream", Filename="test.dat", Asset=story) # right now, every access to the "file_data" property causes an HTTP request. # in the future the SDK needs to cache this on reads and do dirty tracking / # commit managment for writes. attachment.file_data = '\x00\xFF' * 20000 print len(attachment.file_data)