This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/users/test/test_shared.py
Joseph Schorr 804d3c46c3 Add feature flag to allow users to be created only if invited to join a team
Allows for open user creation, but only if extended an invitation by someone who already has access
2017-09-14 16:28:39 -04:00

38 lines
1.3 KiB
Python

import pytest
from mock import patch
from data.database import model
from data.users.shared import can_create_user
from test.fixtures import *
@pytest.mark.parametrize('open_creation, invite_only, email, has_invite, can_create', [
# Open user creation => always allowed.
(True, False, None, False, True),
# Open user creation => always allowed.
(True, False, 'foo@example.com', False, True),
# Invite only user creation + no invite => disallowed.
(True, True, None, False, False),
# Invite only user creation + no invite => disallowed.
(True, True, 'foo@example.com', False, False),
# Invite only user creation + invite => allowed.
(True, True, 'foo@example.com', True, True),
# No open creation => Disallowed.
(False, True, 'foo@example.com', False, False),
(False, True, 'foo@example.com', True, False),
])
def test_can_create_user(open_creation, invite_only, email, has_invite, can_create, app):
if has_invite:
inviter = model.user.get_user('devtable')
team = model.team.get_organization_team('buynlarge', 'owners')
model.team.add_or_invite_to_team(inviter, team, email=email)
with patch('features.USER_CREATION', open_creation):
with patch('features.INVITE_ONLY_USER_CREATION', invite_only):
assert can_create_user(email) == can_create