Skip to content

Commit

Permalink
Merge pull request #22 from Kagiso-Future-Media/endpoints
Browse files Browse the repository at this point in the history
Updated endpoints
  • Loading branch information
colinfrankb committed Sep 14, 2015
2 parents 690b87c + b7ce651 commit 1056b80
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion auth_backend/auth_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class AuthApiClient:

BASE_URL = settings.CAS_BASE_URL
TIMEOUT_IN_SECONDS = 3
TIMEOUT_IN_SECONDS = 6

def __init__(self, cas_credentials=None):
if cas_credentials is None:
Expand Down
6 changes: 3 additions & 3 deletions auth_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def set_password(self, raw_password):

def confirm_email(self, confirmation_token):
payload = {'confirmation_token': confirmation_token}
endpoint = 'users/{id}/confirm_email'.format(id=self.id)
endpoint = 'confirm_email'
status, data = self._auth_api_client.call(endpoint, 'POST', payload)

if not status == 200:
Expand All @@ -72,7 +72,7 @@ def confirm_email(self, confirmation_token):
self.save()

def generate_reset_password_token(self):
endpoint = 'users/{id}/reset_password'.format(id=self.id)
endpoint = 'reset_password/{email}'.format(email=self.email)
status, data = self._auth_api_client.call(endpoint, 'GET')

if not status == 200:
Expand All @@ -85,7 +85,7 @@ def reset_password(self, password, reset_password_token):
'reset_password_token': reset_password_token,
'password': password,
}
endpoint = 'users/{id}/reset_password'.format(id=self.id)
endpoint = 'reset_password/{email}'.format(email=self.email)
status, data = self._auth_api_client.call(endpoint, 'POST', payload)

if not status == 200:
Expand Down
1 change: 1 addition & 0 deletions auth_backend/tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_reset_password(self):
)
user.set_password('password')
user.save()
user.confirm_email(user.confirmation_token)

# ----- Reset the password -----
new_password = 'new_password'
Expand Down
13 changes: 7 additions & 6 deletions auth_backend/tests/unit/mocks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import json

import responses
Expand Down Expand Up @@ -65,8 +66,8 @@ def mock_out_delete_users(id, status=204):
return url


def mock_out_post_confirm_email(id, status=200):
url = 'https://auth.kagiso.io/api/v1/users/{id}/confirm_email/.json'.format(id=id) # noqa
def mock_out_post_confirm_email(status=200):
url = 'https://auth.kagiso.io/api/v1/confirm_email/.json' # noqa

responses.add(
responses.POST,
Expand All @@ -77,8 +78,8 @@ def mock_out_post_confirm_email(id, status=200):
return url


def mock_out_get_reset_password(id, status=200):
url = 'https://auth.kagiso.io/api/v1/users/{id}/reset_password/.json'.format(id=id) # noqa
def mock_out_get_reset_password(email, status=200):
url = 'https://auth.kagiso.io/api/v1/reset_password/{email}/.json'.format(email=email) # noqa
data = {
'reset_password_token': 'random_token',
}
Expand All @@ -93,8 +94,8 @@ def mock_out_get_reset_password(id, status=200):
return url, data


def mock_out_post_reset_password(id, status=200):
url = 'https://auth.kagiso.io/api/v1/users/{id}/reset_password/.json'.format(id=id) # noqa
def mock_out_post_reset_password(email, status=200):
url = 'https://auth.kagiso.io/api/v1/reset_password/{email}/.json'.format(email=email) # noqa

responses.add(
responses.POST,
Expand Down
12 changes: 6 additions & 6 deletions auth_backend/tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def test_confirm_email(self):
user.email,
profile=user.profile
)
url = mocks.mock_out_post_confirm_email(user.id)
url = mocks.mock_out_post_confirm_email()

user.confirm_email(post_data['confirmation_token'])

Expand All @@ -328,7 +328,7 @@ def test_confirm_email_invalid_status_code_raises(self):
user.email,
profile=user.profile
)
mocks.mock_out_post_confirm_email(user.id, status=500)
mocks.mock_out_post_confirm_email(status=500)

with pytest.raises(CASUnexpectedStatusCode):
user.confirm_email(post_data['confirmation_token'])
Expand Down Expand Up @@ -364,7 +364,7 @@ def test_record_sign_out_invalid_status_code_raises(self):
def test_generate_reset_password_token(self):
_, post_data = mocks.mock_out_post_users(1, 'test@email.com')
user = mommy.make(models.KagisoUser, id=None)
url, data = mocks.mock_out_get_reset_password(user.id)
url, data = mocks.mock_out_get_reset_password(user.email)

reset_password_token = user.generate_reset_password_token()

Expand All @@ -377,7 +377,7 @@ def test_generate_reset_password_token(self):
def test_generate_reset_password_token_invalid_status_raises(self):
_, post_data = mocks.mock_out_post_users(1, 'test@email.com')
user = mommy.make(models.KagisoUser, id=None)
url, data = mocks.mock_out_get_reset_password(user.id, status=500)
url, data = mocks.mock_out_get_reset_password(user.email, status=500)

with pytest.raises(CASUnexpectedStatusCode):
reset_password_token = user.generate_reset_password_token()
Expand All @@ -387,7 +387,7 @@ def test_generate_reset_password_token_invalid_status_raises(self):
def test_reset_password(self):
_, post_data = mocks.mock_out_post_users(1, 'test@email.com')
user = mommy.make(models.KagisoUser, id=None)
url = mocks.mock_out_post_reset_password(user.id)
url = mocks.mock_out_post_reset_password(user.email)

did_password_reset = user.reset_password('new_password', 'test_token')

Expand All @@ -400,7 +400,7 @@ def test_reset_password(self):
def test_reset_password_invalid_status_code_raises(self):
_, post_data = mocks.mock_out_post_users(1, 'test@email.com')
user = mommy.make(models.KagisoUser, id=None)
mocks.mock_out_post_reset_password(user.id, status=500)
mocks.mock_out_post_reset_password(user.email, status=500)

with pytest.raises(CASUnexpectedStatusCode):
did_password_reset = user.reset_password(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='kagiso_django_auth',
version='1.2.2',
version='2.0.0',
author='Kagiso Media',
author_email='development@kagiso.io',
description='Kagiso Django AuthBackend',
Expand Down

0 comments on commit 1056b80

Please sign in to comment.