Argus icon indicating copy to clipboard operation
Argus copied to clipboard

Move common functionality to destination base class

Open hmpf opened this issue 1 year ago • 11 comments

Best reviewed per file.

hmpf avatar Nov 11 '24 14:11 hmpf

Codecov Report

Attention: Patch coverage is 69.82249% with 51 lines in your changes missing coverage. Please review.

Project coverage is 76.70%. Comparing base (eaa3a25) to head (713e5d5). Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/argus/notificationprofile/media/base.py 62.10% 36 Missing :warning:
src/argus/notificationprofile/media/email.py 80.95% 8 Missing :warning:
src/argus/notificationprofile/media/__init__.py 42.85% 4 Missing :warning:
src/argus/notificationprofile/serializers.py 89.47% 2 Missing :warning:
...rc/argus/notificationprofile/media/sms_as_email.py 83.33% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #936      +/-   ##
==========================================
- Coverage   77.36%   76.70%   -0.66%     
==========================================
  Files         141      141              
  Lines        5548     5667     +119     
==========================================
+ Hits         4292     4347      +55     
- Misses       1256     1320      +64     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Dec 03 '24 08:12 codecov-commenter

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not

We do have tests for when trying to change the medium that that will lead to an error

We are now way out of scope for a refactor.

I guess the underlying problem is that we cannot lookup and change destinations of a specific media type directly, as part of the url of the endpoint. If we could, we would never need bother with media in the update-serializer.

hmpf avatar Dec 06 '24 10:12 hmpf

I just checked and we don't have a test for trying to PATCH update with medium being empty, that should be added, I think then it would be clearer if the changes work or not We do have tests for when trying to change the medium that that will lead to an error

We are now way out of scope for a refactor.

Yes, I agree, I can do this in another PR, but that would have to merged before this then, because it would show if the functionality is staying the same

johannaengland avatar Dec 06 '24 11:12 johannaengland

I don't think it is wise to stress with finishing this PR this week anymore, so start on the patch-PR next week.

hmpf avatar Dec 06 '24 11:12 hmpf

I decided to pass in the DestinationConfig instance (if any) to the clean-method so that it will have access to the currently stored settings.

hmpf avatar Jan 08 '25 12:01 hmpf

We could change the __str__ function of DestinationConfig change to use the get_label function in general. Then we can simplify this

Originally posted by @johannaengland in https://github.com/Uninett/Argus/pull/1118#discussion_r1914806712

hmpf avatar Jan 15 '25 07:01 hmpf

I got stuff mostly working with this but the main problem is extracting errors to show in the related fields

stveit avatar Jan 15 '25 14:01 stveit

Updating existing destination is still buggy. It allows me to update either the email on its own or the label and email together. it does not allow me to only update the label, or just click update without making any changes. In the cases where it doesnt work this is the server log error:

2025-03-14 11:57:19,231 django.request ERROR    Internal Server Error: /destinations/9/htmx-update/
Traceback (most recent call last):
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/django/views/decorators/http.py", line 64, in inner
    return func(request, *args, **kwargs)
  File "/home/simon/repos/Argus/src/argus/htmx/destination/views.py", line 58, in update_htmx
    form.save()
  File "/home/simon/repos/Argus/src/argus/htmx/destination/forms.py", line 37, in save
    self.serializer.save(user=self.request.user)
  File "/home/simon/repos/Argus/venv/lib/python3.10/site-packages/rest_framework/serializers.py", line 180, in save
    assert not self.errors, (
AssertionError: You cannot call `.save()` on a serializer with invalid data.
2025-03-14 11:57:19,233 django.server INFO     "POST /destinations/9/htmx-update/ HTTP/1.1" 200 814

stveit avatar Mar 14 '25 10:03 stveit