Exemplo n.º 1
0
 def test_list_displays_only_visible_nodes(self):
     node = factory.make_node(owner=factory.make_user())
     factory.make_node_commission_result(node)
     url = reverse('commissioning_results_handler')
     response = self.client.get(url, {'op': 'list'})
     self.assertEqual(httplib.OK, response.status_code, response.content)
     parsed_results = json.loads(response.content)
     self.assertEqual([], parsed_results)
Exemplo n.º 2
0
    def test_can_store_data(self):
        node = factory.make_node()
        name = factory.getRandomString()
        data = factory.getRandomBytes()
        factory.make_node_commission_result(node=node, name=name, data=data)

        ncr = NodeCommissionResult.objects.get(name=name)
        self.assertAttributes(ncr, dict(node=node, data=data))
 def test_node_name_uniqueness(self):
     # You cannot have two result rows with the same name for the
     # same node.
     node = factory.make_node()
     factory.make_node_commission_result(node=node, name="foo")
     self.assertRaises(
         ValidationError,
         factory.make_node_commission_result, node=node, name="foo")
    def test_can_store_data(self):
        node = factory.make_node()
        name = factory.getRandomString(100)
        data = factory.getRandomString(1025)
        factory.make_node_commission_result(node=node, name=name, data=data)

        ncr = NodeCommissionResult.objects.get(name=name)
        self.assertAttributes(ncr, dict(node=node, data=data))
Exemplo n.º 5
0
 def test_node_name_uniqueness(self):
     # You cannot have two result rows with the same name for the
     # same node.
     node = factory.make_node()
     factory.make_node_commission_result(node=node, name="foo")
     self.assertRaises(
         ValidationError,
         factory.make_node_commission_result, node=node, name="foo")
Exemplo n.º 6
0
 def test_ignores_tags_with_unrecognised_namespaces(self):
     node = factory.make_node()
     factory.make_node_commission_result(
         node, commissioningscript.LSHW_OUTPUT_NAME, 0, b"<foo/>")
     tags = [
         factory.make_tag("foo", "/foo"),
         factory.make_tag("lou", "//nge:bar"),
         ]
     populate_tags_for_single_node(tags, node)  # Look mom, no exception!
     self.assertSequenceEqual(
         ["foo"], [tag.name for tag in node.tags.all()])
    def test_clear_results_ignores_other_nodes(self):
        # clear_results should only remove results for the supplied
        # node.
        node1 = factory.make_node()
        factory.make_node_commission_result(node=node1)
        node2 = factory.make_node()
        factory.make_node_commission_result(node=node2)

        NodeCommissionResult.objects.clear_results(node1)
        self.assertTrue(
            NodeCommissionResult.objects.filter(node=node2).exists())
Exemplo n.º 8
0
    def test_clear_results_ignores_other_nodes(self):
        # clear_results should only remove results for the supplied
        # node.
        node1 = factory.make_node()
        factory.make_node_commission_result(node=node1)
        node2 = factory.make_node()
        factory.make_node_commission_result(node=node2)

        NodeCommissionResult.objects.clear_results(node1)
        self.assertTrue(
            NodeCommissionResult.objects.filter(node=node2).exists())
Exemplo n.º 9
0
 def test_ignores_tags_without_definition(self):
     node = factory.make_node()
     factory.make_node_commission_result(
         node, commissioningscript.LSHW_OUTPUT_NAME, 0, b"<foo/>")
     tags = [
         factory.make_tag("foo", "/foo"),
         Tag(name="empty", definition=""),
         Tag(name="null", definition=None),
         ]
     populate_tags_for_single_node(tags, node)  # Look mom, no exception!
     self.assertSequenceEqual(
         ["foo"], [tag.name for tag in node.tags.all()])
Exemplo n.º 10
0
    def test_store_data_updates_existing(self):
        node = factory.make_node()
        name = factory.getRandomString(255)
        script_result = randint(0, 10)
        factory.make_node_commission_result(node=node, name=name)
        data = factory.getRandomString(1024 * 1024)
        NodeCommissionResult.objects.store_data(
            node, name=name, script_result=script_result, data=data)

        self.assertAttributes(
            get_one(NodeCommissionResult.objects.filter(node=node)),
            dict(name=name, data=data))
Exemplo n.º 11
0
    def test_store_data_updates_existing(self):
        node = factory.make_node()
        name = factory.getRandomString(255)
        script_result = randint(0, 10)
        factory.make_node_commission_result(node=node, name=name)
        data = factory.getRandomBytes(1024 * 1024)
        NodeCommissionResult.objects.store_data(
            node, name=name, script_result=script_result, data=Bin(data))

        self.assertAttributes(
            NodeCommissionResult.objects.get(node=node),
            dict(name=name, data=data))
