Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize variables that are potentially referenced before assignment in maintenance edit() view #2784

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions python/nav/web/maintenance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ def cancel(request, task_id):
def edit(request, task_id=None, start_time=None, **_):
account = get_account(request)
quickselect = QuickSelect(service=True)
component_trail = None
component_keys = None
task = None
component_trail = component_keys_errors = component_data = task = None
lunkwill42 marked this conversation as resolved.
Show resolved Hide resolved

if task_id:
task = get_object_or_404(MaintenanceTask, pk=task_id)
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/web/maintenance/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
# more details. You should have received a copy of the GNU General Public
# License along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
import datetime

import pytest
from django.urls import reverse

from nav.compatibility import smart_str
from nav.models.manage import Netbox
from nav.models.msgmaint import MaintenanceTask
Expand Down Expand Up @@ -136,3 +139,27 @@ def test_with_end_time_before_start_time_should_fail(self, db, client, localhost
assert not MaintenanceTask.objects.filter(
description=data["description"]
).exists()


class TestEditMaintenanceTask:
def test_when_existing_task_is_requested_it_should_render_with_intact_description(
self, db, client, localhost, empty_maintenance_task
):
url = reverse("maintenance-edit", kwargs={"task_id": empty_maintenance_task.id})
response = client.get(url, follow=True)

assert response.status_code == 200
assert empty_maintenance_task.description in smart_str(response.content)


@pytest.fixture
def empty_maintenance_task(db):
now = datetime.datetime.now()
task = MaintenanceTask(
start_time=now,
end_time=now + datetime.timedelta(hours=1),
description="Temporary test fixture task",
)
task.save()
yield task
task.delete()
Loading