Skip to content

Commit

Permalink
Fix adding netbox with non existing profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Nov 28, 2023
1 parent cbad667 commit a2a1890
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/nav/web/seeddb/page/netbox/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def clean(self):
self._errors['profiles'] = self.error_class(
["Category %s requires a management profile." % cat.id]
)
del cleaned_data['profiles']
cleaned_data.pop('profiles', None)

return cleaned_data

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/seeddb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ def test_adding_netbox_with_invalid_ip_should_fail(db, client):
assert 'Could not resolve name' in smart_str(response.content)


def test_adding_netbox_with_invalid_profiles_should_fail(db, client):
url = reverse('seeddb-netbox-edit')
ip = "10.254.254.253"

response = client.post(
url,
follow=True,
data={
"ip": ip,
"room": "myroom",
"category": "GW",
"organization": "myorg",
"profiles": "-5785')) ORDER BY 1-- qAPu",
},
)

assert response.status_code == 200
assert 'Form was not valid' in smart_str(response.content)
assert not Netbox.objects.filter(ip=ip).exists()


@pytest.fixture()
def netbox(management_profile):
box = Netbox(
Expand Down

0 comments on commit a2a1890

Please sign in to comment.