fixtures:
    - APIFixture

defaults:
    request_headers:
        x-auth-token: admin
        accept: application/json
        openstack-api-version: placement latest

tests:

- name: test microversion masks resource-classes endpoint for list with 404
  GET: /resource_classes
  request_headers:
    openstack-api-version: placement 1.1
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: test microversion masks resource-classes endpoint for create with 404
  desc: we want to get a 404 even if content-type is correct
  POST: /resource_classes
  request_headers:
    openstack-api-version: placement 1.1
    content-type: application/json
  data:
      name: CUSTOM_NFV_BAR
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: test microversion mask when wrong content type
  desc: we want to get a 404 before a 415
  POST: /resource_classes
  request_headers:
    openstack-api-version: placement 1.1
    content-type: text/plain
  data: data
  status: 404

- name: test wrong content type
  desc: we want to get a 415 when bad content type
  POST: /resource_classes
  request_headers:
    openstack-api-version: placement 1.2
    content-type: text/plain
  data: data
  status: 415

- name: non admin forbidden
  GET: /resource_classes
  request_headers:
      x-auth-token: user
      accept: application/json
  status: 403
  response_json_paths:
      $.errors[0].title: Forbidden

- name: post invalid non json
  POST: /resource_classes
  request_headers:
    accept: text/plain
    content-type: application/json
  data:
      name: FOO
  status: 400
  response_strings:
      - JSON does not validate

- name: post illegal characters in name
  POST: /resource_classes
  request_headers:
    content-type: application/json
  data:
      name: CUSTOM_Illegal&@!Name?
  status: 400
  response_strings:
      - JSON does not validate
  response_json_paths:
      $.errors[0].title: Bad Request

- name: post new resource class
  POST: /resource_classes
  request_headers:
    content-type: application/json
  data:
      name: $ENVIRON['CUSTOM_RES_CLASS']
  status: 201
  response_headers:
      location: //resource_classes/$ENVIRON['CUSTOM_RES_CLASS']/
  response_forbidden_headers:
      - content-type

- name: try to create same again
  POST: /resource_classes
  request_headers:
    content-type: application/json
  data:
      name: $ENVIRON['CUSTOM_RES_CLASS']
  status: 409
  response_strings:
      - Conflicting resource class already exists
  response_json_paths:
      $.errors[0].title: Conflict

- name: confirm the correct post
  GET: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
      content-type: application/json
  response_json_paths:
      $.name: $ENVIRON['CUSTOM_RES_CLASS']
      $.links[?rel = "self"].href: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']

- name: test microversion masks resource-classes endpoint for show with 404
  GET: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
    openstack-api-version: placement 1.1
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: get resource class works with no accept
  GET: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
    content-type: application/json
  response_headers:
      content-type: /application/json/
  response_json_paths:
      $.name: $ENVIRON['CUSTOM_RES_CLASS']

- name: list resource classes after addition of custom res class
  GET: /resource_classes
  response_json_paths:
      $.resource_classes.`len`: 22  # 21 standard plus 1 custom

- name: update standard resource class bad json
  PUT: /resource_classes/VCPU
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.6
  data:
      name: VCPU_ALTERNATE
  status: 400
  response_strings:
      - JSON does not validate
  response_json_paths:
      $.errors[0].title: Bad Request

- name: update standard resource class to custom
  desc: standard classes cannot be updated
  PUT: /resource_classes/VCPU
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.6
  data:
      name: $ENVIRON['CUSTOM_RES_CLASS']
  status: 400
  response_strings:
      - Cannot update standard resource class VCPU
  response_json_paths:
      $.errors[0].title: Bad Request

- name: update custom resource class to standard resource class name
  PUT: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.6
  data:
      name: VCPU
  status: 400
  response_strings:
      - JSON does not validate
  response_json_paths:
      $.errors[0].title: Bad Request

- name: post another custom resource class
  POST: /resource_classes
  request_headers:
    content-type: application/json
  data:
      name: CUSTOM_NFV_FOO
  status: 201

- name: update custom resource class to already existing custom resource class name
  PUT: /resource_classes/CUSTOM_NFV_FOO
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.6
  data:
      name: $ENVIRON['CUSTOM_RES_CLASS']
  status: 409
  response_strings:
      - Resource class already exists
      - $ENVIRON['CUSTOM_RES_CLASS']
  response_json_paths:
      $.errors[0].title: Conflict

- name: test microversion masks resource-classes endpoint for update with 404
  PUT: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
    openstack-api-version: placement 1.1
    content-type: application/json
  data:
      name: CUSTOM_NFV_BAR
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: update custom resource class with additional properties
  PUT: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.6
  data:
      name: CUSTOM_NFV_BAR
      additional: additional
  status: 400
  response_strings:
      - Additional properties are not allowed

- name: update custom resource class
  PUT: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
    content-type: application/json
    openstack-api-version: placement 1.6
  data:
      name: CUSTOM_NFV_BAR
  status: 200
  response_json_paths:
      $.name: CUSTOM_NFV_BAR
      $.links[?rel = "self"].href: /resource_classes/CUSTOM_NFV_BAR

- name: delete standard resource class
  DELETE: /resource_classes/VCPU
  status: 400
  response_strings:
      - Cannot delete standard resource class
  response_json_paths:
      $.errors[0].title: Bad Request

- name: test microversion masks resource-classes endpoint for delete with 404
  DELETE: /resource_classes/CUSTOM_NFV_BAR
  request_headers:
    openstack-api-version: placement 1.1
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: delete custom resource class
  DELETE: /resource_classes/CUSTOM_NFV_BAR
  status: 204

- name: 404 on deleted resource class
  DELETE: $LAST_URL
  status: 404
  response_json_paths:
      $.errors[0].title: Not Found

- name: post malformed json as json
  POST: /resource_classes
  request_headers:
      content-type: application/json
  data: '{"foo": }'
  status: 400
  response_strings:
      - 'Malformed JSON:'
  response_json_paths:
      $.errors[0].title: Bad Request

- name: post bad resource class name IRON_NFV
  POST: /resource_classes
  request_headers:
      content-type: application/json
  data:
      name: IRON_NFV  # Doesn't start with CUSTOM_
  status: 400
  response_strings:
      - JSON does not validate
  response_json_paths:
      $.errors[0].title: Bad Request

- name: try to create resource class with name exceed max characters
  POST: /resource_classes
  request_headers:
      content-type: application/json
  data:
      name: &name_exceeds_max_length_check CUSTOM_THIS_IS_A_LONG_TEXT_OF_LENGTH_256_CHARACTERSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  status: 400
  response_strings:
      - "Failed validating 'maxLength'"
  response_json_paths:
      $.errors[0].title: Bad Request

- name: try to update resource class with name exceed max characters
  PUT: /resource_classes/$ENVIRON['CUSTOM_RES_CLASS']
  request_headers:
      content-type: application/json
      openstack-api-version: placement 1.6
  data:
      name: *name_exceeds_max_length_check
  status: 400
  response_strings:
      - "Failed validating 'maxLength'"
  response_json_paths:
      $.errors[0].title: Bad Request

- name: try to create resource class with additional properties
  POST: /resource_classes
  request_headers:
      content-type: application/json
  data:
      name: CUSTOM_NFV_BAR
      additional: additional
  status: 400
  response_strings:
      - Additional properties are not allowed
