def test_cannot_create_duplicate_feature_state_in_an_environment(self):
        # Given
        duplicate_feature_state = FeatureState(feature=self.feature,
                                               environment=self.environment,
                                               enabled=True)

        # When
        with pytest.raises(ValidationError):
            duplicate_feature_state.save()

        # Then
        assert FeatureState.objects.filter(
            feature=self.feature, environment=self.environment).count() == 1
Exemple #2
0
 def test_should_remove_identityfeature_when_delete(self):
     # Given
     client = self.set_up()
     organisation = Organisation.objects.get(name="test org")
     project = Project.objects.get(name="test project",
                                   organisation=organisation)
     feature_one = Feature(name='feature1', project=project)
     feature_one.save()
     feature_two = Feature(name='feature2', project=project)
     feature_two.save()
     environment = Environment.objects.get(name="test env")
     identity = Identity(identifier="test_identity",
                         environment=environment)
     identity.save()
     environment = Environment.objects.get(name="test env")
     identity_feature_one = FeatureState(feature=feature_one,
                                         identity=identity,
                                         enabled=False,
                                         environment=environment)
     identity_feature_one.save()
     identity_feature_two = FeatureState(feature=feature_two,
                                         identity=identity,
                                         enabled=True,
                                         environment=environment)
     identity_feature_two.save()
     # When
     client.delete(self.feature_states_detail_url %
                   (identity.environment.api_key, identity.identifier,
                    identity_feature_one.id),
                   content_type='application/json')
     # Then
     identity_features = FeatureState.objects.filter(identity=identity)
     self.assertEquals(identity_features.count(), 1)
     Helper.clean_up()
    def save(self, *args, **kwargs):
        """
        Override save method to initialise feature states for all features in new environment
        """
        super(Environment, self).save(*args, **kwargs)

        # also create feature states for all features in the project
        features = self.project.features.all()
        for feature in features:
            feature_state = FeatureState(feature=feature,
                                         environment=self,
                                         identity=None,
                                         enabled=False)
            feature_state.save()
Exemple #4
0
    def test_cannot_create_duplicate_feature_state_in_an_environment(
            self, mock_trigger_webhooks):
        """
        Note that although the mock isn't used in this test, it throws an exception on it's thread so we mock it
        here anyway.
        """
        # Given
        duplicate_feature_state = FeatureState(feature=self.feature,
                                               environment=self.environment,
                                               enabled=True)

        # When
        with pytest.raises(ValidationError):
            duplicate_feature_state.save()

        # Then
        assert (FeatureState.objects.filter(
            feature=self.feature, environment=self.environment).count() == 1)
Exemple #5
0
 def test_should_change_enabled_state_when_put(self):
     # Given
     client = self.set_up()
     organisation = Organisation.objects.get(name="test org")
     project = Project.objects.get(name="test project",
                                   organisation=organisation)
     feature = Feature(name='feature1', project=project)
     feature.save()
     environment = Environment.objects.get(name="test env")
     identity = Identity(identifier="test_identity",
                         environment=environment)
     identity.save()
     feature_state = FeatureState(feature=feature,
                                  identity=identity,
                                  enabled=False,
                                  environment=environment)
     feature_state.save()
     # When
     response = client.put(self.feature_states_detail_url %
                           (identity.environment.api_key,
                            identity.identifier, feature_state.id),
                           data=self.put_template % True,
                           content_type='application/json')
     feature_state.refresh_from_db()
     # Then
     self.assertEquals(response.status_code, status.HTTP_200_OK)
     self.assertEquals(feature_state.enabled, True)
     Helper.clean_up()