Пример #1
0
    def test_nodegroup_list_nodes_works_for_admin(self):
        nodegroup = factory.make_node_group()
        admin = factory.make_admin()
        client = OAuthAuthenticatedClient(admin)
        node = factory.make_node(nodegroup=nodegroup)

        response = client.get(
            reverse('nodegroup_handler', args=[nodegroup.uuid]),
            {'op': 'list_nodes'})

        self.assertEqual(httplib.OK, response.status_code,
                         explain_unexpected_response(httplib.OK, response))
        parsed_result = json.loads(response.content)
        self.assertItemsEqual([node.system_id], parsed_result)
Пример #2
0
    def test_nodegroup_list_nodes_works_for_admin(self):
        nodegroup = factory.make_node_group()
        admin = factory.make_admin()
        client = OAuthAuthenticatedClient(admin)
        node = factory.make_node(nodegroup=nodegroup)

        response = client.get(
            reverse('nodegroup_handler', args=[nodegroup.uuid]),
            {'op': 'list_nodes'})

        self.assertEqual(
            httplib.OK, response.status_code,
            explain_unexpected_response(httplib.OK, response))
        parsed_result = json.loads(response.content)
        self.assertItemsEqual([node.system_id], parsed_result)
Пример #3
0
    def test_GET_nodes_hides_invisible_nodes(self):
        user2 = factory.make_user()
        node1 = factory.make_node()
        inject_lshw_result(node1, b'<node><foo/></node>')
        node2 = factory.make_node(status=NODE_STATUS.ALLOCATED, owner=user2)
        inject_lshw_result(node2, b'<node><bar/></node>')
        tag = factory.make_tag(definition='//node')
        response = self.client.get(self.get_tag_uri(tag), {'op': 'nodes'})

        self.assertEqual(httplib.OK, response.status_code)
        parsed_result = json.loads(response.content)
        self.assertEqual([node1.system_id],
                         [r['system_id'] for r in parsed_result])
        # However, for the other user, they should see the result
        client2 = OAuthAuthenticatedClient(user2)
        response = client2.get(self.get_tag_uri(tag), {'op': 'nodes'})
        self.assertEqual(httplib.OK, response.status_code)
        parsed_result = json.loads(response.content)
        self.assertItemsEqual([node1.system_id, node2.system_id],
                              [r['system_id'] for r in parsed_result])
Пример #4
0
    def test_GET_nodes_hides_invisible_nodes(self):
        user2 = factory.make_user()
        node1 = factory.make_node()
        inject_lshw_result(node1, b'<node><foo/></node>')
        node2 = factory.make_node(status=NODE_STATUS.ALLOCATED, owner=user2)
        inject_lshw_result(node2, b'<node><bar/></node>')
        tag = factory.make_tag(definition='//node')
        response = self.client.get(self.get_tag_uri(tag), {'op': 'nodes'})

        self.assertEqual(httplib.OK, response.status_code)
        parsed_result = json.loads(response.content)
        self.assertEqual([node1.system_id],
                         [r['system_id'] for r in parsed_result])
        # However, for the other user, they should see the result
        client2 = OAuthAuthenticatedClient(user2)
        response = client2.get(self.get_tag_uri(tag), {'op': 'nodes'})
        self.assertEqual(httplib.OK, response.status_code)
        parsed_result = json.loads(response.content)
        self.assertItemsEqual([node1.system_id, node2.system_id],
                              [r['system_id'] for r in parsed_result])
Пример #5
0
 def test_node_init_user_cannot_access(self):
     token = NodeKey.objects.get_token_for_node(factory.make_node())
     client = OAuthAuthenticatedClient(get_node_init_user(), token)
     response = client.get(reverse('nodes_handler'), {'op': 'list'})
     self.assertEqual(httplib.FORBIDDEN, response.status_code)