

@patch_policies(with_ec_default=True)
def test_get_name_and_placement_object_req(self):
    path = '/device/part/account/container/object'
    req = Request.blank(path, headers={
        'X-Backend-Storage-Policy-Index': '0',
    })
    (device, part, account, container, obj, policy) = get_name_and_placement(req, 5, 5, True)
    self.assertEqual(device, 'device')
    self.assertEqual(part, 'part')
    self.assertEqual(account, 'account')
    self.assertEqual(container, 'container')
    self.assertEqual(obj, 'object')
    self.assertEqual(policy, POLICIES[0])
    self.assertEqual(policy.policy_type, EC_POLICY)
    req.headers['X-Backend-Storage-Policy-Index'] = 1
    (device, part, account, container, obj, policy) = get_name_and_placement(req, 5, 5, True)
    self.assertEqual(device, 'device')
    self.assertEqual(part, 'part')
    self.assertEqual(account, 'account')
    self.assertEqual(container, 'container')
    self.assertEqual(obj, 'object')
    self.assertEqual(policy, POLICIES[1])
    self.assertEqual(policy.policy_type, REPL_POLICY)
    req.headers['X-Backend-Storage-Policy-Index'] = 'foo'
    try:
        (device, part, account, container, obj, policy) = get_name_and_placement(req, 5, 5, True)
    except HTTPException as e:
        self.assertEqual(e.status_int, 503)
        self.assertEqual(str(e), '503 Service Unavailable')
        self.assertEqual(e.body, 'No policy with index foo')
    else:
        self.fail('get_name_and_placement did not raise error for invalid storage policy index')

dataset/ETHPy150Open openstack/swift/test/unit/common/test_request_helpers.py TestRequestHelpers.test_get_name_and_placement_object_req/original