示例#1
0
 def test_from_response_http_status(self):
     fake_resp = FakeApiResponse()
     fake_resp.status = 404
     exc = exceptions.from_response(fake_resp, None)
     self.assertIsInstance(exc, exceptions.NotFound)
     fake_resp.status = 409
     exc = exceptions.from_response(fake_resp, None)
     self.assertIsInstance(exc, exceptions.Conflict)
示例#2
0
    def test_create_metadata(self):
        api = self.api
        resp = FakeApiResponse()
        resp.status = 201
        api._direct_request = Mock(return_value=(resp, None))

        metadata = {}
        k1 = random_str(32)
        v1 = random_str(32)

        k2 = random_str(32)
        v2 = random_str(32)

        metadata[k1] = v1
        metadata[k2] = v2

        api.create(self.account, self.name, properties=metadata)
        uri = "%s/reference/create" % self.uri_base
        params = {'acct': self.account, 'ref': self.name}

        data = json.dumps({'properties': metadata})
        api._direct_request.assert_called_once_with('POST',
                                                    uri,
                                                    params=params,
                                                    data=data)
示例#3
0
 def test_from_response(self):
     fake_resp = FakeApiResponse()
     fake_resp.status = 500
     exc = exceptions.from_response(fake_resp, None)
     self.assertIsInstance(exc, exceptions.ClientException)
     self.assertEqual(exc.http_status, fake_resp.status)
     self.assertEqual(exc.message, "n/a")
     self.assertIn("HTTP 500", str(exc))
示例#4
0
    def test_container_create_exist(self):
        api = self.api
        resp = FakeApiResponse()
        resp.status = 204
        api.container._direct_request = Mock(return_value=(resp, None))

        name = random_str(32)
        result = api.container_create(self.account, name)
        self.assertEqual(result, False)
示例#5
0
 def test_from_response_with_body(self):
     fake_resp = FakeApiResponse()
     fake_resp.status = 500
     body = {"status": 300, "message": "Fake error"}
     exc = exceptions.from_response(fake_resp, body)
     self.assertIsInstance(exc, exceptions.ClientException)
     self.assertEqual(exc.http_status, fake_resp.status)
     self.assertEqual(exc.status, 300)
     self.assertEqual(exc.message, "Fake error")
     self.assertIn("HTTP 500", str(exc))
     self.assertIn("STATUS 300", str(exc))
示例#6
0
    def test_create_already_exists(self):
        api = self.api
        resp = FakeApiResponse()
        resp.status = 202
        api._direct_request = Mock(return_value=(resp, None))
        api.create(self.account, self.name)
        uri = "%s/reference/create" % self.uri_base
        params = {'acct': self.account, 'ref': self.name}

        data = json.dumps({'properties': {}})
        api._direct_request.assert_called_once_with(
            'POST', uri, params=params, data=data)
示例#7
0
    def test_container_create(self):
        api = self.api
        resp = FakeApiResponse()
        resp.status = 201
        api.container._direct_request = Mock(return_value=(resp, None))

        name = random_str(32)
        result = api.container_create(self.account, name, headers=self.headers)
        self.assertEqual(result, True)

        uri = "%s/container/create" % self.uri_base
        params = {'acct': self.account, 'ref': name}
        self.headers['x-oio-action-mode'] = 'autocreate'
        data = json.dumps({'properties': {}, 'system': {}})
        api.container._direct_request.assert_called_once_with(
            'POST', uri, params=params, data=data,
            headers=self.headers)