예제 #1
0
 def test_get(self):
     user = factory.make_User()
     handler = IPRangeHandler(user, {}, None)
     subnet = factory.make_ipv4_Subnet_with_IPRanges()
     iprange = subnet.iprange_set.first()
     self.assertEqual(self.dehydrate_iprange(iprange),
                      handler.get({"id": iprange.id}))
예제 #2
0
 def test_list(self):
     user = factory.make_User()
     handler = IPRangeHandler(user, {}, None)
     factory.make_ipv4_Subnet_with_IPRanges()
     expected_ipranges = [
         self.dehydrate_iprange(iprange, for_list=True)
         for iprange in IPRange.objects.all()
     ]
     self.assertItemsEqual(expected_ipranges, handler.list({}))
예제 #3
0
 def test_delete(self):
     user = factory.make_User()
     factory.make_Subnet(cidr="192.168.0.0/24")
     handler = IPRangeHandler(user, {}, None)
     ip_range = handler.create({
         "type": "reserved",
         "start_ip": "192.168.0.10",
         "end_ip": "192.168.0.20",
     })
     handler.delete(ip_range)
     self.assertIsNone(get_one(IPRange.objects.filter(id=ip_range["id"])))
예제 #4
0
 def test_create(self):
     user = factory.make_User()
     factory.make_Subnet(cidr="192.168.0.0/24")
     handler = IPRangeHandler(user, {})
     ip_range = handler.create({
         "type": "reserved",
         "start_ip": "192.168.0.10",
         "end_ip": "192.168.0.20",
     })
     self.assertThat(
         IPRange.objects.get(id=ip_range['id']),
         MatchesStructure.byEquality(
             type="reserved", start_ip="192.168.0.10",
             end_ip="192.168.0.20"))