Skip to content

Commit 357ee5e

Browse files
committed
Support for user auth(). (#202)
* Support for user auth(). * Style fix. * Small integration test. * Removing this test for now. * I've changed a little bit concept, * Imports sorting. * Simple test. * s/!/.
1 parent 0b458e1 commit 357ee5e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

syncano/models/accounts.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
from syncano.exceptions import SyncanoValueError
22

33
from . import fields
44
from .base import Model
@@ -117,6 +117,10 @@ class Meta:
117117
'methods': ['post'],
118118
'path': '/users/{id}/reset_key/',
119119
},
120+
'auth': {
121+
'methods': ['post'],
122+
'path': '/user/auth/',
123+
},
120124
'list': {
121125
'methods': ['get'],
122126
'path': '/users/',
@@ -133,6 +137,21 @@ def reset_key(self):
133137
connection = self._get_connection()
134138
return connection.request('POST', endpoint)
135139

140+
def auth(self, username=None, password=None):
141+
properties = self.get_endpoint_data()
142+
endpoint = self._meta.resolve_endpoint('auth', properties)
143+
connection = self._get_connection()
144+
145+
if not (username and password):
146+
raise SyncanoValueError('You need provide username and password.')
147+
148+
data = {
149+
'username': username,
150+
'password': password
151+
}
152+
153+
return connection.request('POST', endpoint, data=data)
154+
136155
def _user_groups_method(self, group_id=None, method='GET'):
137156
properties = self.get_endpoint_data()
138157
endpoint = self._meta.resolve_endpoint('groups', properties)

tests/integration_test_accounts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ def test_user_alt_login(self):
6767
user_key=self.USER_KEY,
6868
instance_name=self.INSTANCE_NAME)
6969
self.check_connection(con)
70+
71+
def test_user_auth(self):
72+
self.assertTrue(
73+
self.connection.User().auth(username=self.USER_NAME, password=self.USER_PASSWORD)
74+
)

0 commit comments

Comments
 (0)