Commit f15bfbe1 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Project: new `api_retrieve()` classmethod

This is more direct than `webdriver_retrieve()`, with the usual
benefits of API methods: performance and stability

In this particular case, we were relying on the full session cookie
to be accepted in the API, which is not guaranteed to be acceptable
in the long run.

At this point `webdriver_retrieve()` is not called any more, but
we're not removing it right away.
parent 78434c68466d
Pipeline #6531 passed with stages
in 25 minutes and 40 seconds
......@@ -790,6 +790,28 @@ class Project(object):
wiki_path = repo_path[:-3] + '.wiki.hg'
heptapod.run_shell(('rm', '-rf', repo_path, wiki_path))
@classmethod
def api_retrieve(cls, heptapod, user_name, group, name, check=True):
"""Retrieve Project instance if `id` is not known.
:param user_name: name of an user having enough access to retrieve
project info and in particular owner name
"""
project = cls(heptapod=heptapod,
owner=user_name, # temporary
group=group,
name=name)
resp = project.owner_api_get() # TODO introduce api_get(user=...)
if check:
assert resp.status_code == 200
elif resp.status_code == 404:
return
data = resp.json()
project.id = data['id']
project.owner = data['owner']['username']
return project
@classmethod
def webdriver_create(cls, heptapod, user_name, project_name):
"""Create a new project with the webdriver for given user
......@@ -798,8 +820,8 @@ class Project(object):
driver = heptapod.users[user_name]['webdriver']
driver.get('{url}/projects/new'.format(url=heptapod.url))
cls.webdriver_new_project_submit(driver, project_name)
project = cls.webdriver_retrieve(driver, heptapod, group,
project_name)
project = cls.api_retrieve(heptapod, user_name, group, project_name)
project.wait_hg_availability()
return project
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment