Skip to content

Commit

Permalink
🔧 chore(data-secrecy): update data secrecy tests & attempt to fix del…
Browse files Browse the repository at this point in the history
…ete endpoint (#79228)

i am trying to use another way to get the waiver entry and delete it
because i have a bizarre issue that i can't replicate where the delete
method returns a 404 when the waiver exists.

also improved the tests
  • Loading branch information
iamrajjoshi authored Oct 16, 2024
1 parent b59ae68 commit 5ed1ade
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/sentry/data_secrecy/api/waive_data_secrecy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def put(self, request: Request, organization: Organization):
serialize(ds, request.user, DataSecrecyWaiverSerializer()), status=status.HTTP_200_OK
)

def delete(self, request: Request, organization):
def delete(self, request: Request, organization: Organization):
"""
Reinstates data secrecy for an organization.
"""
try:
ds = get_object_or_404(DataSecrecyWaiver, organization=organization)
ds = DataSecrecyWaiver.objects.get(organization=organization)
ds.delete()

self.create_audit_entry(
Expand All @@ -136,7 +136,7 @@ def delete(self, request: Request, organization):
{"detail": "Data secrecy has been reinstated."},
status=status.HTTP_204_NO_CONTENT,
)
except Http404:
except DataSecrecyWaiver.DoesNotExist:
return Response(
{"detail": "No data secrecy waiver found for this organization."},
status=status.HTTP_404_NOT_FOUND,
Expand Down
12 changes: 11 additions & 1 deletion tests/sentry/data_secrecy/api/test_waive_data_secrecy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def test_put_update(self):
assert ds.access_start == datetime.now(tz=timezone.utc) + timedelta(days=1)
assert ds.access_end == datetime.now(tz=timezone.utc) + timedelta(days=2)

assert_org_audit_log_exists(
organization=self.org,
event=audit_log.get_event_id("DATA_SECRECY_WAIVED"),
)

@freeze_time(datetime(2024, 7, 18, 0, 0, 0, tzinfo=timezone.utc))
def test_put_invalid_dates(self):
self.body_params["accessEnd"] = self.body_params["accessStart"]
Expand Down Expand Up @@ -120,10 +125,15 @@ def test_delete_existing_waiver(self):
)

with outbox_runner():
self.get_success_response(self.org.slug, method="delete")
self.get_success_response(self.org.slug, method="delete", status_code=204)

assert DataSecrecyWaiver.objects.filter(organization=self.org).first() is None

assert_org_audit_log_exists(
organization=self.org,
event=audit_log.get_event_id("DATA_SECRECY_REINSTATED"),
)

@freeze_time(datetime(2024, 7, 18, 0, 0, 0, tzinfo=timezone.utc))
def test_delete_non_existing_waiver(self):
self.get_error_response(self.org.slug, method="delete", status_code=404)

0 comments on commit 5ed1ade

Please sign in to comment.