Ejemplo n.º 1
0
    def test_GetInfrastructureListWithErrors(self, bottle_request,
                                             GetInfrastructureList):
        """Test REST GetInfrastructureList without auth data."""
        bottle_request.environ = {'HTTP_HOST': 'imserver.com'}
        bottle_request.return_value = MagicMock()
        bottle_request.headers = {"Accept": "application/json"}

        GetInfrastructureList.return_value = ["1", "2"]
        res = RESTGetInfrastructureList()
        res_json = json.loads(res)
        self.assertEqual(res_json['code'], 401)
Ejemplo n.º 2
0
    def test_GetInfrastructureList(self, bottle_request,
                                   GetInfrastructureList):
        """Test REST GetInfrastructureList."""
        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"),
            "Accept":
            "application/json"
        }

        GetInfrastructureList.return_value = ["1", "2"]
        res = RESTGetInfrastructureList()
        self.assertEqual(
            res,
            ('{"uri-list": [{"uri": "http://imserver.com/infrastructures/1"},'
             ' {"uri": "http://imserver.com/infrastructures/2"}]}'))

        GetInfrastructureList.side_effect = InvaliddUserException()
        res = RESTGetInfrastructureList()
        res = json.loads(res)
        self.assertEqual(
            res, {
                "message":
                "Error Getting Inf. List: Invalid InfrastructureManager credentials",
                "code": 401
            })

        GetInfrastructureList.side_effect = UnauthorizedUserException()
        res = RESTGetInfrastructureList()
        res = json.loads(res)
        self.assertEqual(
            res, {
                "message":
                "Error Getting Inf. List: Access to this infrastructure not granted.",
                "code": 400
            })
Ejemplo n.º 3
0
Archivo: REST.py Proyecto: nakos/im
    def test_GetInfrastructureList(self, bottle_request,
                                   GetInfrastructureList):
        """Test REST GetInfrastructureList."""
        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"),
            "Accept":
            "application/json"
        }

        GetInfrastructureList.return_value = ["1", "2"]
        res = RESTGetInfrastructureList()
        self.assertEqual(
            res,
            ('{"uri-list": [{"uri": "http://imserver.com/infrastructures/1"},'
             ' {"uri": "http://imserver.com/infrastructures/2"}]}'))