-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update feature flag keys (#1192)
* refactor: Update feature flag keys and improve error logging in AuthService * test: Add unit tests for community admin testimonial nudge functionality * test: Remove debug print statement from CadminTestimonialNudge test * refactor: Improve community admin authorization check in EventStore * refactor: Remove unnecessary user_info parameter from send_events_report call in download_data * fix: Handle case where community may be None in Action model serialization * refactor: Simplify admin authorization check in EventStore and enhance test coverage for file URL retrieval
- Loading branch information
1 parent
2f571ee
commit 3bddeed
Showing
9 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
# # Create your tests here. | ||
class GetFileUrlTests(TestCase): | ||
|
||
def setUp(self): | ||
self.m1 = makeMedia(name="m1") | ||
self.m2 = makeMedia(name="m2", file=None) | ||
|
||
def test_get_file_url_with_no_image(self): | ||
result = _get_file_url(None) | ||
self.assertEqual(result, "") | ||
|
||
def test_get_file_url_with_file(self): | ||
result = _get_file_url(self.m1) | ||
self.assertRegex(result, r'^/media/media/.*$') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters