mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Admin uses correct endpoint for getting user by email address.
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
from notifications_python_client.notifications import BaseAPIClient
|
from notifications_python_client.notifications import BaseAPIClient
|
||||||
from notifications_python_client.errors import (
|
from notifications_python_client.errors import HTTPError
|
||||||
HTTPError,
|
|
||||||
InvalidResponse
|
|
||||||
)
|
|
||||||
|
|
||||||
from flask.ext.login import UserMixin
|
from flask.ext.login import UserMixin
|
||||||
|
|
||||||
@@ -34,6 +31,11 @@ class UserApiClient(BaseAPIClient):
|
|||||||
user_data = self.get(url)
|
user_data = self.get(url)
|
||||||
return User(user_data['data'], max_failed_login_count=self.max_failed_login_count)
|
return User(user_data['data'], max_failed_login_count=self.max_failed_login_count)
|
||||||
|
|
||||||
|
def get_user_by_email(self, email_address):
|
||||||
|
params = {'email': email_address}
|
||||||
|
user_data = self.get('/user/email', params=params)
|
||||||
|
return User(user_data['data'], max_failed_login_count=self.max_failed_login_count)
|
||||||
|
|
||||||
def get_users(self):
|
def get_users(self):
|
||||||
users_data = self.get("/user")['data']
|
users_data = self.get("/user")['data']
|
||||||
users = []
|
users = []
|
||||||
@@ -57,13 +59,6 @@ class UserApiClient(BaseAPIClient):
|
|||||||
if e.status_code == 400 or e.status_code == 404:
|
if e.status_code == 400 or e.status_code == 404:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_user_by_email(self, email_address):
|
|
||||||
users = self.get_users()
|
|
||||||
user = [u for u in users if u.email_address == email_address]
|
|
||||||
if len(user) == 1:
|
|
||||||
return user[0]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def send_verify_code(self, user_id, code_type, to):
|
def send_verify_code(self, user_id, code_type, to):
|
||||||
data = {'to': to}
|
data = {'to': to}
|
||||||
endpoint = '/user/{0}/{1}-code'.format(user_id, code_type)
|
endpoint = '/user/{0}/{1}-code'.format(user_id, code_type)
|
||||||
|
|||||||
15
tests/app/main/notify_client/test_user_client.py
Normal file
15
tests/app/main/notify_client/test_user_client.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from app.notify_client.user_api_client import UserApiClient
|
||||||
|
|
||||||
|
|
||||||
|
def test_client_uses_correct_find_by_email(mocker, api_user_active):
|
||||||
|
|
||||||
|
expected_url = '/user/email'
|
||||||
|
expected_params = {'email': api_user_active.email_address}
|
||||||
|
|
||||||
|
client = UserApiClient()
|
||||||
|
client.max_failed_login_count = 1 # doesn't matter for this test
|
||||||
|
mock_get = mocker.patch('app.notify_client.user_api_client.UserApiClient.get')
|
||||||
|
|
||||||
|
client.get_user_by_email(api_user_active.email_address)
|
||||||
|
|
||||||
|
mock_get.assert_called_once_with(expected_url, params=expected_params)
|
||||||
Reference in New Issue
Block a user