Exemple #1
0
 def test_delete_as_admin_success(self):
     user = factory.make_admin()
     handler = SpaceHandler(user, {}, None)
     space = factory.make_Space()
     handler.delete({"id": space.id})
     space = reload_object(space)
     self.assertThat(space, Equals(None))
Exemple #2
0
 def test_reloads_user(self):
     user = factory.make_admin()
     handler = SpaceHandler(user, {}, None)
     space = factory.make_Space()
     user.is_superuser = False
     user.save()
     with ExpectedException(AssertionError, "Permission denied."):
         handler.delete({"id": space.id})
Exemple #3
0
 def test_list(self):
     user = factory.make_User()
     handler = SpaceHandler(user, {}, None)
     factory.make_Space()
     expected_spaces = [
         self.dehydrate_space(space) for space in Space.objects.all()
     ]
     self.assertItemsEqual(expected_spaces, handler.list({}))
Exemple #4
0
 def test__delete_as_non_admin_asserts(self):
     user = factory.make_User()
     handler = SpaceHandler(user, {}, None)
     space = factory.make_Space()
     with ExpectedException(AssertionError, "Permission denied."):
         handler.delete({
             "id": space.id,
         })
Exemple #5
0
 def test_get(self):
     user = factory.make_User()
     handler = SpaceHandler(user, {}, None)
     space = factory.make_Space()
     for _ in range(3):
         node = factory.make_Node(interface=True)
         interface = node.get_boot_interface()
         subnet = factory.make_Subnet(space=space, vlan=interface.vlan)
         factory.make_StaticIPAddress(subnet=subnet, interface=interface)
     self.assertEqual(self.dehydrate_space(space),
                      handler.get({"id": space.id}))
Exemple #6
0
    def test_list_constant_queries(self):
        user = factory.make_User()
        handler = SpaceHandler(user, {}, None)
        for _ in range(10):
            space = factory.make_Space()
            node = factory.make_Node(interface=True)
            interface = node.get_boot_interface()
            subnet = factory.make_Subnet(space=space, vlan=interface.vlan)
            factory.make_StaticIPAddress(subnet=subnet, interface=interface)
        queries_one, _ = count_queries(handler.list, {"limit": 1})
        queries_multiple, _ = count_queries(handler.list, {})

        self.assertEqual(queries_one, queries_multiple)