Esempio n. 1
0
    def _init_validation(self, obj: NodeObject, mock_server: Server,
                         mock_parent: NodeObject, name: str):
        """
        Default init validation that can be reused in overrides of test_init
        """
        # ... The object must be of the type that was provided
        test_case = unittest.TestCase('__init__')
        test_case.assertIsInstance(obj, NodeObject)
        test_case.assertIsInstance(obj, self.class_for_test)

        # ... The NodeObject basic properties should be set up appropriately
        utils.assert_threeway_equals(mock_server, obj._server, obj.server)
        utils.assert_threeway_equals(None, obj._oid, obj.oid)
        utils.assert_threeway_equals(name, obj._name, obj.name)
        utils.assert_threeway_equals(mock_parent, obj._parent, obj.parent)

        # ... The rest of the properties should be none
        for prop in self.basic_properties.keys():
            test_case.assertIsNone(getattr(obj, prop))

        # ... The full properties collection should be a lazy property collection
        test_case.assertIsInstance(obj._full_properties,
                                   NodeLazyPropertyCollection)

        # ... The child node collections should be assigned to node collections
        for coll in self.collections:
            test_case.assertIsInstance(getattr(obj, coll), NodeCollection)
Esempio n. 2
0
    def test_from_node_query(self):
        # If: I create a new object from a node row with the expected parent type
        mock_server = Server(utils.MockConnection(None))
        mock_parent = utils.MockNodeObject(
            mock_server, None,
            'parent') if not self.parent_expected_to_be_none else None

        obj = self.class_for_test._from_node_query(mock_server, mock_parent,
                                                   **self.node_query)

        # Then:
        # ... The returned object must be an instance of the class
        NodeObjectTestBase.unittest.assertIsInstance(obj, NodeObject)
        NodeObjectTestBase.unittest.assertIsInstance(obj, self.class_for_test)

        # ... Validate the node object properties
        utils.assert_threeway_equals(mock_server, obj._server, obj.server)
        utils.assert_threeway_equals(self.node_query['oid'], obj._oid, obj.oid)
        utils.assert_threeway_equals(self.node_query['name'], obj._name,
                                     obj.name)

        # ... Validate the basic properties
        for attr, value in self.basic_properties.items():
            NodeObjectTestBase.unittest.assertEqual(getattr(obj, attr), value)

        # ... Validate the collections
        for attr in self.collections:
            NodeObjectTestBase.unittest.assertIsInstance(
                getattr(obj, attr), NodeCollection)

        # ... Call the validation function
        self._custom_validate_from_node(obj, mock_server)
Esempio n. 3
0
    def test_init(self):
        # If: I create a node object
        server = Server(utils.MockConnection(None))
        parent = utils.MockNodeObject(server, None, 'parent')
        node_obj = utils.MockNodeObject(server, parent, 'abc')

        # Then: The properties should be assigned as defined
        utils.assert_threeway_equals(None, node_obj._oid, node_obj.oid)
        utils.assert_threeway_equals('abc', node_obj._name, node_obj.name)
        utils.assert_threeway_equals(server, node_obj._server, node_obj.server)
        utils.assert_threeway_equals(parent, node_obj._parent, node_obj.parent)

        self.assertDictEqual(node_obj._child_collections, {})
        self.assertEqual(len(node_obj._property_collections), 1)

        self.assertIsInstance(node_obj._full_properties,
                              node.NodeLazyPropertyCollection)
        self.assertEqual(node_obj._full_properties._generator,
                         node_obj._property_generator)
Esempio n. 4
0
 def _custom_validate_init(obj, mock_server: Server):
     # Make sure that the datatype value is set
     utils.assert_threeway_equals('character', obj._datatype, obj.datatype)