diff --git a/python/nav/web/seeddb/page/netbox/forms.py b/python/nav/web/seeddb/page/netbox/forms.py index 3dde54c40b..7f956a5cad 100644 --- a/python/nav/web/seeddb/page/netbox/forms.py +++ b/python/nav/web/seeddb/page/netbox/forms.py @@ -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 diff --git a/tests/integration/seeddb_test.py b/tests/integration/seeddb_test.py index b34f996646..0a11c10811 100644 --- a/tests/integration/seeddb_test.py +++ b/tests/integration/seeddb_test.py @@ -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(