Skip to content

Commit

Permalink
Merge pull request #3366 from uktrade/DT-2407-add-table-update-number…
Browse files Browse the repository at this point in the history
…s-validation-for-table-names-and-descriptive-names

fix/allow-add-numbers-to-table-name-validation
  • Loading branch information
JamesPRobinson authored Nov 21, 2024
2 parents 8a709d6 + 9b27cd1 commit 882a0fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dataworkspace/dataworkspace/apps/datasets/add_table/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def clean_table_name(self):
table_name = str(cleaned_data["table_name"])
if len(table_name) > 42:
raise ValidationError("Table name must be 42 characters or less")
elif bool(re.search(r"[^A-Za-z_]", table_name)):
raise ValidationError("Table name cannot contain numbers or special characters")
elif bool(re.search(r"[^A-Za-z0-9_]", table_name)):
raise ValidationError("Table name cannot contain special characters")
elif table_name in self.table_names:
raise ValidationError("Table name already in use")
elif "dataset" in table_name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def setUp(self):
government_security_classification=2,
)
self.source = factories.SourceTableFactory.create(
dataset=self.dataset, schema="test", table="table_one", name="table_one"
dataset=self.dataset, schema="test", table="table_one", name="table_1"
)
self.descriptive_name = "my_table"

Expand Down Expand Up @@ -475,8 +475,8 @@ def test_error_shows_when_table_name_input_is_over_42_characters(self):
assert "There is a problem" in error_header_text
assert "Table name must be 42 characters or less" in error_message_text

def test_error_shows_when_table_name_contains_special_characters_or_numbers(self):
invalid_names = ["specialCharacter@", "has spaces", "numbers123"]
def test_error_shows_when_table_name_contains_special_characters(self):
invalid_names = ["specialCharacter@", "has spaces"]
for invalid_name in invalid_names:
response = self.get_post_response(invalid_name)

Expand All @@ -488,7 +488,7 @@ def test_error_shows_when_table_name_contains_special_characters_or_numbers(self

assert response.status_code == 200
assert "There is a problem" in error_header_text
assert "Table name cannot contain numbers or special characters" in error_message_text
assert "Table name cannot contain special characters" in error_message_text

def test_error_shows_when_table_name_is_already_in_use(self):
response = self.get_post_response(self.source.table)
Expand Down

0 comments on commit 882a0fd

Please sign in to comment.