예제 #1
0
파일: test_zone.py 프로젝트: tai271828/maas
 def test_updates_zone(self):
     zone = factory.make_Zone()
     new_description = factory.make_string()
     form = ZoneForm(data={"description": new_description}, instance=zone)
     form.save()
     zone = reload_object(zone)
     self.assertEqual(new_description, zone.description)
예제 #2
0
파일: test_zone.py 프로젝트: tai271828/maas
 def test_update_default_zone_description_works(self):
     zone = Zone.objects.get_default_zone()
     new_description = factory.make_string()
     form = ZoneForm(data={"description": new_description}, instance=zone)
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     zone = reload_object(zone)
     self.assertEqual(new_description, zone.description)
예제 #3
0
파일: test_zone.py 프로젝트: tai271828/maas
 def test_renames_zone(self):
     zone = factory.make_Zone()
     new_name = factory.make_name("zone")
     form = ZoneForm(data={"name": new_name}, instance=zone)
     form.save()
     zone = reload_object(zone)
     self.assertEqual(new_name, zone.name)
     self.assertEqual(zone, Zone.objects.get(name=new_name))
예제 #4
0
파일: test_zone.py 프로젝트: tai271828/maas
 def test_creates_zone(self):
     name = factory.make_name("zone")
     description = factory.make_string()
     form = ZoneForm(data={"name": name, "description": description})
     form.save()
     zone = Zone.objects.get(name=name)
     self.assertIsNotNone(zone)
     self.assertEqual(description, zone.description)
예제 #5
0
 def test_disallows_renaming_default_zone(self):
     zone = Zone.objects.get_default_zone()
     form = ZoneForm(
         data={'name': factory.make_name('zone')},
         instance=zone)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         {'name': ["This zone is the default zone, it cannot be renamed."]},
         form.errors)
예제 #6
0
    def update(self, request, name):
        """PUT request.  Update zone.

        Returns 404 if the zone is not found.
        """
        zone = get_object_or_404(Zone, name=name)
        form = ZoneForm(instance=zone, data=request.data)
        if not form.is_valid():
            raise MAASAPIValidationError(form.errors)
        return form.save()
예제 #7
0
    def create(self, request):
        """Create a new physical zone.

        :param name: Identifier-style name for the new zone.
        :type name: unicode
        :param description: Free-form description of the new zone.
        :type description: unicode
        """
        form = ZoneForm(request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
예제 #8
0
파일: test_zone.py 프로젝트: tai271828/maas
 def test_allows_renaming_default_zone(self):
     zone = Zone.objects.get_default_zone()
     form = ZoneForm(data={"name": factory.make_name("zone")},
                     instance=zone)
     self.assertTrue(form.is_valid())