---
test_name: Check general history format (json output)

strict:
  - json:on

stages:
  - name: history format single entry
    request:
      url: http://{SAB_HOST}:{SAB_PORT}/api
      method: GET
      params:
        mode: history
        apikey: "{SAB_APIKEY}"
        limit: 1
    response:
      status_code: 200
      headers:
        content-type: !re_match "application/json"
        content-type: !re_search "charset=(UTF|utf)-8"
        pragma: "no-cache"
        access-control-allow-origin: "*"
      json:
        history:
          # all four sizes may have a single digit value, so anything beyond that is optional
          total_size: !re_match "[0-9][0-9.]*(\ [A-Z])?"
          month_size: !re_match "[0-9][0-9.]*(\ [A-Z])?"
          week_size: !re_match "[0-9][0-9.]*(\ [A-Z])?"
          day_size: !re_match "[0-9][0-9.]*(\ [A-Z])?"
          slots:
            - completed: !anyint
              name: !anystr
              nzb_name: !anystr
              category: !anystr
              pp: !re_match "[URD]?"
              script: !anystr
              report: !anything
              url: !anystr
              status: !anystr
              nzo_id: !anystr
              storage: !anystr
              path: !anystr
              script_line: !anystr
              download_time: !anyint
              postproc_time: !anyint
              stage_log: !anylist
              downloaded: !anyint
              completeness: null
              fail_message: !anystr
              url_info: !anystr
              bytes: !anyint
              meta: null
              series: !anything
              duplicate_key: !anything
              md5sum: !re_match "[0-9a-fA-F]+"
              password: !anystr
              action_line: !anything
              size: !re_match "[0-9][0-9.]*\ [A-Z]"
              loaded: !anybool
              retry: !anybool
              archive: !anybool
              time_added: !anyint
          noofslots: !anyint
          ppslots: !anyint
          last_history_update: !anyint
          version: !anystr

---
test_name: Check general history format (xml output)

stages:
  - name: history format single entry
    request:
      url: http://{SAB_HOST}:{SAB_PORT}/api
      method: GET
      params:
        mode: history
        apikey: "{SAB_APIKEY}"
        output: xml
        limit: 1
    response:
      status_code: 200
      headers:
        content-type: !re_match "text/xml"
        content-type: !re_search "charset=(UTF|utf)-8"
        pragma: "no-cache"
        access-control-allow-origin: "*"
        content-length: !re_match "[0-9]+"
      verify_response_with:
        function: tavalidate:assert_xml
        extra_kwargs:
          strict: True  # don't accept extra tags in the response
          expected: |
            <?xml version="1.0" encoding="UTF-8" ?>
            <history><total_size>!anystr</total_size>
            <month_size>!anystr</month_size>
            <week_size>!anystr</week_size>
            <day_size>!anystr</day_size>
            <slots><slot>
            <completed>!anyint</completed>
            <name>!anystr</name>
            <nzb_name>!anystr</nzb_name>
            <category>!anystr</category>
            <pp>!anystr</pp>
            <script>!anystr</script>
            <report></report>
            <url>!anystr</url>
            <status>!anystr</status>
            <nzo_id>!anystr</nzo_id>
            <storage>!anystr</storage>
            <path>!anystr</path>
            <script_line>!anystr</script_line>
            <download_time>!anyint</download_time>
            <postproc_time>!anyint</postproc_time>
            <stage_log>!anystr</stage_log>
            <downloaded>!anyint</downloaded>
            <completeness>!anything</completeness>
            <fail_message>!anystr</fail_message>
            <url_info>!anystr</url_info>
            <bytes>!anyint</bytes>
            <meta>!anystr</meta>
            <series>!anystr</series>
            <duplicate_key>!anystr</duplicate_key>
            <md5sum>!anystr</md5sum>
            <password>!anystr</password>
            <action_line>!anystr</action_line>
            <size>!anystr</size>
            <loaded>!anybool</loaded>
            <retry>!anybool</retry>
            <archive>!anybool</archive>
            <time_added>!anyint</time_added>
            </slot>
            </slots>
            <noofslots>!anyint</noofslots>
            <ppslots>!anyint</ppslots>
            <last_history_update>!anyint</last_history_update>
            <version>!anystr</version>
            </history>


---
test_name: Verify value of history slot count

strict:
  - json:off

stages:
  - name: history slot count
    request:
      url: "http://{SAB_HOST}:{SAB_PORT}/api"
      method: GET
      params:
        mode: history
        apikey: "{SAB_APIKEY}"
    response:
      status_code: 200
      headers:
        content-type: !re_match "application/json"
        content-type: !re_search "charset=(UTF|utf)-8"
      json:
        history:
          noofslots: !int "{daemon_history_size}"
          version: "{SAB_VERSION}"
