Ejemplo n.º 1
0
Archivo: REST.py Proyecto: nakos/im
    def test_CreateInfrastructure(self, bottle_request, CreateInfrastructure):
        """Test REST CreateInfrastructure."""
        bottle_request.environ = {'HTTP_HOST': 'imserver.com'}
        bottle_request.return_value = MagicMock()
        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass")
        }
        bottle_request.body.read.return_value = "radl"

        CreateInfrastructure.return_value = "1"

        res = RESTCreateInfrastructure()
        self.assertEqual(res, "http://imserver.com/infrastructures/1")

        res = RESTCreateInfrastructure()
        self.assertEqual(res, "http://imserver.com/infrastructures/1")

        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass"),
            "Content-Type":
            "application/json"
        }
        bottle_request.body.read.return_value = read_file_as_string(
            "../files/test_simple.json")

        CreateInfrastructure.return_value = "1"
Ejemplo n.º 2
0
    def test_CreateInfrastructureWithErrors(self, bottle_request,
                                            CreateInfrastructure):
        """Test REST CreateInfrastructure."""
        bottle_request.environ = {'HTTP_HOST': 'imserver.com'}
        bottle_request.return_value = MagicMock()
        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass"),
            "Content-Type":
            "application/pdf",
            "Accept":
            "application/json"
        }
        bottle_request.body = BytesIO(b"radl")

        CreateInfrastructure.return_value = "1"

        res = RESTCreateInfrastructure()
        res_json = json.loads(res)
        self.assertEqual(res_json['code'], 415)
Ejemplo n.º 3
0
    def test_CreateInfrastructure(self, bottle_request, get_infrastructure,
                                  CreateInfrastructure):
        """Test REST CreateInfrastructure."""
        bottle_request.environ = {'HTTP_HOST': 'imserver.com'}
        bottle_request.return_value = MagicMock()
        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass")
        }
        bottle_request.body = BytesIO(b"radl")

        CreateInfrastructure.return_value = "1"

        res = RESTCreateInfrastructure()
        self.assertEqual(res, "http://imserver.com/infrastructures/1")

        bottle_request.params = {"async": "yes"}
        res = RESTCreateInfrastructure()
        self.assertEqual(res, "http://imserver.com/infrastructures/1")

        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass"),
            "Content-Type":
            "application/json"
        }
        bottle_request.body = read_file_as_bytes("../files/test_simple.json")

        CreateInfrastructure.return_value = "1"

        res = RESTCreateInfrastructure()
        self.assertEqual(res, "http://imserver.com/infrastructures/1")

        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass"),
            "Content-Type":
            "text/yaml"
        }
        bottle_request.body = read_file_as_bytes("../files/tosca_create.yml")

        CreateInfrastructure.return_value = "1"

        res = RESTCreateInfrastructure()
        self.assertEqual(res, "http://imserver.com/infrastructures/1")

        bottle_request.body = read_file_as_bytes("../files/tosca_create.yml")
        CreateInfrastructure.side_effect = InvaliddUserException()
        res = RESTCreateInfrastructure()
        self.assertEqual(
            res,
            "Error Getting Inf. info: Invalid InfrastructureManager credentials"
        )

        bottle_request.body = read_file_as_bytes("../files/tosca_create.yml")
        CreateInfrastructure.side_effect = UnauthorizedUserException()
        res = RESTCreateInfrastructure()
        self.assertEqual(
            res,
            "Error Creating Inf.: Access to this infrastructure not granted.")