Skip to content

Commit

Permalink
Merge pull request #4725 from opensafely-core/iaindillingham/remove-i…
Browse files Browse the repository at this point in the history
…naccessible-validationerror

Remove inaccessible `ValidationError`
  • Loading branch information
iaindillingham authored Nov 8, 2024
2 parents 942f131 + ed8ddef commit c53ae33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 0 additions & 5 deletions jobserver/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ def clean(self):
msg = "Unknown repo, please reload the page and try again"
raise forms.ValidationError(msg)

# normalise branch names so we can do a case insensitive match
branches = [b.lower() for b in repo["branches"]]
if branch.lower() not in branches:
raise forms.ValidationError(f'Unknown branch "{branch}"')

def clean_name(self):
name = self.cleaned_data["name"].lower()

Expand Down
11 changes: 5 additions & 6 deletions tests/unit/jobserver/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,16 @@ def test_workspacecreateform_unknown_branch_validation_fails():
"branches": ["test-branch"],
}
]
form = WorkspaceCreateForm(repos_with_branches)
form.cleaned_data = {
data = {
"name": "test",
"repo": "http://example.com/derp/test-repo",
"branch": "unknown-branch",
"purpose": "For testing",
}
form = WorkspaceCreateForm(repos_with_branches, data)

with pytest.raises(ValidationError) as e:
form.clean()

assert e.value.message.startswith("Unknown branch")
assert not form.is_valid()
assert "branch" in form.errors


def test_workspacecreateform_unknown_repo_validation_fails():
Expand Down

0 comments on commit c53ae33

Please sign in to comment.