예제 #1
0
    def test_identify_integrations_segment_called(self, mock_segment_wrapper):
        # Given
        # segment configuration for environment
        SegmentConfiguration.objects.create(api_key="abc-123",
                                            environment=self.environment)
        identify_integrations(self.identity,
                              self.identity.get_all_feature_states())

        # and segment identify users should be called
        mock_segment_wrapper.assert_called()
예제 #2
0
    def test_identify_integrations_segment_and_amplitude_called(
            self, mock_amplitude_wrapper, mock_segment_wrapper):
        # Given
        SegmentConfiguration.objects.create(api_key="abc-123",
                                            environment=self.environment)
        AmplitudeConfiguration.objects.create(api_key="abc-123",
                                              environment=self.environment)
        identify_integrations(self.identity,
                              self.identity.get_all_feature_states())

        mock_segment_wrapper.assert_called()
        mock_amplitude_wrapper.assert_called()
예제 #3
0
    def _get_feature_states_for_user_response(self,
                                              identity,
                                              trait_models=None,
                                              features=None):
        """
        Get all feature (or a subset of them) states for an identity

        :param identity: Identity model to return feature states for
        :param trait_models: optional list of trait_models to apply over top of any already persisted traits for the identity
        :return: Response containing lists of both serialized flags and traits
        """
        shadowed_keys = [] if trait_models is None else map(
            lambda t: t.trait_key, trait_models)

        traits = identity.identity_traits.all(
        ) if trait_models is None else list(
            identity.identity_traits.all().exclude(
                trait_key__in=shadowed_keys)) + trait_models

        if features is None:
            feature_states = identity.get_all_feature_states(traits)
        else:
            feature_states = identity.get_feature_states(features, traits)

        serialized_flags = FeatureStateSerializerFull(feature_states,
                                                      many=True)

        serialized_traits = TraitSerializerBasic(traits, many=True)

        identify_integrations(identity, feature_states)

        response = {
            "flags": serialized_flags.data,
            "traits": serialized_traits.data
        }

        return Response(data=response, status=status.HTTP_200_OK)
예제 #4
0
    def _get_all_feature_states_for_user_response(self,
                                                  identity,
                                                  trait_models=None):
        """
        Get all feature states for an identity

        :param identity: Identity model to return feature states for
        :param trait_models: optional list of trait_models to pass in for organisations that don't persist them
        :return: Response containing lists of both serialized flags and traits
        """
        all_feature_states = identity.get_all_feature_states()
        serialized_flags = FeatureStateSerializerFull(all_feature_states,
                                                      many=True)
        serialized_traits = TraitSerializerBasic(
            identity.identity_traits.all(), many=True)

        identify_integrations(identity, all_feature_states)

        response = {
            "flags": serialized_flags.data,
            "traits": serialized_traits.data
        }

        return Response(data=response, status=status.HTTP_200_OK)