Beispiel #1
0
    def update(self, request, id):
        """@description-title Update fabric
        @description Update a fabric with the given id.

        @param (int) "{id}" [required=true] A fabric id.

        @param (string) "name" [required=false] Name of the fabric.

        @param (string) "description" [required=false] Description of the
        fabric.

        @param (string) "class_type" [required=false] Class type of the fabric.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the updated
        fabric object.
        @success-example "success-json" [exkey=fabrics-update] placeholder
        text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested fabric is not found.
        @error-example "not-found"
            Not Found
        """
        fabric = Fabric.objects.get_fabric_or_404(id, request.user,
                                                  NodePermission.admin)
        form = FabricForm(instance=fabric, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
Beispiel #2
0
    def create(self, request):
        """Create a fabric.

        :param name: Name of the fabric.
        :param description: Description of the fabric.
        :param class_type: Class type of the fabric.
        """
        form = FabricForm(data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
Beispiel #3
0
 def test__creates_fabric(self):
     fabric_name = factory.make_name("fabric")
     fabric_description = factory.make_name("description")
     fabric_class_type = factory.make_name("class_type")
     form = FabricForm({
         "name": fabric_name,
         "description": fabric_description,
         "class_type": fabric_class_type,
     })
     self.assertTrue(form.is_valid(), form.errors)
     fabric = form.save()
     self.assertEqual(fabric_name, fabric.name)
     self.assertEqual(fabric_description, fabric.description)
     self.assertEqual(fabric_class_type, fabric.class_type)
Beispiel #4
0
    def update(self, request, id):
        """Update fabric.

        :param name: Name of the fabric.
        :param description: Description of the fabric.
        :param class_type: Class type of the fabric.

        Returns 404 if the fabric is not found.
        """
        fabric = Fabric.objects.get_fabric_or_404(id, request.user,
                                                  NODE_PERMISSION.ADMIN)
        form = FabricForm(instance=fabric, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
Beispiel #5
0
 def test__updates_fabric(self):
     new_name = factory.make_name("fabric")
     new_fabric_description = factory.make_name("description")
     new_class_type = factory.make_name("class_type")
     fabric = factory.make_Fabric()
     form = FabricForm(instance=fabric,
                       data={
                           "name": new_name,
                           "description": new_fabric_description,
                           "class_type": new_class_type,
                       })
     self.assertTrue(form.is_valid(), form.errors)
     form.save()
     self.assertEqual(new_name, reload_object(fabric).name)
     self.assertEqual(new_fabric_description,
                      reload_object(fabric).description)
     self.assertEqual(new_class_type, reload_object(fabric).class_type)
Beispiel #6
0
    def create(self, request):
        """@description-title Create a fabric
        @description Create a fabric.

        @param (string) "name" [required=false] Name of the fabric.

        @param (string) "description" [required=false] Description of the
        fabric.

        @param (string) "class_type" [required=false] Class type of the fabric.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the new fabric
        object.
        @success-example "success-json" [exkey=fabrics-create] placeholder text
        """
        form = FabricForm(data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
Beispiel #7
0
 def test_doest_require_name_on_update(self):
     fabric = factory.make_Fabric()
     form = FabricForm(instance=fabric, data={})
     self.assertTrue(form.is_valid(), form.errors)