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 25, 2023
1 parent 2f9cd06 commit dd2c5b2
Show file tree
Hide file tree
Showing 2 changed files with 23 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
22 changes: 22 additions & 0 deletions tests/integration/seeddb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.test.client import RequestFactory
from mock import MagicMock

from nav.compatibility import smart_str
from nav.models.manage import Netbox, Room
from nav.web.seeddb.page.netbox.edit import netbox_edit, log_netbox_change
from nav.web.seeddb.utils.delete import dependencies
Expand All @@ -28,6 +29,27 @@ def test_editing_deleted_netboxes_should_raise_404(admin_account):
netbox_edit(request, netboxid)


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 dd2c5b2

Please sign in to comment.