def test_unexpired_invite_is_revokable(): portfolio = PortfolioFactory.create() user = UserFactory.create() portfolio_role = PortfolioRoleFactory.create( portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING) invite = PortfolioInvitationFactory.create(role=portfolio_role) assert invite.is_revokable
def test_invite_is_not_revokable_if_invite_is_not_pending(): portfolio = PortfolioFactory.create() user = UserFactory.create() portfolio_role = PortfolioRoleFactory.create( portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING) invite = PortfolioInvitationFactory.create( role=portfolio_role, status=InvitationStatus.ACCEPTED) assert not invite.is_revokable
def test_revoke_invitation(): portfolio = PortfolioFactory.create() user = UserFactory.create() role = PortfolioRoleFactory.create(user=user, portfolio=portfolio) invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id) assert invite.is_pending PortfolioInvitations.revoke(invite.token) assert invite.is_revoked assert invite.role.status == PortfolioRoleStatus.DISABLED
def test_wrong_user_accepts_invitation(): user = UserFactory.create() portfolio = PortfolioFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio) wrong_user = UserFactory.create() invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id) with pytest.raises(WrongUserError): PortfolioInvitations.accept(wrong_user, invite.token) assert invite.role.status == PortfolioRoleStatus.PENDING
def test_accept_invitation_twice(): portfolio = PortfolioFactory.create() user = UserFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio) invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id) PortfolioInvitations.accept(user, invite.token) with pytest.raises(InvitationError): PortfolioInvitations.accept(user, invite.token) assert invite.role.is_active
def test_accept_revoked_invite(): user = UserFactory.create() portfolio = PortfolioFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio) invite = PortfolioInvitationFactory.create(status=InvitationStatus.REVOKED, role=role, dod_id=user.dod_id) with pytest.raises(InvitationError): PortfolioInvitations.accept(user, invite.token) assert invite.role.status == PortfolioRoleStatus.PENDING
def test_audit_event_for_accepted_invite(): portfolio = PortfolioFactory.create() user = UserFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio) invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id) invite = PortfolioInvitations.accept(user, invite.token) accepted_event = AuditLog.get_by_resource(invite.id)[0] assert "email" in accepted_event.event_details assert "dod_id" in accepted_event.event_details
def test_resend_invitation(session): portfolio = PortfolioFactory.create() user = UserFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio) first_invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id) assert first_invite.is_pending second_invite = PortfolioInvitations.resend(user, first_invite.token) assert first_invite.is_revoked assert second_invite.is_pending
def test_expired_invite_is_not_revokable(): portfolio = PortfolioFactory.create() user = UserFactory.create() portfolio_role = PortfolioRoleFactory.create( portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING) invite = PortfolioInvitationFactory.create( expiration_time=datetime.datetime.now() - datetime.timedelta(minutes=60), role=portfolio_role, ) assert not invite.is_revokable
def test_accept_expired_invitation(): user = UserFactory.create() portfolio = PortfolioFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio) increment = PortfolioInvitations.EXPIRATION_LIMIT_MINUTES + 1 expiration_time = datetime.datetime.now() - datetime.timedelta( minutes=increment) invite = PortfolioInvitationFactory.create( expiration_time=expiration_time, status=InvitationStatus.PENDING, role=role, dod_id=user.dod_id, ) with pytest.raises(ExpiredError): PortfolioInvitations.accept(user, invite.token) assert invite.is_rejected assert invite.role.status == PortfolioRoleStatus.PENDING