Example #1
0
    def test_oai_provider_set_upsert_raises_error_if_save_failed(
            self, mock_save):
        # Arrange
        mock_save.side_effect = Exception()

        # Act # Assert
        with self.assertRaises(Exception):
            provider_set_api.upsert(self.mock_oai_provider_set)
Example #2
0
 def _save(self, form):
     # Save treatment.
     try:
         self.object.templates_manager = [
             x.id for x in self.object.templates_manager
         ]
         oai_provider_set_api.upsert(self.object)
     except Exception as e:
         form.add_error(None, str(e))
Example #3
0
    def test_oai_provider_set_upsert_return_object(self, mock_save):
        # Arrange
        mock_save.return_value = self.mock_oai_provider_set

        # Act
        result = provider_set_api.upsert(self.mock_oai_provider_set)

        # Assert
        self.assertIsInstance(result, OaiProviderSet)
Example #4
0
 def update(self, instance, validated_data):
     instance.set_spec = validated_data.get('set_spec', instance.set_spec)
     instance.set_name = validated_data.get('set_name', instance.set_name)
     templates_manager = validated_data.get('templates_manager', [])
     if len(templates_manager) > 0:
         templates_manager = [
             version_manager_api.get(id_) for id_ in templates_manager
         ]
         instance.templates_manager = templates_manager
     instance.description = validated_data.get('description',
                                               instance.description)
     return oai_provider_set_api.upsert(instance)
 def update(self, instance, validated_data):
     instance.set_spec = validated_data.get("set_spec", instance.set_spec)
     instance.set_name = validated_data.get("set_name", instance.set_name)
     templates_manager = validated_data.get("templates_manager", [])
     if len(templates_manager) > 0:
         templates_manager = [
             version_manager_api.get(id_, request=self.context["request"])
             for id_ in templates_manager
         ]
         instance.templates_manager = templates_manager
     instance.description = validated_data.get("description",
                                               instance.description)
     return oai_provider_set_api.upsert(instance)
Example #6
0
 def create(self, validated_data):
     return oai_provider_set_api.upsert(OaiProviderSet(**validated_data))