Пример #1
0
    def test_get_obj_by_urn_wrong_server(self):
        # Setup: Create a server object
        server = Server(utils.MockConnection(None))

        with self.assertRaises(ValueError):
            # If: I get an object by its URN with a URN that is invalid for the server
            # Then: I should get an exception
            invalid_urn = '//[email protected]:456/Database.123/'
            server.get_object_by_urn(invalid_urn)
Пример #2
0
    def test_get_obj_by_urn_wrong_collection(self):
        # Setup: Create a server object
        server = Server(utils.MockConnection(None))

        with self.assertRaises(ValueError):
            # If: I get an object by its URN with a URN that points to an invalid path off the server
            # Then: I should get an exception
            invalid_urn = parse.urljoin(server.urn_base, 'Datatype.123/')
            server.get_object_by_urn(invalid_urn)
Пример #3
0
    def test_get_obj_by_urn_empty(self):
        # Setup: Create a server object
        server = Server(utils.MockConnection(None))

        test_cases = [None, '', '\t \n\r']
        for test_case in test_cases:
            with self.assertRaises(ValueError):
                # If: I get an object by its URN without providing a URN
                # Then: I should get an exception
                server.get_object_by_urn(test_case)
Пример #4
0
    def test_get_obj_by_urn_success(self):
        # Setup: Create a server with a database under it
        server = Server(utils.MockConnection(None))
        mock_db = Database(server, 'test_db')
        mock_db._oid = 123
        server._child_objects[Database.__name__] = {123: mock_db}

        # If: I get an object by its URN
        urn = parse.urljoin(server.urn_base, '/Database.123/')
        obj = server.get_object_by_urn(urn)

        # Then: The object I get back should be the same as the object I provided
        self.assertIs(obj, mock_db)