Skip to content

Commit

Permalink
Updates following peer review.
Browse files Browse the repository at this point in the history
  • Loading branch information
manstis committed Feb 8, 2024
1 parent 08ac0d5 commit 9616944
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
4 changes: 3 additions & 1 deletion ansible_wisdom/ai/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def is_schema_2_telemetry_enabled(self, org_id: int) -> bool:
if self.client:
logger.debug(f"constructing User context for Organization '{org_id}'")
logger.debug(f"retrieving feature flag '{WisdomFlags.SCHEMA_2_TELEMETRY_ORG_ENABLED}'")
context = Context.builder(str(org_id)).set("org_id", org_id).build()
context = (
Context.builder(str(org_id)).kind("organization").set("org_id", org_id).build()
)
return self.client.variation(WisdomFlags.SCHEMA_2_TELEMETRY_ORG_ENABLED, context, False)
else:
raise Exception("feature flag client is not initialized")
2 changes: 1 addition & 1 deletion ansible_wisdom/ai/tests/test_feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_feature_flags_is_schema_2_telemetry_enabled(self, LDClient):
name: str = args[0][0]
context: Context = args[0][1]
self.assertEqual(name, WisdomFlags.SCHEMA_2_TELEMETRY_ORG_ENABLED)
self.assertEqual(context.kind, 'user')
self.assertEqual(context.kind, 'organization')
self.assertEqual(context.key, '123')
self.assertEqual(context.custom_attributes['org_id'], 123)
self.assertFalse(args[0][2])
48 changes: 27 additions & 21 deletions ansible_wisdom/organizations/tests/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,45 @@
from organizations.models import Organization


class TestIsOrgLightspeedSubscriber(TestCase):
def test_org_with_telemetry_schema_2_enabled(self):
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=True)[0]
self.assertFalse(organization.is_schema_2_telemetry_override_enabled)

def test_org_with_telemetry_schema_2_disabled(self):
class TestOrganization(TestCase):
def test_org_with_telemetry_schema_2_opted_in(self):
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0]
self.assertFalse(organization.is_schema_2_telemetry_override_enabled)
self.assertFalse(organization.telemetry_opt_out)
self.assertFalse(organization.is_schema_2_telemetry_enabled)

def test_org_with_telemetry_schema_2_opted_out(self):
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=True)[0]
self.assertTrue(organization.telemetry_opt_out)
self.assertFalse(organization.is_schema_2_telemetry_enabled)

@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key')
@patch.object(feature_flags, 'LDClient')
def test_org_with_telemetry_schema_2_disabled_with_feature_flags(self, LDClient):
LDClient.return_value.variation.return_value = ''
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0]
self.assertFalse(organization.is_schema_2_telemetry_override_enabled)
def test_org_with_telemetry_schema_2_opted_in_with_feature_flag_override(self, LDClient):
LDClient.return_value.variation.return_value = True
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=True)[0]
self.assertTrue(organization.telemetry_opt_out)
self.assertTrue(organization.is_schema_2_telemetry_enabled)

@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key')
@patch.object(feature_flags, 'LDClient')
def test_org_with_telemetry_schema_2_disabled_with_feature_flags_no_override(self, LDClient):
LDClient.return_value.variation.return_value = '999'
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0]
self.assertFalse(organization.is_schema_2_telemetry_override_enabled)
def test_org_with_telemetry_schema_2_opted_in_with_feature_flag_no_override(self, LDClient):
LDClient.return_value.variation.return_value = False
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=True)[0]
self.assertTrue(organization.telemetry_opt_out)
self.assertFalse(organization.is_schema_2_telemetry_enabled)

@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key')
@patch.object(feature_flags, 'LDClient')
def test_org_with_telemetry_schema_2_disabled_with_feature_flags_with_override(self, LDClient):
LDClient.return_value.variation.return_value = '123'
def test_org_with_telemetry_schema_2_opted_out_with_feature_flag_override(self, LDClient):
LDClient.return_value.variation.return_value = True
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0]
self.assertTrue(organization.is_schema_2_telemetry_override_enabled)
self.assertFalse(organization.telemetry_opt_out)
self.assertTrue(organization.is_schema_2_telemetry_enabled)

@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key')
@patch.object(feature_flags, 'LDClient')
def test_org_with_telemetry_schema_2_disabled_with_feature_flags_with_overrides(self, LDClient):
LDClient.return_value.variation.return_value = '000,999,123'
def test_org_with_telemetry_schema_2_opted_out_with_feature_flag_no_override(self, LDClient):
LDClient.return_value.variation.return_value = False
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0]
self.assertTrue(organization.is_schema_2_telemetry_override_enabled)
self.assertFalse(organization.telemetry_opt_out)
self.assertFalse(organization.is_schema_2_telemetry_enabled)

0 comments on commit 9616944

Please sign in to comment.