Exemplo n.º 12
0
 def test_updates_node_with_all_applicable_tags(self):
     node = factory.make_node()
     factory.make_node_commission_result(
         node, commissioningscript.LSHW_OUTPUT_NAME, 0, b"<foo/>")
     factory.make_node_commission_result(
         node, commissioningscript.LLDP_OUTPUT_NAME, 0, b"<bar/>")
     tags = [
         factory.make_tag("foo", "/foo"),
         factory.make_tag("bar", "//lldp:bar"),
         factory.make_tag("baz", "/foo/bar"),
         ]
     populate_tags_for_single_node(tags, node)
     self.assertItemsEqual(
         ["foo", "bar"], [tag.name for tag in node.tags.all()])
Exemplo n.º 13
0
 def test_list_can_be_filtered_by_name(self):
     commissioning_results = [
         factory.make_node_commission_result() for counter in range(3)
     ]
     url = reverse('commissioning_results_handler')
     response = self.client.get(url, {
         'op': 'list',
         'name': commissioning_results[0].name
     })
     self.assertEqual(httplib.OK, response.status_code, response.content)
     parsed_results = json.loads(response.content)
     self.assertItemsEqual(
         [b64encode(commissioning_results[0].data)],
         [result.get('data') for result in parsed_results])
Exemplo n.º 14
0
    def test_clear_results_removes_rows(self):
        # clear_results should remove all a node's results.
        node = factory.make_node()
        factory.make_node_commission_result(node=node)
        factory.make_node_commission_result(node=node)
        factory.make_node_commission_result(node=node)

        NodeCommissionResult.objects.clear_results(node)
        self.assertItemsEqual(
            [],
            NodeCommissionResult.objects.filter(node=node))
Exemplo n.º 15
0
    def test_clear_results_removes_rows(self):
        # clear_results should remove all a node's results.
        node = factory.make_node()
        factory.make_node_commission_result(node=node)
        factory.make_node_commission_result(node=node)
        factory.make_node_commission_result(node=node)

        NodeCommissionResult.objects.clear_results(node)
        self.assertItemsEqual(
            [],
            NodeCommissionResult.objects.filter(node=node))
Exemplo n.º 16
0
 def test_list_returns_commissioning_results(self):
     commissioning_results = [
         factory.make_node_commission_result() for counter in range(3)
     ]
     url = reverse('commissioning_results_handler')
     response = self.client.get(url, {'op': 'list'})
     self.assertEqual(httplib.OK, response.status_code, response.content)
     parsed_results = json.loads(response.content)
     self.assertItemsEqual([(
         commissioning_result.name,
         commissioning_result.script_result,
         b64encode(commissioning_result.data),
         commissioning_result.node.system_id,
     ) for commissioning_result in commissioning_results], [(
         result.get('name'),
         result.get('script_result'),
         result.get('data'),
         result.get('node').get('system_id'),
     ) for result in parsed_results])
Exemplo n.º 17
0
 def make_lshw_result(self, node, script_result=0):
     return factory.make_node_commission_result(
         node=node, name=commissioningscript.LSHW_OUTPUT_NAME,
         script_result=script_result)
Exemplo n.º 18
0
 def test_different_nodes_can_have_same_data_name(self):
     node = factory.make_node()
     ncr1 = factory.make_node_commission_result(node=node, name="foo")
     node2 = factory.make_node()
     ncr2 = factory.make_node_commission_result(node=node2, name="foo")
     self.assertEqual(ncr1.name, ncr2.name)
Exemplo n.º 19
0
def make_lldp_result(node, data, script_result=0):
    return factory.make_node_commission_result(
        node=node, name=commissioningscript.LLDP_OUTPUT_NAME,
        data=data, script_result=script_result)
Exemplo n.º 20
0
 def test_get_data(self):
     ncr = factory.make_node_commission_result()
     result = NodeCommissionResult.objects.get_data(ncr.node, ncr.name)
     self.assertEqual(ncr.data, result)
Exemplo n.º 21
0
 def test_get_data_404s_when_not_found(self):
     ncr = factory.make_node_commission_result()
     self.assertRaises(
         Http404,
         NodeCommissionResult.objects.get_data, ncr.node, "bad name")
Exemplo n.º 22
0
 def test_get_data(self):
     ncr = factory.make_node_commission_result()
     result = NodeCommissionResult.objects.get_data(ncr.node, ncr.name)
     self.assertEqual(ncr.data, result)
Exemplo n.º 23
0
 def test_get_data_404s_when_not_found(self):
     ncr = factory.make_node_commission_result()
     self.assertRaises(
         Http404,
         NodeCommissionResult.objects.get_data, ncr.node, "bad name")
Exemplo n.º 24
0
def make_lldp_result(node, data, script_result=0):
    return factory.make_node_commission_result(
        node=node,
        name=commissioningscript.LLDP_OUTPUT_NAME,
        data=data,
        script_result=script_result)
Exemplo n.º 25
0
 def test_different_nodes_can_have_same_data_name(self):
     node = factory.make_node()
     ncr1 = factory.make_node_commission_result(node=node, name="foo")
     node2 = factory.make_node()
     ncr2 = factory.make_node_commission_result(node=node2, name="foo")
     self.assertEqual(ncr1.name, ncr2.name)