Skip to content

Commit d0a9334

Browse files
author
Gauvain Pocentek
committed
make the tests pass
1 parent 6be990c commit d0a9334

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

gitlab/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ def _credentials_auth(self):
197197
r = self._raw_post('/session', data,
198198
content_type='application/json')
199199
raise_error_from_response(r, GitlabAuthenticationError, 201)
200-
self.user = objects.CurrentUser(self, r.json())
200+
self.user = self._objects.CurrentUser(self, r.json())
201201
else:
202202
manager = self._objects.CurrentUserManager()
203-
self.user = credentials_auth(self.email, self.password)
203+
self.user = manager.get(self.email, self.password)
204204

205205
self._set_token(self.user.private_token)
206206

@@ -211,7 +211,10 @@ def token_auth(self):
211211
self._token_auth()
212212

213213
def _token_auth(self):
214-
self.user = self._objects.CurrentUserManager(self).get()
214+
if self.api_version == '3':
215+
self.user = self._objects.CurrentUser(self)
216+
else:
217+
self.user = self._objects.CurrentUserManager(self).get()
215218

216219
def version(self):
217220
"""Returns the version and revision of the gitlab server.

gitlab/mixins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
255255

256256
path = '%s/%s/approve' % (self.manager.path, self.id)
257257
data = {'access_level': access_level}
258-
server_data = self.manager.gitlab.http_put(url, post_data=data,
258+
server_data = self.manager.gitlab.http_put(path, post_data=data,
259259
**kwargs)
260260
self._update_attrs(server_data)
261261

262262

263263
class SubscribableMixin(object):
264-
def subscribe(self, **kwarg):
264+
def subscribe(self, **kwargs):
265265
"""Subscribe to the object notifications.
266266
267267
raises:

gitlab/v4/objects.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import six
2525

26-
import gitlab
2726
from gitlab.base import * # noqa
2827
from gitlab.exceptions import * # noqa
2928
from gitlab.mixins import * # noqa
@@ -203,6 +202,7 @@ def credentials_auth(self, email, password):
203202
server_data = self.gitlab.http_post('/session', post_data=data)
204203
return CurrentUser(self, server_data)
205204

205+
206206
class ApplicationSettings(SaveMixin, RESTObject):
207207
_id_attr = None
208208

@@ -300,6 +300,7 @@ class GitlabciymlManager(RetrieveMixin, RESTManager):
300300
class GroupIssue(RESTObject):
301301
pass
302302

303+
303304
class GroupIssueManager(GetFromListMixin, RESTManager):
304305
_path = '/groups/%(group_id)s/issues'
305306
_obj_cls = GroupIssue
@@ -373,7 +374,7 @@ class License(RESTObject):
373374
class LicenseManager(RetrieveMixin, RESTManager):
374375
_path = '/templates/licenses'
375376
_obj_cls = License
376-
_list_filters =('popular')
377+
_list_filters = ('popular', )
377378
_optional_get_attrs = ('project', 'fullname')
378379

379380

@@ -402,7 +403,7 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
402403
path = '/snippets/%s/raw' % self.get_id()
403404
result = self.manager.gitlab.http_get(path, streamed=streamed,
404405
**kwargs)
405-
return utils.response_content(r, streamed, action, chunk_size)
406+
return utils.response_content(result, streamed, action, chunk_size)
406407

407408

