Skip to content

Commit

Permalink
Create related objects with similar names in workspace factories
Browse files Browse the repository at this point in the history
When using a factory to create various types of workspaces (e.g.,
dbGaPWorkspaceFactory, CDSAWorkspaceFactory, ...), set the name of
any related object using the name of the workspace. Examples: the
auth domain for that workspace, an associated writers group, etc.
This mimics how we create them for real.
  • Loading branch information
amstilp committed Jan 24, 2024
1 parent 27c7d16 commit 139f61d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion primed/cdsa/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def authorization_domains(self, create, extracted, **kwargs):
return

# Create an authorization domain.
auth_domain = ManagedGroupFactory.create()
auth_domain = ManagedGroupFactory.create(
name="auth_{}".format(self.workspace.name)
)
self.workspace.authorization_domains.add(auth_domain)

class Meta:
Expand Down
13 changes: 10 additions & 3 deletions primed/collaborative_analysis/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ManagedGroupFactory,
WorkspaceFactory,
)
from factory import SubFactory, post_generation
from factory import LazyAttribute, SubFactory, post_generation
from factory.django import DjangoModelFactory

from primed.users.tests.factories import UserFactory
Expand All @@ -17,7 +17,12 @@ class Meta:

workspace = SubFactory(WorkspaceFactory, workspace_type="collab_analysis")
custodian = SubFactory(UserFactory)
analyst_group = SubFactory(ManagedGroupFactory)
analyst_group = SubFactory(
ManagedGroupFactory,
name=LazyAttribute(
lambda o: "analysts_{}".format(o.factory_parent.workspace.name)
),
)

@post_generation
def authorization_domains(self, create, extracted, **kwargs):
Expand All @@ -27,7 +32,9 @@ def authorization_domains(self, create, extracted, **kwargs):
return

# Create an authorization domain.
auth_domain = ManagedGroupFactory.create()
auth_domain = ManagedGroupFactory.create(
name="auth_{}".format(self.workspace.name)
)
print(auth_domain)
self.workspace.authorization_domains.add(auth_domain)

Expand Down
4 changes: 3 additions & 1 deletion primed/dbgap/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def authorization_domains(self, create, extracted, **kwargs):
return

# Create an authorization domain.
auth_domain = ManagedGroupFactory.create()
auth_domain = ManagedGroupFactory.create(
name="auth_{}".format(self.workspace.name)
)
self.workspace.authorization_domains.add(auth_domain)


Expand Down

0 comments on commit 139f61d

Please sign in to comment.