mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Add test to invite nonwhitelist user and refactor
This commit is contained in:
@@ -61,7 +61,8 @@ class Config(object):
|
|||||||
"valtech\.co\.uk",
|
"valtech\.co\.uk",
|
||||||
"cgi\.com",
|
"cgi\.com",
|
||||||
"capita\.co\.uk",
|
"capita\.co\.uk",
|
||||||
"ucds.email"]
|
"ucds.email"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Development(Config):
|
class Development(Config):
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
import pytest
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import app
|
import app
|
||||||
from app.notify_client.models import InvitedUser
|
from app.notify_client.models import InvitedUser
|
||||||
|
from app.utils import user_in_whitelist
|
||||||
from tests.conftest import service_one as service_1
|
from tests.conftest import service_one as service_1
|
||||||
|
|
||||||
|
|
||||||
@@ -129,20 +131,26 @@ def test_should_show_page_for_inviting_user(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('email_address, whitelist_user', [
|
||||||
|
('test@example.gov.uk', True),
|
||||||
|
('test@nonwhitelist.com', False)
|
||||||
|
])
|
||||||
def test_invite_user(
|
def test_invite_user(
|
||||||
app_,
|
app_,
|
||||||
active_user_with_permissions,
|
active_user_with_permissions,
|
||||||
mocker,
|
mocker,
|
||||||
sample_invite
|
sample_invite,
|
||||||
|
email_address,
|
||||||
|
whitelist_user
|
||||||
):
|
):
|
||||||
service = service_1(active_user_with_permissions)
|
service = service_1(active_user_with_permissions)
|
||||||
email_address = 'test@example.gov.uk'
|
|
||||||
sample_invite['email_address'] = 'test@example.gov.uk'
|
sample_invite['email_address'] = 'test@example.gov.uk'
|
||||||
|
|
||||||
data = [InvitedUser(**sample_invite)]
|
data = [InvitedUser(**sample_invite)]
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user_with_permissions, mocker, service)
|
client.login(active_user_with_permissions, mocker, service)
|
||||||
|
assert user_in_whitelist(email_address) == whitelist_user
|
||||||
mocker.patch('app.invite_api_client.get_invites_for_service', return_value=data)
|
mocker.patch('app.invite_api_client.get_invites_for_service', return_value=data)
|
||||||
mocker.patch('app.user_api_client.get_users_for_service', return_value=[active_user_with_permissions])
|
mocker.patch('app.user_api_client.get_users_for_service', return_value=[active_user_with_permissions])
|
||||||
mocker.patch('app.invite_api_client.create_invite', return_value=InvitedUser(**sample_invite))
|
mocker.patch('app.invite_api_client.create_invite', return_value=InvitedUser(**sample_invite))
|
||||||
|
|||||||
Reference in New Issue
Block a user