#
# Test the resource history related API
#

fixtures:
    - ConfigFixture

tests:
    - name: create archive policy
      POST: /v1/archive_policy
      request_headers:
          content-type: application/json
          x-roles: admin
      data:
          name: low
          definition:
              - granularity: 1 hour
      status: 201
      response_headers:
          location: $SCHEME://$NETLOC/v1/archive_policy/low

# Try creating a new generic resource

    - name: post generic resource
      POST: /v1/resource/generic
      request_headers:
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          content-type: application/json
      data:
          id: f93450f2-d8a5-4d67-9985-02511241e7d1
          started_at: "2014-01-03T02:02:02.000000"
          user_id: 0fbb231484614b1a80131fc22f6afc9c
          project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
      status: 201
      response_headers:
          location: $SCHEME://$NETLOC/v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1
          content-type: /^application\/json/
      response_json_paths:
          $.created_by_project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $.created_by_user_id: 0fbb231484614b1a80131fc22f6afc9c
          $.user_id: 0fbb231484614b1a80131fc22f6afc9c

# Update it twice
    - name: patch resource user_id
      PATCH: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1
      request_headers:
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          content-type: application/json
      data:
          user_id: f53c58a4-fdea-4c09-aac4-02135900be67
      status: 200
      response_json_paths:
          user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea

    - name: patch resource project_id
      PATCH: $LAST_URL
      request_headers:
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          content-type: application/json
      data:
          project_id: fe20a931-1012-4cc6-addc-39556ec60907
          metrics:
            mymetric:
              archive_policy_name: low
      status: 200
      response_json_paths:
          user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          project_id: fe20a931-1012-4cc6-addc-39556ec60907

# List resources

    - name: list all resources without history
      GET: /v1/resource/generic
      request_headers:
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
      response_json_paths:
          $[0].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[0].project_id: fe20a931-1012-4cc6-addc-39556ec60907

    - name: list all resources with history
      GET: $LAST_URL
      request_headers:
          accept: application/json; details=True; history=True
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
      response_json_paths:
          $.`len`: 3
          $[0].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[0].user_id: 0fbb231484614b1a80131fc22f6afc9c
          $[0].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[1].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[1].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[1].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[2].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[2].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[2].project_id: fe20a931-1012-4cc6-addc-39556ec60907

    - name: patch resource metrics
      PATCH: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1
      request_headers:
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          content-type: application/json
      data:
          metrics:
            foo:
              archive_policy_name: low
      status: 200

    - name: list all resources with history no change after metrics update
      GET: /v1/resource/generic
      request_headers:
          accept: application/json; details=True; history=True
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
      response_json_paths:
          $.`len`: 3
          $[0].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[0].user_id: 0fbb231484614b1a80131fc22f6afc9c
          $[0].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[1].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[1].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[1].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[2].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[2].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[2].project_id: fe20a931-1012-4cc6-addc-39556ec60907

    - name: create new metrics
      POST: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1/metric
      request_headers:
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          content-type: application/json
      data:
        foobar:
          archive_policy_name: low
      status: 204

    - name: list all resources with history no change after metrics creation
      GET: /v1/resource/generic
      request_headers:
          accept: application/json; details=True; history=True
          x-user-id: 0fbb231484614b1a80131fc22f6afc9c
          x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
      response_json_paths:
          $.`len`: 3
          $[0].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[0].user_id: 0fbb231484614b1a80131fc22f6afc9c
          $[0].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[1].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[1].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[1].project_id: f3d41b770cc14f0bb94a1d5be9c0e3ea
          $[2].id: f93450f2-d8a5-4d67-9985-02511241e7d1
          $[2].user_id: f53c58a4-fdea-4c09-aac4-02135900be67
          $[2].project_id: fe20a931-1012-4cc6-addc-39556ec60907
