Skip to content

Commit

Permalink
refactor: Simplify admin authorization check in EventStore and enhanc…
Browse files Browse the repository at this point in the history
…e test coverage for file URL retrieval
  • Loading branch information
abdullai-t committed Dec 4, 2024
1 parent e25bd49 commit 8b3cd89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/api/store/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,8 @@ def delete_event(self, context: Context, event_id) -> Tuple[dict, MassEnergizeAP
return None, InvalidResourceError()

event_community = events.first().community
if event_community:
if not is_admin_of_community(context, event_community.id):
return None, NotAuthorizedError()
if event_community and not is_admin_of_community(context, event_community.id):
return None, NotAuthorizedError()

if len(events) > 1:
return None, CustomMassenergizeError("Deleting multiple events not supported")
Expand Down
20 changes: 18 additions & 2 deletions src/website/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# from django.test import TestCase
from django.test import TestCase
from unittest.mock import Mock
from api.tests.common import makeMedia
from website.views import _get_file_url

Check warning on line 4 in src/website/tests.py

View check run for this annotation

Codecov / codecov/patch

src/website/tests.py#L1-L4

Added lines #L1 - L4 were not covered by tests

# # Create your tests here.
class GetFileUrlTests(TestCase):

Check warning on line 6 in src/website/tests.py

View check run for this annotation

Codecov / codecov/patch

src/website/tests.py#L6

Added line #L6 was not covered by tests

def setUp(self):
self.m1 = makeMedia(name="m1")
self.m2 = makeMedia(name="m2", file=None)

Check warning on line 10 in src/website/tests.py

View check run for this annotation

Codecov / codecov/patch

src/website/tests.py#L8-L10

Added lines #L8 - L10 were not covered by tests

def test_get_file_url_with_no_image(self):
result = _get_file_url(None)
self.assertEqual(result, "")

Check warning on line 14 in src/website/tests.py

View check run for this annotation

Codecov / codecov/patch

src/website/tests.py#L12-L14

Added lines #L12 - L14 were not covered by tests

def test_get_file_url_with_file(self):
result = _get_file_url(self.m1)
self.assertRegex(result, r'^/media/media/.*$')

Check warning on line 18 in src/website/tests.py

View check run for this annotation

Codecov / codecov/patch

src/website/tests.py#L16-L18

Added lines #L16 - L18 were not covered by tests

0 comments on commit 8b3cd89

Please sign in to comment.