import re from tests.atlas_um import factories from atlas_um.applications import services UUID_RE = re.compile( r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", re.I, ) def test_create_application_service(pgdb_session, faker): test_name = faker.pystr() test_resource_group = factories.ResourceGroupFactory() test_dna_account = factories.DNAAccountFactory() test_audience = faker.pystr() test_ttl = faker.pyint() test_scope = faker.pystr() result = services.CreateApplicationService.execute( dna_account=test_dna_account, resource_group=test_resource_group, name=test_name, audience=test_audience, ttl=test_ttl, scope=test_scope, ) assert result.is_right application = result.value assert application.name == test_name assert application.dna_account == test_dna_account assert application.resource_group == test_resource_group assert application.audience == test_audience assert application.ttl == test_ttl assert application.scope == test_scope assert UUID_RE.match(application.client_id) assert UUID_RE.match(application.client_secret) def test_update_application_service(pgdb_session, faker): application = factories.ApplicationFactory() test_name = faker.pystr() test_resource_group = factories.ResourceGroupFactory() test_audience = faker.pystr() test_ttl = faker.pyint() test_scope = faker.pystr() result = services.UpdateApplicationService.execute( application=application, resource_group=test_resource_group, name=test_name, audience=test_audience, ttl=test_ttl, scope=test_scope, ) assert result.is_right application = result.value assert application.name == test_name assert application.resource_group == test_resource_group assert application.audience == test_audience assert application.ttl == test_ttl assert application.scope == test_scope assert UUID_RE.match(application.client_id) assert UUID_RE.match(application.client_secret) def test_reset_client_secret_service(pgdb_session, faker): application = factories.ApplicationFactory() old_secret = application.client_secret result = services.ResetClientSecretService.execute(application=application) assert result.is_right application = result.value assert UUID_RE.match(application.client_secret) assert old_secret != application.client_secret def test_delete_application_service(pgdb_session): application = factories.ApplicationFactory() assert not application.is_deleted result = services.DeleteApplicationService.execute(application=application) assert result.is_right application = result.value assert application.is_deleted