# Requests to cover the basic endpoints for alarms.

fixtures:
    - ConfigFixture

tests:
- name: list alarms none
  desc: Lists alarms, none yet exist
  url: /v2/alarms
  method: GET
  response_strings:
      - "[]"

# TODO(chdent) because of the way _lookup is used in the
# AlarmsController pecan is unable to correctly create a 405
# when it receives a PUT to /v2/alarms. This is partially
# fixable in Ceilometer by raising an exception in _lookup if
# alarm_id is not present, but no Allow header will be created.
- name: try to PUT an alarm
  xfail: true
  desc: what does PUT do
  url: /v2/alarms
  method: PUT
  request_headers:
      content-type: application/json
  data:
      name: added_alarm_defaults2
      type: threshold
      threshold_rule:
          meter_name: ameter
          threshold: 300.0
  status: 405
  response_headers:
      allow: GET, POST

# TODO(chdent): A POST should return a location header.
- name: createAlarm
  xfail: true
  desc: Creates an alarm.
  url: /v2/alarms
  method: POST
  request_headers:
      content-type: application/json
  data:
      name: added_alarm_defaults
      type: threshold
      threshold_rule:
          meter_name: ameter
          threshold: 300.0
  status: 201
  response_headers:
      location: /$SCHEME://$NETLOC/v2/alarms/
      content-type: application/json; charset=UTF-8
  response_json_paths:
      $.severity: low
      $.threshold_rule.threshold: 300.0
      $.threshold_rule.comparison_operator: eq

- name: showAlarm
  desc: Shows information for a specified alarm.
  url: /v2/alarms/$RESPONSE['$.alarm_id']
  method: GET
  response_json_paths:
      $.severity: low
      $.alarm_id: $RESPONSE['$.alarm_id']
      $.threshold_rule.threshold: 300.0
      $.threshold_rule.comparison_operator: eq
  response_headers:
      content-type: application/json; charset=UTF-8

- name: updateAlarm
  desc: Updates a specified alarm.
  url: /v2/alarms/$RESPONSE['$.alarm_id']
  method: PUT
  request_headers:
      content-type: application/json
  data:
      name: added_alarm_defaults
      type: threshold
      severity: moderate
      threshold_rule:
          meter_name: ameter
          threshold: 200.0
# TODO(chdent): why do we have a response, why not status: 204?
# status: 204
  response_json_paths:
      $.threshold_rule.threshold: 200.0
      $.severity: moderate
      $.state: insufficient data

- name: showAlarmHistory
  desc: Assembles the history for a specified alarm.
  url: /v2/alarms/$RESPONSE['$.alarm_id']/history?q.field=type&q.op=eq&q.value=rule%20change
  method: GET
  response_json_paths:
      $[0].type: rule change

- name: updateAlarmState
  desc: Sets the state of a specified alarm.
  url: /v2/alarms/$RESPONSE['$[0].alarm_id']/state
  request_headers:
      content-type: application/json
  data: '"alarm"'
  method: PUT
# TODO(chdent): really? Of what possible use is this?
  response_json_paths:
      $: alarm

# Get a list of alarms so we can extract an id for the next test
- name: list alarms for data
  desc: Lists alarms, only one
  url: /v2/alarms
  method: GET
  response_json_paths:
      $[0].name: added_alarm_defaults

- name: showAlarmState
  desc: Gets the state of a specified alarm.
  url: /v2/alarms/$RESPONSE['$[0].alarm_id']/state
  method: GET
  response_headers:
      content-type: application/json; charset=UTF-8
  response_json_paths:
      $: alarm

- name: list alarms one
  desc: Lists alarms, only one
  url: /v2/alarms
  method: GET
  response_json_paths:
      $[0].name: added_alarm_defaults

- name: deleteAlarm
  desc: Deletes a specified alarm.
  url: /v2/alarms/$RESPONSE['$[0].alarm_id']
  method: DELETE
  status: 204

- name: list alarms none end
  desc: Lists alarms, none now exist
  url: /v2/alarms
  method: GET
  response_strings:
      - "[]"
