mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Merge branch 'main' into unskip
This commit is contained in:
@@ -16,7 +16,7 @@ from app.dao.organization_dao import (
|
||||
dao_get_users_for_organization,
|
||||
dao_update_organization,
|
||||
)
|
||||
from app.enums import OrganizationType
|
||||
from app.enums import OrganizationType, UserState
|
||||
from app.models import Organization, Service
|
||||
from app.utils import utc_now
|
||||
from tests.app.db import (
|
||||
@@ -310,7 +310,7 @@ def test_dao_get_users_for_organization_only_returns_active_users(sample_organiz
|
||||
organization_id=sample_organization.id, user_id=second.id
|
||||
)
|
||||
|
||||
second.state = "inactive"
|
||||
second.state = UserState.INACTIVE
|
||||
|
||||
results = dao_get_users_for_organization(organization_id=sample_organization.id)
|
||||
assert len(results) == 1
|
||||
|
||||
@@ -26,7 +26,7 @@ from app.dao.users_dao import (
|
||||
update_user_password,
|
||||
user_can_be_archived,
|
||||
)
|
||||
from app.enums import AuthType, CodeType, PermissionType
|
||||
from app.enums import AuthType, CodeType, PermissionType, UserState
|
||||
from app.errors import InvalidRequest
|
||||
from app.models import User, VerifyCode
|
||||
from app.utils import utc_now
|
||||
@@ -271,7 +271,7 @@ def test_dao_archive_user(sample_user, sample_organization, fake_uuid):
|
||||
assert sample_user.current_session_id == uuid.UUID(
|
||||
"00000000-0000-0000-0000-000000000000"
|
||||
)
|
||||
assert sample_user.state == "inactive"
|
||||
assert sample_user.state == UserState.INACTIVE
|
||||
assert not sample_user.check_password("password")
|
||||
|
||||
|
||||
@@ -329,8 +329,8 @@ def test_user_cannot_be_archived_if_they_belong_to_a_service_with_no_other_activ
|
||||
sample_service,
|
||||
):
|
||||
active_user = create_user(email="1@test.com")
|
||||
pending_user = create_user(email="2@test.com", state="pending")
|
||||
inactive_user = create_user(email="3@test.com", state="inactive")
|
||||
pending_user = create_user(email="2@test.com", state=UserState.PENDING)
|
||||
inactive_user = create_user(email="3@test.com", state=UserState.INACTIVE)
|
||||
|
||||
sample_service.users = [active_user, pending_user, inactive_user]
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ from app.enums import (
|
||||
NotificationType,
|
||||
OrganizationType,
|
||||
TemplateType,
|
||||
UserState,
|
||||
)
|
||||
from app.models import (
|
||||
AnnualBilling,
|
||||
@@ -273,7 +274,7 @@ def test_create_test_user_command(notify_db_session, notify_api):
|
||||
user = db.session.execute(stmt).scalars().first()
|
||||
assert user.email_address == "somebody@fake.gov"
|
||||
assert user.auth_type == AuthType.SMS
|
||||
assert user.state == "active"
|
||||
assert user.state == UserState.ACTIVE
|
||||
|
||||
|
||||
def test_insert_inbound_numbers_from_file(notify_db_session, notify_api, tmpdir):
|
||||
@@ -517,8 +518,7 @@ def test_populate_go_live_success(notify_api, mocker):
|
||||
new_callable=mock_open,
|
||||
read_data="""count,Link,Service ID,DEPT,Service Name,Main contact,Contact detail,MOU,LIVE date,SMS,Email,Letters,CRM,Blue badge\n1,link,123,Dept A,Service A,Contact A,email@example.com,MOU,15/10/2024,Yes,Yes,Yes,Yes,No""", # noqa
|
||||
)
|
||||
mock_current_app = mocker.patch("app.commands.current_app")
|
||||
mock_logger = mock_current_app.logger
|
||||
mocker.patch("app.commands.current_app")
|
||||
mock_dao_update_service = mocker.patch("app.commands.dao_update_service")
|
||||
mock_dao_fetch_service_by_id = mocker.patch("app.commands.dao_fetch_service_by_id")
|
||||
mock_get_user_by_email = mocker.patch("app.commands.get_user_by_email")
|
||||
@@ -579,8 +579,6 @@ def test_populate_go_live_success(notify_api, mocker):
|
||||
)
|
||||
mock_dao_update_service.assert_called_once_with(mock_service)
|
||||
|
||||
mock_logger.info.assert_any_call("Populate go live user and date")
|
||||
|
||||
|
||||
def test_process_row_from_job_success(notify_api, mocker):
|
||||
mock_current_app = mocker.patch("app.commands.current_app")
|
||||
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy import delete, func, select
|
||||
|
||||
from app import db
|
||||
from app.dao.service_user_dao import dao_get_service_user, dao_update_service_user
|
||||
from app.enums import AuthType, KeyType, NotificationType, PermissionType
|
||||
from app.enums import AuthType, KeyType, NotificationType, PermissionType, UserState
|
||||
from app.models import Notification, Permission, User
|
||||
from tests.app.db import (
|
||||
create_organization,
|
||||
@@ -110,7 +110,7 @@ def test_post_user(admin_request, notify_db_session):
|
||||
"password": "password",
|
||||
"mobile_number": "+12028675309",
|
||||
"logged_in_at": None,
|
||||
"state": "active",
|
||||
"state": "ACTIVE",
|
||||
"failed_login_count": 0,
|
||||
"permissions": {},
|
||||
"auth_type": AuthType.EMAIL,
|
||||
@@ -167,7 +167,7 @@ def test_post_user_missing_attribute_email(admin_request, notify_db_session):
|
||||
"password": "password",
|
||||
"mobile_number": "+12028675309",
|
||||
"logged_in_at": None,
|
||||
"state": "active",
|
||||
"state": "ACTIVE",
|
||||
"failed_login_count": 0,
|
||||
"permissions": {},
|
||||
}
|
||||
@@ -191,16 +191,18 @@ def test_create_user_missing_attribute_password(admin_request, notify_db_session
|
||||
|
||||
db.session.execute(delete(User))
|
||||
db.session.commit()
|
||||
|
||||
data = {
|
||||
"name": "Test User",
|
||||
"email_address": "user@digital.fake.gov",
|
||||
"mobile_number": "+12028675309",
|
||||
"logged_in_at": None,
|
||||
"state": "active",
|
||||
"state": "ACTIVE",
|
||||
"failed_login_count": 0,
|
||||
"permissions": {},
|
||||
}
|
||||
json_resp = admin_request.post("user.create_user", _data=data, _expected_status=400)
|
||||
|
||||
assert _get_user_count() == 0
|
||||
assert {"password": ["Missing data for required field."]} == json_resp["message"]
|
||||
|
||||
@@ -765,23 +767,23 @@ def test_send_user_confirm_new_email_returns_400_when_email_missing(
|
||||
|
||||
|
||||
def test_activate_user(admin_request, sample_user):
|
||||
sample_user.state = "pending"
|
||||
sample_user.state = UserState.PENDING
|
||||
|
||||
resp = admin_request.post("user.activate_user", user_id=sample_user.id)
|
||||
|
||||
assert resp["data"]["id"] == str(sample_user.id)
|
||||
assert resp["data"]["state"] == "active"
|
||||
assert sample_user.state == "active"
|
||||
assert sample_user.state == UserState.ACTIVE
|
||||
|
||||
|
||||
def test_deactivate_user(admin_request, sample_user):
|
||||
sample_user.state = "active"
|
||||
sample_user.state = UserState.ACTIVE
|
||||
|
||||
resp = admin_request.post("user.deactivate_user", user_id=sample_user.id)
|
||||
|
||||
assert resp["data"]["id"] == str(sample_user.id)
|
||||
assert resp["data"]["state"] == "pending"
|
||||
assert sample_user.state == "pending"
|
||||
assert sample_user.state == UserState.PENDING
|
||||
|
||||
|
||||
def test_activate_user_fails_if_already_active(admin_request, sample_user):
|
||||
@@ -789,7 +791,7 @@ def test_activate_user_fails_if_already_active(admin_request, sample_user):
|
||||
"user.activate_user", user_id=sample_user.id, _expected_status=400
|
||||
)
|
||||
assert resp["message"] == "User already active"
|
||||
assert sample_user.state == "active"
|
||||
assert sample_user.state == UserState.ACTIVE
|
||||
|
||||
|
||||
def test_update_user_auth_type(admin_request, sample_user):
|
||||
|
||||
Reference in New Issue
Block a user