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

🔧 chore(data-secrecy): update data secrecy tests & attempt to fix delete endpoint #79228

Merged
merged 2 commits into from
Oct 16, 2024
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
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)
Loading