Skip to content

Commit

Permalink
Merge pull request #467 from UW-GAC/feature/max-length-of-anvil-resou…
Browse files Browse the repository at this point in the history
…rces

Set max_length to match what AnVIL allows
  • Loading branch information
amstilp authored Mar 8, 2024
2 parents 68b936e + cdffdf5 commit e23096e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add customizeable `get_extra_detail_context_data` method for workspace adapters. Users can override this method to provide additional context data on a workspace detail page.
* Add filtering by workspace type to the admin interface.
* Set max_length for `ManagedGroup` and `Workspace` models to match what AnVIL allows.

## 0.21.0 (2023-12-04)

Expand Down
2 changes: 1 addition & 1 deletion anvil_consortium_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.22.0.dev1"
__version__ = "0.22.0.dev2"
8 changes: 6 additions & 2 deletions anvil_consortium_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ def has_workspace_access(self, workspace):
class ManagedGroup(TimeStampedModel):
"""A model to store information about AnVIL Managed Groups."""

name = models.SlugField(max_length=64, unique=True, help_text="Name of the group on AnVIL.")
name = models.SlugField(
max_length=60, # Max allowed by AnVIL.
unique=True,
help_text="Name of the group on AnVIL.",
)
email = models.EmailField(
help_text="Email for this group.",
blank=False,
Expand Down Expand Up @@ -630,7 +634,7 @@ class Workspace(TimeStampedModel):
help_text="Billing project associated with this Workspace.",
)
name = models.SlugField(
max_length=64,
max_length=254, # Max allowed by AnVIL.
help_text="Name of the workspace on AnVIL, not including billing project name.",
)
# This makes it possible to easily select the authorization domains in the WorkspaceForm.
Expand Down
17 changes: 17 additions & 0 deletions anvil_consortium_manager/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,14 @@ def test_unique_name(self):
with self.assertRaises(IntegrityError):
instance2.save()

def test_name_max_length(self):
"""ValidationError is raised when the group name is too long."""
instance = factories.ManagedGroupFactory.build(name="a" * 60)
instance.full_clean()
instance = factories.ManagedGroupFactory.build(name="a" * 61)
with self.assertRaises(ValidationError):
instance.full_clean()

def test_unique_email(self):
"""Saving a model with a duplicate name fails."""
instance = factories.ManagedGroupFactory.create()
Expand Down Expand Up @@ -1480,6 +1488,15 @@ def test_model_saving(self):
instance.save()
self.assertIsInstance(instance, Workspace)

def test_name_max_length(self):
"""ValidationError is raised when the group name is too long."""
billing_project = factories.BillingProjectFactory.create()
instance = factories.WorkspaceFactory.build(billing_project=billing_project, name="a" * 254)
instance.full_clean()
instance = factories.WorkspaceFactory.build(billing_project=billing_project, name="a" * 255)
with self.assertRaises(ValidationError):
instance.full_clean()

def test_note_field(self):
"""Creation using the model constructor and .save() works when note is set."""
billing_project = factories.BillingProjectFactory.create()
Expand Down

0 comments on commit e23096e

Please sign in to comment.