Skip to content

Commit

Permalink
Allow using cloud test id or test link to launch it (Blazemeter#719)
Browse files Browse the repository at this point in the history
* Make launching test by its id possible

* Add support of using link to test as a test name

* Reimplement test resolution process

* Implement account/workspace usage from the configuration
file

* Add docs

* Add changefiles
  • Loading branch information
dimp-gh authored Dec 5, 2017
1 parent df0faa3 commit 5cb33b6
Show file tree
Hide file tree
Showing 10 changed files with 500 additions and 82 deletions.
84 changes: 73 additions & 11 deletions bzt/bza.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ def ping(self):
""" Quick check if we can access the service """
self._request(self.address + '/api/v4/web/version')

def accounts(self):
def accounts(self, ident=None, name=None):
"""
:rtype: BZAObjectsList[Account]
"""
res = self._request(self.address + '/api/v4/accounts')
return BZAObjectsList([Account(self, x) for x in res['result']])
accounts = []
for acc in res['result']:
if ident is not None and acc['id'] != ident:
continue
if name is not None and acc['name'] != name:
continue
accounts.append(Account(self, acc))
return BZAObjectsList(accounts)

def fetch(self):
res = self._request(self.address + '/api/v4/user')
Expand Down Expand Up @@ -207,20 +214,55 @@ def _upload_collection_resources(self, resource_files, draft_id):
hdr = {"Content-Type": str(body.get_content_type())}
self._request(url, body.form_as_bytes(), headers=hdr)

def test_by_ids(self, account_id=None, workspace_id=None, project_id=None, test_id=None):
account = self.accounts(ident=account_id).first()
if not account:
raise ValueError("Account not found: %s" % account_id)
workspace = account.workspaces(ident=workspace_id).first()
if workspace is None:
raise ValueError("Workspace not found: %s" % workspace_id)
project = workspace.projects(ident=project_id).first()
if project:
target = project
else:
target = workspace

test = target.multi_tests(ident=test_id).first()
if test is None:
test = target.tests(ident=test_id).first()

if test is None:
raise ValueError("Test wasn't found")

return account, workspace, project, test


class Account(BZAObject):
def workspaces(self):
def workspaces(self, ident=None, name=None):
"""
:rtype: BZAObjectsList[Workspace]
"""
params = {"accountId": self['id'], 'enabled': 'true', 'limit': 100}
params = OrderedDict(sorted(params.items(), key=lambda t: t[0]))
res = self._request(self.address + '/api/v4/workspaces?' + urlencode(params))
return BZAObjectsList([Workspace(self, x) for x in res['result'] if x['enabled']])
workspaces = []
for wksp in res['result']:
if not wksp['enabled']:
continue

if name is not None and wksp['name'] != name:
continue

if ident is not None and wksp['id'] != ident:
continue

workspaces.append(Workspace(self, wksp))

return BZAObjectsList(workspaces)


class Workspace(BZAObject):
def projects(self, name=None, proj_id=None):
def projects(self, name=None, ident=None):
"""
:rtype: BZAObjectsList[Project]
"""
Expand All @@ -234,11 +276,11 @@ def projects(self, name=None, proj_id=None):
if name is not None and item['name'] != name:
continue

if proj_id is not None and item['id'] != proj_id:
if ident is not None and item['id'] != ident:
continue

projects.append(Project(self, item))
return projects
return BZAObjectsList(projects)

def locations(self, include_private=False):
if 'locations' not in self:
Expand All @@ -258,17 +300,22 @@ def private_locations(self):
res = self._request(self.address + '/api/v4/private-locations?' + urlencode(params))
return BZAObjectsList([BZAObject(self, x) for x in res['result']])

def tests(self, name=None, test_type=None):
def tests(self, name=None, ident=None, test_type=None):
"""
:rtype: BZAObjectsList[Test]
"""
params = OrderedDict({"workspaceId": self['id']})
if name is not None:
params["name"] = name
if ident is not None:
params["id"] = ident

res = self._request(self.address + '/api/v4/tests?' + urlencode(params))
tests = BZAObjectsList()
for item in res['result']:
if ident is not None and item['id'] != ident:
continue

if name is not None and item['name'] != name:
continue

Expand All @@ -278,17 +325,22 @@ def tests(self, name=None, test_type=None):
tests.append(Test(self, item))
return tests

def multi_tests(self, name=None):
def multi_tests(self, name=None, ident=None):
"""
:rtype: BZAObjectsList[MultiTest]
"""
params = OrderedDict({"workspaceId": self['id']})
if name is not None:
params["name"] = name
if ident is not None:
params["id"] = ident

res = self._request(self.address + '/api/v4/multi-tests?' + urlencode(params))
tests = BZAObjectsList()
for item in res['result']:
if ident is not None and item['id'] != ident:
continue

if name is not None and item['name'] != name:
continue

Expand All @@ -311,17 +363,22 @@ class Location(BZAObject):


class Project(BZAObject):
def tests(self, name=None, test_type=None):
def tests(self, name=None, ident=None, test_type=None):
"""
:rtype: BZAObjectsList[Test]
"""
params = OrderedDict({"projectId": self['id']})
if name is not None:
params["name"] = name
if ident is not None:
params["id"] = ident

res = self._request(self.address + '/api/v4/tests?' + urlencode(params))
tests = BZAObjectsList()
for item in res['result']:
if ident is not None and item['id'] != ident:
continue

if name is not None and item['name'] != name:
continue

Expand All @@ -331,17 +388,22 @@ def tests(self, name=None, test_type=None):
tests.append(Test(self, item))
return tests

def multi_tests(self, name=None):
def multi_tests(self, name=None, ident=None):
"""
:rtype: BZAObjectsList[MultiTest]
"""
params = OrderedDict({"projectId": self['id']})
if name is not None:
params["name"] = name
if ident is not None:
params["id"] = ident

res = self._request(self.address + '/api/v4/multi-tests?' + urlencode(params))
tests = BZAObjectsList()
for item in res['result']:
if ident is not None and item['id'] != ident:
continue

if name is not None and item['name'] != name:
continue

Expand Down
Loading

0 comments on commit 5cb33b6

Please sign in to comment.