408409
class SnippetManager(CRUDMixin, RESTManager):
@@ -467,7 +468,7 @@ class ProjectBranch(RESTObject):
467468
def protect(self, developers_can_push=False, developers_can_merge=False,
468469
**kwargs):
469470
"""Protects the branch.
470-
471+
471472
Args:
472473
developers_can_push (bool): Set to True if developers are allowed
473474
to push to the branch
@@ -588,7 +589,8 @@ class ProjectCommitStatus(RESTObject):
588589

589590

590591
class ProjectCommitStatusManager(RetrieveMixin, CreateMixin, RESTManager):
591-
_path = '/projects/%(project_id)s/repository/commits/%(commit_id)s/statuses'
592+
_path = ('/projects/%(project_id)s/repository/commits/%(commit_id)s'
593+
'/statuses')
592594
_obj_cls = ProjectCommitStatus
593595
_from_parent_attrs = {'project_id': 'project_id', 'commit_id': 'id'}
594596
_create_attrs = (('state', ),
@@ -696,7 +698,7 @@ class ProjectEvent(RESTObject):
696698

697699

698700
class ProjectEventManager(GetFromListMixin, RESTManager):
699-
_path ='/projects/%(project_id)s/events'
701+
_path = '/projects/%(project_id)s/events'
700702
_obj_cls = ProjectEvent
701703
_from_parent_attrs = {'project_id': 'id'}
702704

@@ -741,7 +743,7 @@ class ProjectHookManager(CRUDMixin, RESTManager):
741743

742744

743745
class ProjectIssueNote(SaveMixin, RESTObject):
744-
_constructor_types= {'author': 'User'}
746+
_constructor_types = {'author': 'User'}
745747

746748

747749
class ProjectIssueNoteManager(RetrieveMixin, CreateMixin, UpdateMixin,
@@ -754,7 +756,7 @@ class ProjectIssueNoteManager(RetrieveMixin, CreateMixin, UpdateMixin,
754756

755757

756758
class ProjectIssue(SubscribableMixin, TodoMixin, TimeTrackingMixin, SaveMixin,
757-
RESTObject):
759+
RESTObject):
758760
_constructor_types = {'author': 'User', 'assignee': 'User', 'milestone':
759761
'ProjectMilestone'}
760762
_short_print_attr = 'title'
@@ -769,7 +771,7 @@ def move(self, to_project_id, **kwargs):
769771
"""
770772
path = '%s/%s/move' % (self.manager.path, self.get_id())
771773
data = {'to_project_id': to_project_id}
772-
server_data = self.manager.gitlab.http_post(url, post_data=data,
774+
server_data = self.manager.gitlab.http_post(path, post_data=data,
773775
**kwargs)
774776
self._update_attrs(server_data)
775777

@@ -808,7 +810,7 @@ class ProjectNote(RESTObject):
808810

809811

810812
class ProjectNoteManager(RetrieveMixin, RESTManager):
811-
_path ='/projects/%(project_id)s/notes'
813+
_path = '/projects/%(project_id)s/notes'
812814
_obj_cls = ProjectNote
813815
_from_parent_attrs = {'project_id': 'id'}
814816
_create_attrs = (('body', ), tuple())
@@ -844,13 +846,13 @@ def set_release_description(self, description, **kwargs):
844846
GitlabCreateError: If the server fails to create the release.
845847
GitlabUpdateError: If the server fails to update the release.
846848
"""
847-
_path = '%s/%s/release' % (self.manager.path, self.get_id())
849+
path = '%s/%s/release' % (self.manager.path, self.get_id())
848850
data = {'description': description}
849851
if self.release is None:
850-
result = self.manager.gitlab.http_post(url, post_data=data,
852+
result = self.manager.gitlab.http_post(path, post_data=data,
851853
**kwargs)
852854
else:
853-
result = self.manager.gitlab.http_put(url, post_data=data,
855+
result = self.manager.gitlab.http_put(path, post_data=data,
854856
**kwargs)
855857
self.release = result.json()
856858

@@ -1215,7 +1217,7 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
12151217
path = "%s/%s/raw" % (self.manager.path, self.get_id())
12161218
result = self.manager.gitlab.http_get(path, streamed=streamed,
12171219
**kwargs)
1218-
return utils.response_content(r, streamed, action, chunk_size)
1220+
return utils.response_content(result, streamed, action, chunk_size)
12191221

12201222

12211223
class ProjectSnippetManager(CRUDMixin, RESTManager):
@@ -1382,7 +1384,6 @@ class ProjectRunnerManager(NoUpdateMixin, RESTManager):
13821384
_create_attrs = (('runner_id', ), tuple())
13831385

13841386

1385-
13861387
class Project(SaveMixin, RESTObject):
13871388
_constructor_types = {'owner': 'User', 'namespace': 'Group'}
13881389
_short_print_attr = 'path'
@@ -1459,7 +1460,7 @@ def repository_raw_blob(self, sha, streamed=False, action=None,
14591460
GitlabGetError: If the server fails to perform the request.
14601461
"""
14611462
path = '/projects/%s/repository/raw_blobs/%s' % (self.get_id(), sha)
1462-
result = self.gitlab._raw_get(url, streamed=streamed, **kwargs)
1463+
result = self.gitlab._raw_get(path, streamed=streamed, **kwargs)
14631464
return utils.response_content(result, streamed, action, chunk_size)
14641465

14651466
def repository_compare(self, from_, to, **kwargs):
@@ -1598,7 +1599,7 @@ def unarchive(self, **kwargs):
15981599
GitlabConnectionError: If the server cannot be reached.
15991600
"""
16001601
path = '/projects/%s/unarchive' % self.get_id()
1601-
server_data = self.manager.gitlab.http_post(url, **kwargs)
1602+
server_data = self.manager.gitlab.http_post(path, **kwargs)
16021603
self._update_attrs(server_data)
16031604

16041605
def share(self, group_id, group_access, expires_at=None, **kwargs):
@@ -1649,7 +1650,6 @@ class RunnerManager(RetrieveMixin, UpdateMixin, DeleteMixin, RESTManager):
16491650
_update_attrs = (tuple(), ('description', 'active', 'tag_list'))
16501651
_list_filters = ('scope', )
16511652

1652-
16531653
def all(self, scope=None, **kwargs):
16541654
"""List all the runners.
16551655

0 commit comments

Comments
 (0)