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()
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 test_should_return_identities_for_an_environment(self): client = self.set_up() # Given identifierOne = 'user1' identifierTwo = 'user2' organisation = Organisation(name='ssg') organisation.save() project = Project(name='project1', organisation=organisation) project.save() environment = Environment(name='environment1', project=project) environment.save() identityOne = Identity(identifier=identifierOne, environment=environment) identityOne.save() identityTwo = Identity(identifier=identifierTwo, environment=environment) identityTwo.save() # When response = client.get('/api/v1/environments/%s/identities/' % environment.api_key) # Then self.assertEquals(response.data['results'][0]['identifier'], identifierOne) self.assertEquals(response.data['results'][1]['identifier'], identifierTwo)
def generate_database_models(identifier='user1'): organisation = Organisation(name='ssg') organisation.save() project = Project(name='project1', organisation=organisation) project.save() environment = Environment(name='environment1', project=project) environment.save() feature = Feature(name="feature1", project=project) feature.save() identity = Identity(identifier=identifier, environment=environment) identity.save() return identity, project