Refactor tests

This commit is contained in:
leigh-mil 2020-02-13 11:28:15 -05:00
parent 207c34e536
commit 0deca6afcb

View File

@ -135,62 +135,63 @@ def test_create_application_job_is_idempotent(csp):
csp.create_application.assert_not_called() csp.create_application.assert_not_called()
def test_create_user_job(session, csp, app): class TestCreateUserJob:
portfolio = PortfolioFactory.create( @pytest.fixture
csp_data={ def portfolio(self, app):
"tenant_id": str(uuid4()), return PortfolioFactory.create(
"domain_name": f"rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}", csp_data={
} "tenant_id": str(uuid4()),
) "domain_name": f"rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}",
application = ApplicationFactory.create(portfolio=portfolio, cloud_id="321") }
user = UserFactory.create( )
first_name="Han", last_name="Solo", email="han@example.com"
)
app_role = ApplicationRoleFactory.create(
application=application,
user=user,
status=ApplicationRoleStatus.ACTIVE,
cloud_id=None,
)
session.begin_nested() @pytest.fixture
do_create_user(csp, [app_role.id]) def app_1(self, portfolio):
session.rollback() return ApplicationFactory.create(portfolio=portfolio, cloud_id="321")
assert app_role.cloud_id @pytest.fixture
def app_2(self, portfolio):
return ApplicationFactory.create(portfolio=portfolio, cloud_id="123")
@pytest.fixture
def user(self):
return UserFactory.create(
first_name="Han", last_name="Solo", email="han@example.com"
)
def test_create_user_sends_email(monkeypatch, csp): @pytest.fixture
mock = Mock() def app_role_1(self, app_1, user):
monkeypatch.setattr("atst.jobs.send_mail", mock) return ApplicationRoleFactory.create(
application=app_1,
user=user,
status=ApplicationRoleStatus.ACTIVE,
cloud_id=None,
)
portfolio = PortfolioFactory.create( @pytest.fixture
csp_data={ def app_role_2(self, app_2, user):
"tenant_id": str(uuid4()), return ApplicationRoleFactory.create(
"domain_name": "rebelalliance.onmicrosoft.com", application=app_2,
} user=user,
) status=ApplicationRoleStatus.ACTIVE,
application_1 = ApplicationFactory.create(portfolio=portfolio, cloud_id="321") cloud_id=None,
application_2 = ApplicationFactory.create(portfolio=portfolio, cloud_id="123") )
user = UserFactory.create() def test_create_user_job(self, session, csp, app_role_1):
assert not app_role_1.cloud_id
app_role_1 = ApplicationRoleFactory.create( session.begin_nested()
user=user, do_create_user(csp, [app_role_1.id])
application=application_1, session.rollback()
status=ApplicationRoleStatus.ACTIVE,
cloud_id=None,
)
app_role_2 = ApplicationRoleFactory.create( assert app_role_1.cloud_id
user=user,
application=application_2,
status=ApplicationRoleStatus.ACTIVE,
cloud_id=None,
)
do_create_user(csp, [app_role_1.id, app_role_2.id]) def test_create_user_sends_email(self, monkeypatch, csp, app_role_1, app_role_2):
assert mock.call_count == 1 mock = Mock()
monkeypatch.setattr("atst.jobs.send_mail", mock)
do_create_user(csp, [app_role_1.id, app_role_2.id])
assert mock.call_count == 1
def test_dispatch_create_environment(session, monkeypatch): def test_dispatch_create_environment(session, monkeypatch):