Add environment_roles.cloud_id and update query for finding pending
roles.
This commit is contained in:
parent
cdf6a469ed
commit
7c7dd08827
@ -0,0 +1,30 @@
|
||||
"""change to environment_roles.cloud_Id
|
||||
|
||||
Revision ID: 418b52c1cedf
|
||||
Revises: 17da2a475429
|
||||
Create Date: 2020-02-05 13:40:37.870183
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '418b52c1cedf' # pragma: allowlist secret
|
||||
down_revision = '17da2a475429' # pragma: allowlist secret
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('environment_roles', sa.Column('cloud_id', sa.String(), nullable=True))
|
||||
op.drop_column('environment_roles', 'csp_user_id')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('environment_roles', sa.Column('csp_user_id', sa.VARCHAR(), autoincrement=False, nullable=True))
|
||||
op.drop_column('environment_roles', 'cloud_id')
|
||||
# ### end Alembic commands ###
|
@ -90,14 +90,18 @@ class EnvironmentRoles(object):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_environment_roles_pending_creation(cls) -> List[UUID]:
|
||||
def get_pending_creation(cls) -> List[UUID]:
|
||||
results = (
|
||||
db.session.query(EnvironmentRole.id)
|
||||
.join(Environment)
|
||||
.join(ApplicationRole)
|
||||
.filter(Environment.deleted == False)
|
||||
.filter(EnvironmentRole.status == EnvironmentRole.Status.PENDING)
|
||||
.filter(ApplicationRole.status == ApplicationRoleStatus.ACTIVE)
|
||||
.filter(EnvironmentRole.deleted == False)
|
||||
.filter(ApplicationRole.deleted == False)
|
||||
.filter(ApplicationRole.cloud_id != None)
|
||||
.filter(ApplicationRole.status != ApplicationRoleStatus.DISABLED)
|
||||
.filter(EnvironmentRole.status != EnvironmentRole.Status.DISABLED)
|
||||
.filter(EnvironmentRole.cloud_id.is_(None))
|
||||
.all()
|
||||
)
|
||||
return [id_ for id_, in results]
|
||||
|
@ -36,7 +36,7 @@ class EnvironmentRole(
|
||||
)
|
||||
application_role = relationship("ApplicationRole")
|
||||
|
||||
csp_user_id = Column(String())
|
||||
cloud_id = Column(String())
|
||||
|
||||
class Status(Enum):
|
||||
PENDING = "pending"
|
||||
|
@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from atst.domain.environment_roles import EnvironmentRoles
|
||||
from atst.models.environment_role import EnvironmentRole
|
||||
from atst.models import EnvironmentRole, ApplicationRoleStatus
|
||||
|
||||
from tests.factories import *
|
||||
|
||||
@ -161,3 +161,34 @@ def test_for_user(application_role):
|
||||
assert len(env_roles) == 3
|
||||
assert env_roles == [env_role_1, env_role_2, env_role_3]
|
||||
assert not rando_env_role in env_roles
|
||||
|
||||
|
||||
class TestPendingCreation:
|
||||
def test_pending_role(self):
|
||||
appr = ApplicationRoleFactory.create(cloud_id="123")
|
||||
envr = EnvironmentRoleFactory.create(application_role=appr)
|
||||
assert EnvironmentRoles.get_pending_creation() == [envr.id]
|
||||
|
||||
def test_deleted_role(self):
|
||||
appr = ApplicationRoleFactory.create(cloud_id="123")
|
||||
envr = EnvironmentRoleFactory.create(application_role=appr, deleted=True)
|
||||
assert EnvironmentRoles.get_pending_creation() == []
|
||||
|
||||
def test_not_ready_role(self):
|
||||
appr = ApplicationRoleFactory.create(cloud_id=None)
|
||||
envr = EnvironmentRoleFactory.create(application_role=appr)
|
||||
assert EnvironmentRoles.get_pending_creation() == []
|
||||
|
||||
def test_disabled_app_role(self):
|
||||
appr = ApplicationRoleFactory.create(
|
||||
cloud_id="123", status=ApplicationRoleStatus.DISABLED
|
||||
)
|
||||
envr = EnvironmentRoleFactory.create(application_role=appr)
|
||||
assert EnvironmentRoles.get_pending_creation() == []
|
||||
|
||||
def test_disabled_env_role(self):
|
||||
appr = ApplicationRoleFactory.create(cloud_id="123")
|
||||
envr = EnvironmentRoleFactory.create(
|
||||
application_role=appr, status=EnvironmentRole.Status.DISABLED
|
||||
)
|
||||
assert EnvironmentRoles.get_pending_creation() == []
|
||||
|
Loading…
x
Reference in New Issue
Block a user