def test_Contains_limited_set_of_fields(self): form = ControllerForm() self.assertItemsEqual([ 'zone', 'domain', 'power_type', 'power_parameters', ], list(form.fields))
def update(self, request, system_id): """@description-title Update a region controller @description Updates a region controller with the given system_id. @param (string) "{system_id}" [required=true] The region controller's system_id. @param (string) "description" [required=false] The new description for this given region controller. @param (string) "power_type" [required=false] The new power type for this region controller. If you use the default value, power_parameters will be set to the empty string. Available to admin users. See the `Power types`_ section for a list of the available power types. @param (string) "power_parameters_{param1}" [required=true] The new value for the 'param1' power parameter. Note that this is dynamic as the available parameters depend on the selected value of the region controller's power_type. Available to admin users. See the `Power types`_ section for a list of the available power parameters for each power type. @param (boolean) "power_parameters_skip_check" [required=false] Whether or not the new power parameters for this region controller should be checked against the expected power parameters for the region controller's power type ('true' or 'false'). The default is 'false'. @param (string) "zone" [required=false] Name of a valid physical zone in which to place this region controller. @success (http-status-code) "200" 200 @success (json) "success-json" A JSON object containing the updated region controller object. @success-example (json) "success-json" [exkey=update] placeholder text @error (http-status-code) "404" 404 @error (content) "not-found" The requested region controller system_id is not found. @error-example "not-found" Not Found @error (http-status-code) "403" 403 @error (content) "no-perms" The user does not have permission to update the region controller. @error-example "no-perms" This method is reserved for admin users. """ region = self.model.objects.get_node_or_404(system_id=system_id, user=request.user, perm=NodePermission.admin) form = ControllerForm(data=request.data, instance=region) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def test__sets_domain(self): rack = factory.make_RackController() domain = factory.make_Domain() form = ControllerForm(data={ 'domain': domain.name, 'power_parameters_skip_check': 'true', }, instance=rack) rack = form.save() self.assertEqual(domain.name, rack.domain.name)
def test__sets_zone(self): rack = factory.make_RackController() zone = factory.make_zone() form = ControllerForm(data={ 'zone': zone.name, 'power_parameters_skip_check': 'true', }, instance=rack) rack = form.save() self.assertEqual(zone.name, rack.zone.name)
def test__sets_power_type(self): rack = factory.make_RackController() power_type = factory.pick_power_type() form = ControllerForm(data={ 'power_type': power_type, 'power_parameters_skip_check': 'true', }, instance=rack) rack = form.save() self.assertEqual(power_type, rack.power_type)
def test__sets_power_parameters(self): rack = factory.make_RackController() power_parameters_field = factory.make_string() form = ControllerForm(data={ 'power_parameters_field': power_parameters_field, 'power_parameters_skip_check': 'true', }, instance=rack) rack = form.save() self.assertEqual(power_parameters_field, rack.power_parameters['field'])
def test_sets_domain(self): rack = factory.make_RackController() domain = factory.make_Domain() form = ControllerForm( data={ "domain": domain.name, "power_parameters_skip_check": "true", }, instance=rack, ) rack = form.save() self.assertEqual(domain.name, rack.domain.name)
def test_sets_zone(self): rack = factory.make_RackController() zone = factory.make_zone() form = ControllerForm( data={ "zone": zone.name, "power_parameters_skip_check": "true" }, instance=rack, ) rack = form.save() self.assertEqual(zone.name, rack.zone.name)
def test_sets_power_type(self): rack = factory.make_RackController() power_type = factory.pick_power_type() form = ControllerForm( data={ "power_type": power_type, "power_parameters_skip_check": "true", }, instance=rack, ) rack = form.save() self.assertEqual(power_type, rack.power_type)
def update(self, request, system_id): """@description-title Update a rack controller @description Updates a rack controller with the given system_id. @param (string) "description" [required=false] The new description for this given rack controller. @param (string) "power_type" [required=false] The new power type for the given rack controller. If you use the default value, power_parameters will be set to an empty string. See the `Power types`_ section for a list of available power types. Note that only admin users can set this parameter. @param (string) "power_parameters_{param}" [required=true] The new value for the 'param' power parameter. This is a dynamic parameter that depends on the rack controller's power_type. See the `Power types`_ section for a list of available parameters based on power type. Note that only admin users can set these parameters. @param (boolean) "power_parameters_skip_check" [required=false] If true, the new power parameters for the given rack controller will be checked against the expected parameters for the rack controller's power type. Default is false. @param (string) "zone" [required=false] The name of a valid zone in which to place the given rack controller. @param (string) "domain" [required=false] The domain for this controller. If not given the default domain is used. @success (http-status-code) "200" 200 @success (content) "success-json" A JSON object containing the updated rack-controller object. @success-example "success-json" [exkey=update] placeholder @error (http-status-code) "404" 404 @error (content) "not-found" The requested rack controller system_id is not found. @error-example "not-found" Not Found @error (http-status-code) "403" 403 @error (content) "no-perms" This method is reserved for admin users. """ rack = self.model.objects.get_node_or_404(system_id=system_id, user=request.user, perm=NodePermission.admin) form = ControllerForm(data=request.data, instance=rack) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def test_sets_power_parameters(self): rack = factory.make_RackController() power_parameters_field = factory.make_string() form = ControllerForm( data={ "power_parameters_field": power_parameters_field, "power_parameters_skip_check": "true", }, instance=rack, ) rack = form.save() self.assertEqual(power_parameters_field, rack.power_parameters["field"])
def test_Contains_limited_set_of_fields(self): form = ControllerForm() self.assertItemsEqual( [ "description", "zone", "domain", "power_type", "power_parameters", ], list(form.fields), )
def update(self, request, system_id): """Update a specific Region controller. :param power_type: The new power type for this region controller. If you use the default value, power_parameters will be set to the empty string. Available to admin users. See the `Power types`_ section for a list of the available power types. :type power_type: unicode :param power_parameters_{param1}: The new value for the 'param1' power parameter. Note that this is dynamic as the available parameters depend on the selected value of the region controller's power_type. Available to admin users. See the `Power types`_ section for a list of the available power parameters for each power type. :type power_parameters_{param1}: unicode :param power_parameters_skip_check: Whether or not the new power parameters for this region controller should be checked against the expected power parameters for the region controller's power type ('true' or 'false'). The default is 'false'. :type power_parameters_skip_check: unicode :param zone: Name of a valid physical zone in which to place this region controller. :type zone: unicode Returns 404 if the region controller is not found. Returns 403 if the user does not have permission to update the region controller. """ region = self.model.objects.get_node_or_404(system_id=system_id, user=request.user, perm=NODE_PERMISSION.EDIT) form = ControllerForm(data=request.data, instance=region) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def test_populates_power_type_initial(self): rack = factory.make_RackController() form = ControllerForm(instance=rack) self.assertEqual(rack.power_type, form.fields["power_type"].initial)
def test_populates_power_type_choices(self): form = ControllerForm() self.assertEqual( [""] + [choice[0] for choice in get_driver_choices()], [choice[0] for choice in form.fields["power_type"].choices], )