summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gitlab/__init__.py3
-rw-r--r--gitlab/cli.py4
-rw-r--r--gitlab/objects.py14
-rwxr-xr-xtools/functional_tests.sh2
-rwxr-xr-xtools/py_functional_tests.sh2
-rw-r--r--tools/python_test.py9
6 files changed, 29 insertions, 5 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index d8ee5bf..28ebfe3 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -551,7 +551,8 @@ class Gitlab(object):
if missing:
raise GitlabUpdateError('Missing attribute(s): %s' %
", ".join(missing))
- url = self._construct_url(id_=obj.id, obj=obj, parameters=params)
+ obj_id = params[obj.idAttr] if obj._id_in_update_url else None
+ url = self._construct_url(id_=obj_id, obj=obj, parameters=params)
headers = self._create_headers(content_type="application/json")
# build data that can really be sent to server
diff --git a/gitlab/cli.py b/gitlab/cli.py
index c2b2fa5..8ac8e45 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -89,7 +89,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
required=True)
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
required=True)
- for x in cls.requiredGetAttrs]
+ for x in cls.requiredGetAttrs if x != cls.idAttr]
elif action_name == CREATE:
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
@@ -109,7 +109,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
else cls.requiredCreateAttrs)
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
required=True)
- for x in attrs]
+ for x in attrs if x != cls.idAttr]
attrs = (cls.optionalUpdateAttrs
if cls.optionalUpdateAttrs is not None
diff --git a/gitlab/objects.py b/gitlab/objects.py
index ddcbae7..0330807 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -178,6 +178,7 @@ class GitlabObject(object):
# plural
_urlPlural = None
_id_in_delete_url = True
+ _id_in_update_url = True
_returnClass = None
_constructorTypes = None
@@ -936,6 +937,7 @@ class ProjectMilestoneManager(BaseManager):
class ProjectLabel(GitlabObject):
_url = '/projects/%(project_id)s/labels'
_id_in_delete_url = False
+ _id_in_update_url = False
canGet = 'from_list'
requiredUrlAttrs = ['project_id']
idAttr = 'name'
@@ -1031,6 +1033,17 @@ class ProjectTriggerManager(BaseManager):
obj_cls = ProjectTrigger
+class ProjectVariable(GitlabObject):
+ _url = '/projects/%(project_id)s/variables'
+ idAttr = 'key'
+ requiredUrlAttrs = ['project_id']
+ requiredCreateAttrs = ['key', 'value']
+
+
+class ProjectVariableManager(BaseManager):
+ obj_cls = ProjectVariable
+
+
class Project(GitlabObject):
_url = '/projects'
_constructorTypes = {'owner': 'User', 'namespace': 'Group'}
@@ -1059,6 +1072,7 @@ class Project(GitlabObject):
('snippets', ProjectSnippetManager, [('project_id', 'id')]),
('tags', ProjectTagManager, [('project_id', 'id')]),
('triggers', ProjectTriggerManager, [('project_id', 'id')]),
+ ('variables', ProjectVariableManager, [('project_id', 'id')]),
]
def Branch(self, id=None, **kwargs):
diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh
index 18770e9..6cb868d 100755
--- a/tools/functional_tests.sh
+++ b/tools/functional_tests.sh
@@ -41,7 +41,7 @@ pip install -rrequirements.txt
pip install -e .
# NOTE(gpocentek): the first call might fail without a little delay
-sleep 5
+sleep 20
set -e
diff --git a/tools/py_functional_tests.sh b/tools/py_functional_tests.sh
index a30230b..f37aaea 100755
--- a/tools/py_functional_tests.sh
+++ b/tools/py_functional_tests.sh
@@ -34,6 +34,6 @@ $VENV_CMD $VENV
pip install -rrequirements.txt
pip install -e .
-sleep 10
+sleep 20
python $(dirname $0)/python_test.py
diff --git a/tools/python_test.py b/tools/python_test.py
index 820dca1..ff4aa2a 100644
--- a/tools/python_test.py
+++ b/tools/python_test.py
@@ -158,3 +158,12 @@ tr1 = admin_project.triggers.create({})
assert(len(admin_project.triggers.list()) == 1)
tr1 = admin_project.triggers.get(tr1.token)
tr1.delete()
+
+# variables
+v1 = admin_project.variables.create({'key': 'key1', 'value': 'value1'})
+assert(len(admin_project.variables.list()) == 1)
+v1.value = 'new_value1'
+v1.save()
+v1 = admin_project.variables.get(v1.key)
+assert(v1.value == 'new_value1')
+v1.delete()