예제 #1
0
 def test_edits_boot_source_selection_object(self):
     boot_source_selection = factory.make_BootSourceSelection()
     boot_source = boot_source_selection.boot_source
     params = self.make_valid_source_selection_params(boot_source)
     form = BootSourceSelectionForm(instance=boot_source_selection,
                                    data=params)
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     boot_source_selection = reload_object(boot_source_selection)
     self.assertAttributes(boot_source_selection, params)
예제 #2
0
    def test_cannot_create_duplicate_entry(self):
        boot_source = factory.make_BootSource()
        params = self.make_valid_source_selection_params(boot_source)
        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertTrue(form.is_valid(), form._errors)
        form.save()

        # Duplicates should be detected for the same boot_source, os and
        # release, the other fields are irrelevant.
        dup_params = {"os": params["os"], "release": params["release"]}
        form = BootSourceSelectionForm(boot_source=boot_source,
                                       data=dup_params)
        self.assertRaises(ValidationError, form.save)
예제 #3
0
 def test_creates_boot_source_selection_object(self):
     boot_source = factory.make_BootSource()
     params = self.make_valid_source_selection_params(boot_source)
     form = BootSourceSelectionForm(boot_source=boot_source, data=params)
     self.assertTrue(form.is_valid(), form._errors)
     boot_source_selection = form.save()
     self.assertAttributes(boot_source_selection, params)
예제 #4
0
    def create(self, request, boot_source_id):
        """Create a new boot source selection.

        :param os: The OS (e.g. ubuntu, centos) for which to import resources.
        :param release: The release for which to import resources.
        :param arches: The architecture list for which to import resources.
        :param subarches: The subarchitecture list for which to import
            resources.
        :param labels: The label lists for which to import resources.
        """
        boot_source = get_object_or_404(BootSource, id=boot_source_id)
        form = BootSourceSelectionForm(data=request.data,
                                       boot_source=boot_source)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
예제 #5
0
    def update(self, request, boot_source_id, id):
        """@description-title Update a boot-source selection
        @description Update a boot source selection with the given id.

        @param (string) "{boot_source_id}" [required=true] A boot-source id.
        @param (string) "{id}" [required=true] A boot-source selection id.

        @param (string) "os" [required=false] The OS (e.g. ubuntu, centos) for
        which to import resources.

        @param (string) "release" [required=false] The release for which to
        import resources.

        @param (string) "arches" [required=false] The list of architectures for
        which to import resources.

        @param (string) "subarches" [required=false] The list of
        sub-architectures for which to import resources.

        @param (string) "labels" [required=false] The list of labels for which
        to import resources.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the requested
        boot-source selection object.
        @success-example "success-json" [exkey=boot-source-sel-update]
        placeholder text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested boot-source or boot-source
        selection is not found.
        @error-example "not-found"
            Not Found
        """
        boot_source = get_object_or_404(BootSource, id=boot_source_id)
        boot_source_selection = get_object_or_404(
            BootSourceSelection, boot_source=boot_source, id=id
        )
        form = BootSourceSelectionForm(
            data=request.data, instance=boot_source_selection
        )
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
예제 #6
0
    def update(self, request, boot_source_id, id):
        """Update a specific boot source selection.

        :param os: The OS (e.g. ubuntu, centos) for which to import resources.
        :param release: The release for which to import resources.
        :param arches: The list of architectures for which to import resources.
        :param subarches: The list of subarchitectures for which to import
            resources.
        :param labels: The list of labels for which to import resources.
        """
        boot_source = get_object_or_404(BootSource, id=boot_source_id)
        boot_source_selection = get_object_or_404(BootSourceSelection,
                                                  boot_source=boot_source,
                                                  id=id)
        form = BootSourceSelectionForm(data=request.data,
                                       instance=boot_source_selection)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)