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

refactor: Update feature flag keys #1192

Merged
merged 7 commits into from
Dec 4, 2024
2 changes: 1 addition & 1 deletion src/_main_/utils/feature_flag_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
REMOVE_DUPLICATE_IMAGE_FF = "remove-duplicate-images-feature-flag"
UPDATE_ACTIONS_CONTENT_FF = "update-actions-content-feature-flag"
REWIRING_AMERICA_MENU_ITEM_FF = "rewiring-america-menu-item-feature-flag"
SHARED_TESTIMONIALS_NUDGE_FF = "shared-testimonials-nudge-feature-flag"
TESTIMONIAL_AUTO_SHARE_SETTINGS_NUDGE_FEATURE_FLAG_KEY = "testimonial-auto-sharing-feature-flag"
4 changes: 2 additions & 2 deletions src/api/services/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
else:
return None, None, CustomMassenergizeError("invalid_auth")
except PermissionError:
log.error("not_an_admin", level="error")
log.error("not_an_admin")

Check warning on line 84 in src/api/services/auth.py

View check run for this annotation

Codecov / codecov/patch

src/api/services/auth.py#L84

Added line #L84 was not covered by tests
return None, None, CustomMassenergizeError('not_an_admin')
except Exception as e:
print(e)
log.error("Authentication Error", level="error")
log.error("Authentication Error")

Check warning on line 88 in src/api/services/auth.py

View check run for this annotation

Codecov / codecov/patch

src/api/services/auth.py#L88

Added line #L88 was not covered by tests
return None, None, CustomMassenergizeError(e)


Expand Down
5 changes: 3 additions & 2 deletions src/api/store/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ def delete_event(self, context: Context, event_id) -> Tuple[dict, MassEnergizeAP
events = Event.objects.filter(id=event_id)
if not events:
return None, InvalidResourceError()

if not is_admin_of_community(context, events.first().community.id):

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

if len(events) > 1:
Expand Down
2 changes: 1 addition & 1 deletion src/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
for com in community_list:
events = generate_event_list_for_community(com)
event_list = events.get("events", [])
stat = send_events_report(user.full_name, user.email, event_list, user.user_info)
stat = send_events_report(user.full_name, user.email, event_list)

Check warning on line 122 in src/api/tasks.py

View check run for this annotation

Codecov / codecov/patch

src/api/tasks.py#L122

Added line #L122 was not covered by tests
if not stat:
error_notification(CADMIN_REPORT, email)
return
Expand Down
92 changes: 92 additions & 0 deletions src/api/tests/unit/tasks/test_cadmin_testimonial_nudge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from django.test.testcases import TestCase
from _main_.utils.feature_flag_keys import TESTIMONIAL_AUTO_SHARE_SETTINGS_NUDGE_FEATURE_FLAG_KEY
from _main_.utils.utils import Console
from api.tests.common import make_feature_flag, make_testimonial_auto_share_settings, makeAdmin, makeCommunity, makeTestimonial, makeUser
from database.models import TestimonialSharedCommunity
from database.utils.settings.model_constants.enums import SharingType
from task_queue.nudges.cadmin_testimonial_nudge import get_cadmin_names_and_emails, prepare_testimonials_for_community_admins
from django.utils import timezone

class CadminTestimonialNudgeTestCases(TestCase):

def setUp(self):
self.c1 = makeCommunity(name="Test Community 1")
self.c2 = makeCommunity(name="Test Community 2")
self.c3 = makeCommunity(name="Test Community 3")
self.c4 = makeCommunity(name="Test Community 4")
self.c5 = makeCommunity(name="Test Community 5")

user = makeUser(email="[email protected]", full_name="Test Admin")
user1 = makeUser(email="[email protected]", full_name="Test Admin 1")
user2 = makeUser(email="[email protected]", full_name="Test Admin 2")
user3 = makeUser(email="[email protected]", full_name="Test Admin 3")
user4 = makeUser(email="[email protected]", full_name="Test Admin 4")
makeAdmin(communities=[self.c1],admin=user)
makeAdmin(communities=[self.c2],admin=user1)
makeAdmin(communities=[self.c3],admin=user2)
makeAdmin(communities=[self.c4],admin=user3)
makeAdmin(communities=[self.c1],admin=user4)


make_feature_flag(
key=TESTIMONIAL_AUTO_SHARE_SETTINGS_NUDGE_FEATURE_FLAG_KEY,
communities=[self.c1, self.c2, self.c3, self.c4, self.c5],
audience="EVERYONE",
name="Testimonial Auto Share Settings Nudge"
)

t1 =makeTestimonial(
community=self.c2, user=user, title="Testimonial shared to c2 c3, c5",
sharing_type=SharingType.OPEN_TO.value[0], audience=[self.c2, self.c3, self.c5],
is_published=True,
published_at=timezone.now()
)
t2 = makeTestimonial(
community=self.c3, user=user, title="Testimonial shared to none",
sharing_type=SharingType.OPEN.value[0],
is_published=True,
published_at=timezone.now()
)
t3 = makeTestimonial(
community=self.c1, user=user, title="Testimonial shared to none for c1",
sharing_type=SharingType.OPEN.value[0],
is_published=True,
published_at=timezone.now()
)
t4 = makeTestimonial(
community=self.c3, user=user, title="Testimonial shared to none for c3",
sharing_type=SharingType.OPEN.value[0],
is_published=True,
published_at=timezone.now()
)
TestimonialSharedCommunity.objects.create(community=self.c2, testimonial=t1)
TestimonialSharedCommunity.objects.create(community=self.c3, testimonial=t1)
TestimonialSharedCommunity.objects.create(community=self.c5, testimonial=t1)
TestimonialSharedCommunity.objects.create(community=self.c1, testimonial=t3)
TestimonialSharedCommunity.objects.create(community=self.c3, testimonial=t4)


def tearDown(self):
return super().tearDown()


def test_get_cadmin_names_and_emails_success(self):

Console.header("Test get_cadmin_names_and_emails_success for c1")

data = get_cadmin_names_and_emails(self.c1)
keys = data.keys()
self.assertIn('[email protected]', keys)
self.assertIn('[email protected]', keys)
self.assertIsNotNone(data)



def test_prepare_testimonials_for_community_admins_success(self):
Console.header("Test prepare_testimonials_for_community_admins_success")
task = None
result = prepare_testimonials_for_community_admins(task)
self.assertTrue(result)



2 changes: 1 addition & 1 deletion src/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ def info(self):
"community":{
"id": self.community.id,
"name": self.community.name,
},
} if self.community else None,
"image": get_json_if_not_none(self.image),
}

