예제 #1
0
    def test_update_lookup_experiment(self):
        """
        On an experiment rename, make sure only resources that are children of
        the experiment are changed.

        This is a regression test.
        """
        new_exp_name = 'new_exp'
        collection = 'col2'
        orig_exp_name = 'exp1'

        collection_obj = Collection.objects.get(name=collection)
        experiment_obj = Experiment.objects.get(name=orig_exp_name,
                                                collection=collection_obj)
        lookup_key = str(collection_obj.pk) + '&' + str(experiment_obj.pk)
        boss_key = collection_obj.name + '&' + new_exp_name

        # Method under test.
        LookUpKey.update_lookup_experiment(lookup_key, boss_key,
                                           collection_obj.name, new_exp_name)

        # There should be still 5 rows in the lookup table with orig_exp_name
        # as the experiment name under col1.  There should be the experiment
        # and 4 channels.
        all_lookup_objs = BossLookup.objects.filter(
            experiment_name=orig_exp_name)
        self.assertEqual(5, len(all_lookup_objs))
예제 #2
0
    def test_update_lookup_experiment(self):
        """
        On an experiment rename, make sure only resources that are children of
        the experiment are changed.

        This is a regression test.
        """
        new_exp_name = 'new_exp'
        collection = 'col2'
        orig_exp_name = 'exp1'

        collection_obj = Collection.objects.get(name=collection)
        experiment_obj = Experiment.objects.get(name=orig_exp_name, collection=collection_obj)
        lookup_key = str(collection_obj.pk) + '&' + str(experiment_obj.pk)
        boss_key = collection_obj.name + '&' + new_exp_name

        # Method under test.
        LookUpKey.update_lookup_experiment(
                lookup_key, boss_key, collection_obj.name, new_exp_name)

        # There should be still 5 rows in the lookup table with orig_exp_name
        # as the experiment name under col1.  There should be the experiment
        # and 4 channels.
        all_lookup_objs = BossLookup.objects.filter(experiment_name=orig_exp_name)
        self.assertEqual(5, len(all_lookup_objs))
예제 #3
0
    def put(self, request, collection, experiment):
        """
        Update a experiment using django rest framework

        Args:
            request: DRF Request object
            collection: Collection name
            experiment : Experiment name for the new experiment

        Returns:
            Experiment
        """
        try:
            # Check if the object exists
            collection_obj = Collection.objects.get(name=collection)
            experiment_obj = Experiment.objects.get(name=experiment,
                                                    collection=collection_obj)
            if request.user.has_perm("update", experiment_obj):
                serializer = ExperimentUpdateSerializer(experiment_obj,
                                                        data=request.data,
                                                        partial=True)
                if serializer.is_valid():
                    serializer.save()

                    # update the lookup key if you update the name
                    if 'name' in request.data and request.data[
                            'name'] != experiment:
                        lookup_key = str(collection_obj.pk) + '&' + str(
                            experiment_obj.pk)
                        boss_key = collection_obj.name + '&' + request.data[
                            'name']
                        LookUpKey.update_lookup_experiment(
                            lookup_key, boss_key, collection_obj.name,
                            request.data['name'])

                    # return the object back to the user
                    experiment = serializer.data['name']
                    experiment_obj = Experiment.objects.get(
                        name=experiment, collection=collection_obj)
                    serializer = ExperimentReadSerializer(experiment_obj)
                    return Response(serializer.data)
                else:
                    return BossHTTPError("{}".format(serializer.errors),
                                         ErrorCodes.INVALID_POST_ARGUMENT)
            else:
                return BossPermissionError('update', experiment)

        except Collection.DoesNotExist:
            return BossResourceNotFoundError(collection)
        except Experiment.DoesNotExist:
            return BossResourceNotFoundError(experiment)
        except BossError as err:
            return err.to_http()