Expand Down
4 changes: 2 additions & 2 deletions src/task_queue/nudges/cadmin_testimonial_nudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from _main_.utils.common import encode_data_for_URL, serialize_all
from _main_.utils.constants import ADMIN_URL_ROOT, COMMUNITY_URL_ROOT
from _main_.utils.emailer.send_email import send_massenergize_email_with_attachments
from _main_.utils.feature_flag_keys import SHARED_TESTIMONIALS_NUDGE_FF
from _main_.utils.feature_flag_keys import TESTIMONIAL_AUTO_SHARE_SETTINGS_NUDGE_FEATURE_FLAG_KEY
from _main_.utils.massenergize_logger import log
from api.utils.api_utils import get_sender_email
from api.utils.constants import CADMIN_TESTIMONIAL_NUDGE_TEMPLATE
Expand Down Expand Up @@ -113,7 +113,7 @@ def prepare_testimonials_for_community_admins(task=None):
"""
try:

flag = FeatureFlag.objects.get(key=SHARED_TESTIMONIALS_NUDGE_FF)
flag = FeatureFlag.objects.get(key=TESTIMONIAL_AUTO_SHARE_SETTINGS_NUDGE_FEATURE_FLAG_KEY)
if not flag or not flag.enabled():
return False

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

4 changes: 2 additions & 2 deletions src/website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@

def _get_file_url(image):
if not image:
return None
return image.file.url if image.file else None
return ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add test coverage for this. @abdullai-t

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

return image.file.url if image.file else ""

Check warning on line 314 in src/website/views.py

View check run for this annotation

Codecov / codecov/patch

src/website/views.py#L313-L314

Added lines #L313 - L314 were not covered by tests


def _separate_communities(communities, lat, long):
Expand Down
Loading